gnutls-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] GNU gnutls branch, ocsp, updated. gnutls_3_0_7-60-g0e55ae5


From: Simon Josefsson
Subject: [SCM] GNU gnutls branch, ocsp, updated. gnutls_3_0_7-60-g0e55ae5
Date: Thu, 10 Nov 2011 12:09:50 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU gnutls".

http://git.savannah.gnu.org/cgit/gnutls.git/commit/?id=0e55ae5b0caf878d6dd4128727f9fb696d7136a0

The branch, ocsp has been updated
       via  0e55ae5b0caf878d6dd4128727f9fb696d7136a0 (commit)
       via  647edb316fa9f7415a9d4ff7a1ab4b12b5580563 (commit)
       via  53dae4b4ed9c43025fd88aa16e4ae511cc097e88 (commit)
       via  1ea253d81ceae1ce5fc342fe4b494c2bf409f81a (commit)
       via  6402455d8a63ecc5822504adb0ee9c5741ff8a4c (commit)
       via  7beb6da7f22390d36bf72a012ee7ff4bdcc647be (commit)
       via  66074b4117f2569d795f50e20de7e469bfcea7be (commit)
       via  41a73fb4a147dc4773d4b546d5d8b5cfdae255d9 (commit)
       via  a333d71762903ff5b716d1e3967017b1baf61bd2 (commit)
       via  5d683407978fefa27a36d11c9736fae5a6942668 (commit)
       via  391efb0975aed21a306d37963fcbe75b292f0a48 (commit)
       via  73a6d8dd4486432768c1c0bb7ec738b88182de9a (commit)
       via  133478c1ea66e62cb1671dc8105364f900a557fa (commit)
       via  7823fbbd53bcdb32a39c02d85b598b16f6f4c95a (commit)
       via  95bec0fb1aa37dad34cbd8411ca51bbe51262b3e (commit)
       via  e71de0c575571ae86b507b9c1678ef53fa9e64fd (commit)
       via  93faa4cb6d5c063f982bcb721ada1590f35c63d4 (commit)
       via  2adcb013f0499a6fae96e13076fe95aff55ec0f1 (commit)
       via  0db087a07b271329d85c5f806a06ef5199fd323a (commit)
       via  ce43f3cfab492cacbd669ed880552050d0557bf2 (commit)
       via  92bf546f0214166981180c6621da5fc1a2fb8eed (commit)
       via  1836ecf17d4821bfb8803ff150092a6a9fede5e4 (commit)
       via  e562008f319c3695937f989f342e98b65b7c7941 (commit)
       via  8116cdc8f131edd586dad3128ae35dd744cfc32f (commit)
       via  63b99057d90aa4257ccb05f024c55185c7cf8ca8 (commit)
       via  395d620849722bd7fef44cb540a6bb435694d626 (commit)
       via  8462e62e31fd8244ecf8c47cd7b6084837b9da17 (commit)
       via  e5d8a79fcc429902e8fb9b7cec91d66b965df5bb (commit)
       via  c35922d2c14edb96bc40e34ba0a34553e9cee230 (commit)
       via  3762977eb4bcff96117fff7456ededd21849b0f2 (commit)
       via  69fa77f03a2358c5e3e1ff164635128c16877c36 (commit)
       via  3160ff8ad863d0ed0f85c86c8e0f873c7d711bff (commit)
       via  f680a8a51c1496006b2cca5e1a3e706739225cd3 (commit)
       via  21caff388b360fca7a774ed5206447ba9ebf4f94 (commit)
       via  fe0a92df94869abd48a8e7a576f9b81867a9c420 (commit)
       via  454256c1972ba5c5b487a0acdf7c782e24f8b2a3 (commit)
       via  2762b06c1a0bf8f2756b981f583e796e0610f07c (commit)
       via  447be72912b43e89b9f6bbd3bd84fb12f1bbb439 (commit)
       via  8f8cea0a5359a4734f55ae13c18326f33db3912b (commit)
       via  89c3301101f3bc1b16351f0965436a4e0ecfc771 (commit)
       via  a171181a4c1a39954a0868c2f77973ef4f8a360e (commit)
       via  dd0e5937288e80df181f8200122bc940524e4aa1 (commit)
       via  0ab57c63fc3d85db50b094a3e5f4ea1119872c9c (commit)
       via  096f32b9b67d9f8a2e37a0d33cc2f96b61791523 (commit)
       via  5795a1be8ce16dc1cb9540975ed15b4e16253619 (commit)
       via  0c74ff70779acf8d9fec0a090efce210a378a07c (commit)
       via  f974f18a07c5e5c5a4ba5d6f3523da824e4c1e8e (commit)
       via  545d25a2d3460ad9acff8f38159aa5cd11c70426 (commit)
       via  6f6bcb4550be5d8ec3eda8744f16e6c0cb150741 (commit)
       via  152cf1ae8f825b18b306229e728663057844f558 (commit)
       via  4cfcee5210c2255719892a7f9d7a97288b07de03 (commit)
       via  16049f6d71b3fe16058edc8bb88b9f82caa38d1f (commit)
       via  d2bf3a57f79a89a4bbc1c49a2912d55046eea4a8 (commit)
       via  1cc41ac9719b04ab71f826968bb59c803f1db2ee (commit)
       via  fbb48833fcadfa00034de511cca897ef698edff1 (commit)
       via  311192b42b922ffdd5d1cfceccbcce4a3e1253ad (commit)
       via  8c3cd7e043e95292f2ee337623b18ed02380d844 (commit)
       via  c8ce1c33468de5becb1cd269b2f51608adc58aea (commit)
       via  e82ef4545e9e98cbcb032f55d7c750b81e3a0450 (commit)
       via  8fe80d662c3320156f5731a672016d7a1b9dba1b (commit)
       via  190cef6eed37d0e73a73c1e205eb31d45ab60a3c (commit)
       via  c6b1847aff211db23cb1f12e8c55ce6055943750 (commit)
       via  124dfe0de2321a4c4a3383c8866f6a1dbd45d635 (commit)
       via  5b541a346638429712f8a9db8ced61f1b5ffcec4 (commit)
       via  d6413571272f59b90938c0e16c7af452cb6ea668 (commit)
       via  a28ad8fc63fd4d0b5b51e1cbb910450177bf3d85 (commit)
       via  87a4d5f682cea76b386e425bfd30a8926c51fc04 (commit)
       via  2dd78b367c3c01780615f2a06329611092430f63 (commit)
       via  28602012b231b2836214b2239936d6b06f9e7769 (commit)
       via  f5a7e3a9e3564db739b72e208e1daba711a379f1 (commit)
       via  97871a2d8ec3fc8ae7bded31feabf783cfdaed81 (commit)
       via  afb47325dcb473f4b07a4ea13c49a3ee596f88f6 (commit)
       via  cb9bd9f425b7c5d01a2ccf41ae2cb0101da24c5e (commit)
       via  6e47f6043aa7c25055e43b2a9d5322db63604d52 (commit)
       via  9d31ac4504a6cbaa1cf701efed301961f4ad5359 (commit)
       via  76da5a03009ed11ecf255178a6184bef3cbb35ea (commit)
       via  0e655812ba68e9acf28970eccced65b6f870e770 (commit)
       via  30ac29b1ab63363367fca586373373d95f8eb15e (commit)
       via  996accb26da18b07e115ed62da1683768abcc3c8 (commit)
       via  92e8e071d322b9822167390546115e9b20b84fb9 (commit)
       via  6fc13e2285a988b97764a8ea080961d80a603310 (commit)
       via  10cbbd52fba11ce69cd69641c7b4a176e673d23e (commit)
       via  dad5a74138c9c202b9c4ed5b08be06c55bb95c9e (commit)
       via  7845d635d248cfe13b1906b4430363cb9e5f664f (commit)
       via  588f31dfe633c8210ca8d4f3f08149e1d67ebde3 (commit)
       via  a893dd2f0685b8bd92ae87ffa0962a79c2bf744f (commit)
       via  ab5d57c498b018af172ff6fbe4ddee1f6b5c39de (commit)
       via  d739844f39240b360eebfb1ddd3597e8da961e23 (commit)
       via  657d9334635a1c4c08fc6e003e3378062f58aa6d (commit)
       via  3c37902adad2c4dd5d22b2d2fcc3e9c947b1a4cb (commit)
       via  4f9bc0fd8acc771b905ffc8de86b40150a305282 (commit)
       via  d3e402a44ed289607d422eadcab0012e64fb37f0 (commit)
       via  85987530d41198b448995b9e093788a292040cb6 (commit)
       via  90981c16adf60a071f6d2d451d8d7296b4a7b9f8 (commit)
       via  761548003b39be1e5649ec244ebc326c325dfbb2 (commit)
       via  addfb5b109df8640eb5cc63bdc51e70fc2d499d8 (commit)
       via  b5428d9518bc582190c78a9b1da9460a73cb5e18 (commit)
       via  ff49604d8bc8862da423adc1dfbc15e34648d243 (commit)
       via  b5d61d751bf13cf69b952cfe1e480adf380ae555 (commit)
       via  64fab216041d699b06d01137a1d6b8eac833b78f (commit)
       via  24f4d29d8c2c6359f8cd5eff1ee46c57d70fe431 (commit)
       via  e1411f865fcd0f40dc1703cf939373e8c1c5fc83 (commit)
       via  8c818a6ba140fe45b7119a934c826f32d8de7256 (commit)
       via  d86ab06220f5148db3a664d5659b4ec3f35d1079 (commit)
       via  482635401b91171259c9a027d0bc2faefb7e8c68 (commit)
       via  16a068802c6540f2f04b4d893a33fd82695a8f9c (commit)
       via  1790ba91f21c233d5cfb920992bb3fc56280c7b5 (commit)
       via  73cb8999395fd24c07b58ad729d8a32738e903ae (commit)
       via  9bd5a3d4b391b909fe039176826c15152e887959 (commit)
       via  eabf80538d544e9067205773b50aed9ed81b9f74 (commit)
       via  0a248bf1a8a2d7c82eea0c157984fb0fe4783ec2 (commit)
       via  b9da2448022a1e095e1a59e898a07d3ade8e8bcf (commit)
       via  0882b6466976d04e1df93bce6fc9dcd8653a1e2f (commit)
       via  8a734bb777748124723de6affb22a5cd1d7a2d7f (commit)
       via  1ce7565f485e67094fb361ca8c5987da9737159f (commit)
       via  c9e0c70d588e0f80d313d13a9ad5f44f62546d9c (commit)
       via  5a110e397e7dc01f7c557ec63811be08ecaa28e7 (commit)
       via  bb8a9e3b1f1e370fe3bd59e76f8080370be6ba70 (commit)
       via  27146d06e16c8ca870d821fa6f1a773954aeb170 (commit)
       via  4ac912339d7b33b25c64116d1b6f420dcdaa4a67 (commit)
       via  e3e90b119bf04d8db44ee5aada6129654eab8440 (commit)
       via  f2c9ee62541384a17990e8280dba52832593b5d2 (commit)
       via  a416d288a60adcefb359f5dbdffcb61fd735eb5a (commit)
       via  3a5d30579702fb6172479aa849407c73b55878de (commit)
       via  bd837126e972c5d5e165fa8a181e54abd5d84604 (commit)
       via  312c884bf5df734f9b672df8ab6459a4af19a4d1 (commit)
       via  daf232347022a62607f3200daf88e46cc8b13586 (commit)
       via  347ddb46c0b3affc1f696ad0477a3c5fae83472e (commit)
       via  603f4999699df3a063f118e10ffb225927ef3d2b (commit)
       via  692120e24e0ee4e1d6e05fe3bb80ec87c01cf503 (commit)
       via  17997e0ce0a9f66a8b4e75646327886cb2b3a627 (commit)
       via  6ae032b15ef7eb0608158245f477e0c9f2218abe (commit)
       via  be68a4889aadbe4e7732f49e96e10275bd5b4034 (commit)
       via  95820fc37206240edee922d89d111d61dab5a052 (commit)
       via  3249f6264a937cd7604d17bf13e284dcd5c5f180 (commit)
       via  d35d3ba149b2424aed91d8398a364532c983fe71 (commit)
       via  e2510b07dd102721f03a6d7ddfc41f3557242f62 (commit)
       via  7287aec16f658ce5ef17fbf1a1e0b03fbeec54bf (commit)
       via  d6b29a8aa48be8e3db2ce9bcea4db54477f12744 (commit)
       via  683ccd706bc847ae2ad2420692f89eba354f8714 (commit)
       via  28805f3560b9354cbeb6a9295f169a40c1662f26 (commit)
       via  7e8a47c58aef188e8d7f50014952e5eccf8f097f (commit)
       via  49b7bb40124f97eb0ca5ac786b154473ef6eaa9f (commit)
       via  e733486d19f60cb2e7b579cc9f8e7b01625c79a7 (commit)
       via  8aad72ed69dbf8150c253de257e3633f1b0070ed (commit)
       via  b7c207fcea8f0ffe6f3960a460aae070623e520b (commit)
       via  1161028cc40ddae74a81d9300de9728e9b039564 (commit)
       via  733960deeac69f70e64b3e0a1c13b345729756f1 (commit)
       via  0cdc48391853f3454c5799bdb354be908c27f911 (commit)
       via  7d8c59fe617c783b47db71c9cde73e4d4b21ef80 (commit)
       via  9887b181c0c1efebd340b427e6b9288be3a60443 (commit)
       via  c37e2767c4cd5126af8ea0ffd32a8ee86bdea94b (commit)
       via  3f031f86521dbe38265415b80e6eda48e24c3b88 (commit)
       via  d0c67b24c809cd401febb2695c9173eca1e01572 (commit)
       via  85945e245f6582fdbba2c5813c71c2d014b51420 (commit)
       via  7441316a38a03003aea456449d5f809ae57209b1 (commit)
       via  f7013222c2d4e42ea0cc5c8ee27d86e9123a13d8 (commit)
       via  8de315cc80ef804c7f3b43d6543b65192c5a100c (commit)
       via  5da2fc0517e2af16178c6fc33c2b8cd72faec516 (commit)
       via  155ec71e76db0a374e42e9bbd2a8c9c5918dd254 (commit)
       via  133dff74828291202f6ddf663d0e65472054f72d (commit)
       via  449d2e9f559bcf2598e1b56cc6085a1cdad0b237 (commit)
       via  4e2564c0e712cbea217ccc1e5081134c5b701ffb (commit)
       via  80586b297c6ba6f7f58f71b75183b219d65b1ad7 (commit)
       via  023a291dc96906c6d5184de97e02459d497a19ca (commit)
       via  9c1051fbebe06c5bee3eed1f3120957035bc1473 (commit)
       via  bcf7a8605cef027c9be23d63f455ba429eec90ca (commit)
       via  8f13c0dfd9c6d9b14b0566bf3f959f069dc972fd (commit)
       via  2e83418372099b93324b845c3f655140a6965c98 (commit)
       via  643ebdf12b415fc3edd3b7bc12654bc92d3aed24 (commit)
       via  690ba815c6dc733c5b7d25038ba5eab88607c38e (commit)
       via  8c6c8b114cd7a5886aa21304ab0fc2ac8de29f8c (commit)
       via  1618e176162d9c60b0a6209d4a2f18d043ed30b4 (commit)
       via  09a46913ed28e7e1c066adabe0167b09299ac446 (commit)
       via  0d6015e52a737e6f2469b368228ff22ea51c7b51 (commit)
       via  626b62916898e53afbb4ca12fefd99fcfd38eae3 (commit)
       via  d227e38569322ad1b14f5ccff6bf51d7f1760b52 (commit)
       via  de6b66a172820f15535abc78ceae46e81c94157f (commit)
       via  8128354e41015c15e27a0bf7c4eb785fff51d08c (commit)
       via  9f339991e432646a7a8d7fc7619c4ecc6bbcec6a (commit)
       via  5f786a35682b9d9b97c9a296c54593fb43dadc87 (commit)
       via  69e6b95b5eb9ee8f5a86241b835f99641d0a8b45 (commit)
       via  d25ae9228b4e24594422ce8f8a52725828bd77b3 (commit)
       via  38a089b67d635e01c607b6d91f212222defed59e (commit)
       via  5659bacf34dad6f8a08f1f8c430298fc2d1ce7c2 (commit)
       via  615894e4ceef4c3bdbfbaf7b2278b0d03400122f (commit)
       via  f731bf67a1103887d0d490c276d73efbfccef218 (commit)
       via  a315d9f3b81fdbf14cbb27cd2dd3797d35c755e2 (commit)
       via  0cc3c9e2ff18f7ef24861eb49f0aa3be83941aff (commit)
       via  88263c53527bc9c58795d0c530065aa5cfea7593 (commit)
       via  cd29d35e9483dd425d015af98f53fd7c9363dc46 (commit)
       via  c75a4dfa301eb5aafe519a92e48598d1e94470b0 (commit)
       via  1f86b82c7a33d37f85ba3bb372bd45d249bed2a3 (commit)
       via  365d4fb996d165f98f992ecb0d1014058a6c4f4d (commit)
       via  fb3aebc6c20b360d2847af3df08fe198281419c2 (commit)
       via  b7f14ee9f8530af66a6012cd904524f2effe31ef (commit)
       via  97eae5bb258a7cddf2b0b9fe2294bcc36cecaea4 (commit)
       via  6731bedf011610c6b40512ba62feb68edb65067a (commit)
       via  59c61c7a724637706a3f578e01994adbff40c919 (commit)
       via  a7a794ad486f41cd848afc4dfe1b20371decbdef (commit)
       via  f402f9b2d2358c2a09e8973fcf877c7de71cd308 (commit)
       via  d56146522aaf03414a4d69f2c61d9f8845134411 (commit)
       via  228048a83e260e708f7bccaff2eaa637df8a164e (commit)
       via  b9dbbe7dbb6f7091305c340f63c404f116601883 (commit)
       via  2f5d34846c617823e86246466ae54779badfad76 (commit)
       via  6ec8b573d566d1513f0db8f942d4d55d1d2ef9af (commit)
       via  a5c1bb3cd6eeab5b8f7c564be282178e87e4f57a (commit)
       via  5678e62f9e4df7d0914bc266e83f9e446088a2d9 (commit)
       via  f3c1f6650707f5b923596c47e30494b6f40b2518 (commit)
       via  3edaf986b6dd126397cede1f23d3c35edb5452ae (commit)
       via  813e50d810b83c478e46bfe9634131e753ad3a0e (commit)
       via  02ae5e25df2f5ceade31e2d79f50b639b446b1a3 (commit)
       via  e996072af9d15713cafb07b8f653222807bcd31b (commit)
       via  32dd798bcfee0508e5566b0a38cf0281a82b481f (commit)
       via  62b81c580fa8f67fa7d849924f5e108f4f568a1d (commit)
       via  3c4e48db5b1d941bd3d22a68b043074785b2a8c6 (commit)
       via  b7b8ec136a089794d99f419687c6e3ee1495d754 (commit)
       via  a006a1f4b2f5d3d2efb951b72752a1ebb7e0af62 (commit)
       via  60a13b98e9f410c3b1019252f271d3c0f20b2e61 (commit)
       via  b0ff3f86b1399edf3d3826baa221bed86b6bef91 (commit)
       via  615f8966f295417d3bb608fd325bbfac57a279c2 (commit)
       via  56120e2caabc4b7becbd961187a4aa92e3534215 (commit)
      from  dc8bb5088a76e0b8399624c78a34f7b9207b56ff (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0e55ae5b0caf878d6dd4128727f9fb696d7136a0
Merge: dc8bb50 647edb3
Author: Simon Josefsson <address@hidden>
Date:   Thu Nov 10 13:06:34 2011 +0100

    Merge branch 'master' into ocsp

-----------------------------------------------------------------------

Summary of changes:
 .gitattributes                                     |    1 -
 .gitignore                                         |  342 ++--
 lib/COPYING => COPYING.LESSER                      |    0
 GNUmakefile                                        |    8 +-
 Makefile.am                                        |    7 +-
 NEWS                                               |  104 +-
 README                                             |   13 +-
 README-alpha                                       |    7 +-
 THANKS                                             |  226 +-
 build-aux/pmccabe2html                             |    2 +-
 cfg.mk                                             |   23 +-
 configure.ac                                       |   47 +-
 doc/Makefile.am                                    |   42 +-
 doc/cha-auth.texi                                  |    3 +-
 doc/cha-cert-auth.texi                             |    2 +-
 doc/cha-functions.texi                             |   11 -
 doc/cha-gtls-app.texi                              |   45 +-
 doc/cha-internals.texi                             |    3 +-
 doc/cha-intro-tls.texi                             |   12 +-
 doc/cha-library.texi                               |   97 +-
 doc/cha-tls-app.texi                               |  127 -
 doc/cyclo/Makefile.am                              |   17 +-
 doc/examples/Makefile.am                           |   10 +-
 doc/examples/ex-client-udp.c                       |    2 +
 doc/examples/ex-client2.c                          |  118 -
 doc/examples/ex-pkcs11-list.c                      |    1 +
 doc/examples/ex-rfc2818.c                          |  180 +-
 doc/examples/examples.h                            |    5 +-
 doc/examples/verify.c                              |   91 +
 doc/gnutls-guile.texi                              |   57 +-
 doc/gnutls.texi                                    |    5 +-
 doc/latex/.gitignore                               |    1 +
 doc/latex/Makefile.am                              |   18 +-
 doc/latex/gnutls.tex                               |    2 -
 doc/manpages/Makefile.am                           |  751 +-----
 doc/reference/Makefile.am                          |   40 +-
 doc/reference/gnutls-docs.sgml                     |   28 +-
 doc/reference/version.xml.in                       |    1 +
 doc/scripts/gdoc                                   |   14 +-
 doc/scripts/mytexi2latex                           |    4 +-
 doc/scripts/sort1.pl                               |    4 +-
 doc/scripts/split-texi.pl                          |    8 +-
 doc/scripts/split.pl                               |    8 +-
 doc/sec-tls-app.texi                               |  127 +
 extra/Makefile.am                                  |   75 +
 {libextra => extra}/gnutls_openssl.c               |    0
 extra/includes/Makefile.am                         |   28 +
 {libextra => extra}/includes/gnutls/openssl.h      |    0
 {libextra => extra}/openssl_compat.c               |    0
 {libextra => extra}/openssl_compat.h               |    0
 gl/Makefile.am                                     |  426 +++-
 gl/accept.c                                        |   52 +
 gl/alignof.h                                       |   53 -
 gl/argp-parse.c                                    |    2 +-
 gl/arpa_inet.in.h                                  |  141 +
 gl/bind.c                                          |   49 +
 gl/close.c                                         |   69 +
 gl/closedir.c                                      |    4 +
 gl/connect.c                                       |   56 +
 gl/errno.in.h                                      |  118 +-
 gl/error.c                                         |    2 +
 gl/float.c                                         |    2 +-
 gl/float.in.h                                      |   16 +-
 gl/frexp.c                                         |    4 +-
 gl/frexpl.c                                        |   21 +-
 gl/fstat.c                                         |   82 +
 gl/getpeername.c                                   |   49 +
 gl/gettext.h                                       |  105 +
 gl/hmac-md5.c                                      |   81 -
 gl/hmac.h                                          |   41 -
 gl/inet_ntop.c                                     |  249 ++
 gl/inet_pton.c                                     |  268 ++
 gl/isnan.c                                         |    4 +-
 gl/itold.c                                         |   28 +
 gl/listen.c                                        |   49 +
 gl/lseek.c                                         |    2 +
 gl/m4/arpa_inet_h.m4                               |   57 +
 gl/m4/close.m4                                     |   33 +
 gl/m4/dup2.m4                                      |    5 +-
 gl/m4/fdopen.m4                                    |   49 +
 gl/m4/float_h.m4                                   |   53 +-
 gl/m4/frexp.m4                                     |   11 +-
 gl/m4/frexpl.m4                                    |   15 +-
 gl/m4/fstat.m4                                     |   28 +
 gl/m4/ftruncate.m4                                 |   24 +
 gl/m4/gnulib-cache.m4                              |   40 +-
 gl/m4/gnulib-common.m4                             |   25 +-
 gl/m4/gnulib-comp.m4                               |  373 +++-
 gl/m4/include_next.m4                              |   13 +-
 gl/m4/inet_ntop.m4                                 |   68 +
 gl/m4/inet_pton.m4                                 |   68 +
 gl/m4/ioctl.m4                                     |   41 +
 gl/m4/isnand.m4                                    |    4 +-
 gl/m4/isnanl.m4                                    |    6 +-
 gl/m4/ldexpl.m4                                    |   10 +-
 gl/m4/math_h.m4                                    |  169 +-
 gl/m4/md5.m4                                       |   13 -
 gl/m4/memxor.m4                                    |   10 -
 gl/m4/msvc-nothrow.m4                              |   10 +
 gl/m4/pathmax.m4                                   |   32 +-
 gl/m4/perror.m4                                    |   63 +
 gl/m4/pipe.m4                                      |   15 +
 gl/m4/printf-frexpl.m4                             |    4 +-
 gl/m4/printf.m4                                    |    5 +-
 gl/m4/select.m4                                    |   75 +
 gl/m4/signal_h.m4                                  |   83 +
 gl/m4/stdalign.m4                                  |   22 +
 gl/m4/stdio_h.m4                                   |    4 +-
 gl/m4/stdlib_h.m4                                  |   10 +-
 gl/m4/strerror_r.m4                                |  173 ++
 gl/m4/sys_ioctl_h.m4                               |   64 +
 gl/m4/sys_select_h.m4                              |   95 +
 gl/m4/sys_stat_h.m4                                |    5 +-
 gl/m4/thread.m4                                    |   18 +
 gl/m4/unistd_h.m4                                  |    6 +-
 gl/m4/valgrind-tests.m4                            |    2 +-
 gl/m4/vasnprintf.m4                                |    5 +-
 gl/m4/yield.m4                                     |   19 +
 gl/math.in.h                                       |  638 ++++-
 gl/md5.c                                           |  462 ---
 gl/md5.h                                           |  126 -
 gl/memxor.c                                        |   35 -
 gl/memxor.h                                        |   31 -
 gl/msvc-inval.c                                    |  130 +
 gl/msvc-inval.h                                    |  223 ++
 gl/msvc-nothrow.c                                  |   50 +
 gl/msvc-nothrow.h                                  |   44 +
 gl/opendir.c                                       |    6 +-
 gl/override/lib/gettext.h.diff                     |  112 -
 gl/override/lib/hmac-md5.c.diff                    |   20 -
 gl/override/lib/memxor.c.diff                      |   11 -
 gl/override/lib/memxor.h.diff                      |   10 -
 gl/override/m4/valgrind-tests.m4.diff              |    2 +-
 gl/printf-frexp.c                                  |    4 +-
 gl/printf-frexpl.c                                 |   23 +-
 gl/recv.c                                          |   49 +
 gl/recvfrom.c                                      |   58 +
 gl/select.c                                        |  492 ++++
 gl/send.c                                          |   49 +
 gl/sendto.c                                        |   50 +
 gl/setsockopt.c                                    |   65 +
 gl/shutdown.c                                      |   49 +
 gl/signal.in.h                                     |  447 +++
 gl/socket.c                                        |   49 +
 gl/sockets.c                                       |    1 +
 gl/sockets.h                                       |    2 +
 gl/stdalign.in.h                                   |   89 +
 gl/stdio.in.h                                      |   20 +
 gl/stdlib.in.h                                     |   18 +-
 gl/strerror-override.c                             |  102 +-
 gl/strerror-override.h                             |    2 +-
 gl/strings.in.h                                    |    5 +
 gl/sys_select.in.h                                 |  288 ++
 gl/sys_socket.in.h                                 |    2 +-
 gl/sys_stat.in.h                                   |   26 +-
 gl/tests/Makefile.am                               |  409 +++-
 gl/tests/dup2.c                                    |   84 +-
 gl/tests/fdopen.c                                  |   69 +
 gl/tests/ftruncate.c                               |   43 +
 gl/tests/glthread/lock.c                           | 1058 +++++++
 gl/tests/glthread/lock.h                           |  928 ++++++
 gl/tests/glthread/thread.c                         |  232 ++
 gl/tests/glthread/thread.h                         |  401 +++
 gl/tests/glthread/threadlib.c                      |   74 +
 gl/tests/glthread/yield.h                          |  122 +
 gl/tests/ioctl.c                                   |   79 +
 gl/tests/msvc-inval.c                              |   69 -
 gl/tests/msvc-inval.h                              |  167 --
 gl/tests/perror.c                                  |   49 +
 gl/tests/pipe.c                                    |   51 +
 gl/tests/putenv.c                                  |    2 +-
 gl/tests/strerror_r.c                              |  327 +++
 gl/tests/sys_ioctl.in.h                            |   79 +
 gl/tests/test-accept.c                             |   54 +
 gl/tests/test-arpa_inet.c                          |   27 +
 gl/tests/test-bind.c                               |   56 +
 gl/tests/test-close.c                              |   44 +
 gl/tests/test-connect.c                            |   58 +
 gl/tests/test-dup2.c                               |    2 +
 gl/tests/test-fgetc.c                              |   12 +
 gl/tests/test-fputc.c                              |   90 +
 gl/tests/test-fread.c                              |   99 +
 gl/tests/test-ftruncate.c                          |   59 +
 gl/tests/test-ftruncate.sh                         |    3 +
 gl/tests/test-fwrite.c                             |   93 +
 gl/tests/test-getpeername.c                        |   54 +
 gl/tests/test-hmac-md5.c                           |  147 -
 gl/tests/test-inet_ntop.c                          |   56 +
 gl/tests/test-inet_pton.c                          |   58 +
 gl/tests/test-ioctl.c                              |   49 +
 gl/tests/test-isnanl.h                             |    2 +-
 gl/tests/test-listen.c                             |   47 +
 gl/tests/test-lock.c                               |  601 ++++
 gl/tests/test-md5.c                                |   67 -
 gl/tests/test-perror.c                             |   37 +
 gl/tests/test-perror.sh                            |   24 +
 gl/tests/test-perror2.c                            |  137 +
 gl/tests/test-pipe.c                               |  105 +
 gl/tests/test-recv.c                               |   49 +
 gl/tests/test-recvfrom.c                           |   60 +
 gl/tests/test-select-fd.c                          |   72 +
 gl/tests/test-select-in.sh                         |   39 +
 gl/tests/test-select-out.sh                        |   35 +
 gl/tests/test-select-stdin.c                       |   83 +
 gl/tests/test-select.c                             |   34 +
 gl/tests/test-select.h                             |  436 +++
 gl/tests/test-send.c                               |   49 +
 gl/tests/test-sendto.c                             |   64 +
 gl/tests/test-setsockopt.c                         |   53 +
 gl/tests/test-shutdown.c                           |   47 +
 gl/tests/test-signal-h.c                           |  129 +
 gl/tests/test-stdalign.c                           |  116 +
 gl/tests/test-strerror_r.c                         |  182 ++
 gl/tests/test-sys_ioctl.c                          |   27 +
 gl/tests/test-sys_select.c                         |   55 +
 gl/tests/test-thread_create.c                      |   78 +
 gl/tests/test-thread_self.c                        |   34 +
 gl/tests/w32sock.h                                 |  136 +
 gl/unistd.in.h                                     |   44 +-
 gl/vasnprintf.c                                    |   81 +-
 gl/w32sock.h                                       |   83 +-
 gtk-doc.make                                       |  186 +-
 guile/modules/Makefile.am                          |   11 +-
 guile/modules/gnutls.in                            |  413 +++
 guile/modules/gnutls.scm                           |  387 ---
 guile/modules/gnutls/build/enums.scm               |   10 +-
 guile/modules/gnutls/build/smobs.scm               |   10 +-
 guile/modules/gnutls/extra.scm                     |   15 +-
 guile/pre-inst-guile.in                            |    8 +-
 guile/src/Makefile.am                              |   41 +-
 guile/src/core.c                                   |  490 ++++
 guile/src/extra.c                                  |  551 ----
 guile/src/make-enum-header.scm                     |   20 +-
 guile/src/make-enum-map.scm                        |    6 +-
 guile/src/make-smob-header.scm                     |   14 +-
 guile/src/make-smob-types.scm                      |    6 +-
 guile/tests/openpgp-auth.scm                       |    1 -
 guile/tests/openpgp-keyring.scm                    |    2 +-
 guile/tests/openpgp-keys.scm                       |    1 -
 lib/Makefile.am                                    |   20 +-
 lib/accelerated/Makefile.am                        |   18 +-
 lib/accelerated/accelerated.c                      |   10 +-
 lib/accelerated/intel/Makefile.am                  |   45 -
 lib/accelerated/intel/README                       |    3 -
 lib/accelerated/intel/aes-gcm-padlock.c            |  166 --
 lib/accelerated/intel/aes-padlock.c                |  241 --
 lib/accelerated/intel/aes-padlock.h                |   43 -
 lib/accelerated/intel/asm/appro-aes-gcm-x86-64.s   | 1068 -------
 lib/accelerated/intel/asm/appro-aes-x86-64.s       | 2578 -----------------
 lib/accelerated/intel/asm/appro-aes-x86.s          | 2186 --------------
 lib/accelerated/intel/asm/cpuid-x86-64.s           |   39 -
 lib/accelerated/intel/asm/cpuid-x86.s              |   54 -
 lib/accelerated/intel/asm/padlock-x86-64.s         |  723 -----
 lib/accelerated/intel/asm/padlock-x86.s            |  822 ------
 lib/accelerated/x86.h                              |   36 -
 lib/accelerated/{intel => x86}/.gitignore          |    0
 lib/accelerated/x86/Makefile.am                    |   59 +
 lib/accelerated/x86/README                         |    3 +
 lib/accelerated/x86/aes-gcm-padlock.c              |  168 ++
 lib/accelerated/{intel => x86}/aes-gcm-x86.c       |    0
 lib/accelerated/x86/aes-padlock.c                  |  410 +++
 lib/accelerated/x86/aes-padlock.h                  |   46 +
 lib/accelerated/{intel => x86}/aes-x86.c           |    0
 lib/accelerated/{intel => x86}/aes-x86.h           |    0
 .../x86/asm-coff/appro-aes-gcm-x86-64-coff.s       | 1211 ++++++++
 .../x86/asm-coff/appro-aes-x86-64-coff.s           | 3044 ++++++++++++++++++++
 lib/accelerated/x86/asm-coff/appro-aes-x86-coff.s  | 2162 ++++++++++++++
 lib/accelerated/x86/asm-coff/cpuid-x86-64-coff.s   |   56 +
 lib/accelerated/x86/asm-coff/cpuid-x86-coff.s      |   68 +
 lib/accelerated/x86/asm-coff/padlock-x86-64-coff.s |  606 ++++
 lib/accelerated/x86/asm-coff/padlock-x86-coff.s    |  615 ++++
 lib/accelerated/x86/asm/appro-aes-gcm-x86-64.s     | 1068 +++++++
 lib/accelerated/x86/asm/appro-aes-x86-64.s         | 2578 +++++++++++++++++
 lib/accelerated/x86/asm/appro-aes-x86.s            | 2186 ++++++++++++++
 lib/accelerated/x86/asm/cpuid-x86-64.s             |   62 +
 lib/accelerated/x86/asm/cpuid-x86.s                |   77 +
 lib/accelerated/x86/asm/padlock-x86-64.s           |  519 ++++
 lib/accelerated/x86/asm/padlock-x86.s              |  625 ++++
 lib/accelerated/x86/hmac-padlock.c                 |  372 +++
 lib/accelerated/{intel => x86}/license.txt         |    0
 lib/accelerated/x86/sha-padlock.c                  |  415 +++
 lib/accelerated/x86/sha-padlock.h                  |   30 +
 lib/accelerated/x86/x86.h                          |   36 +
 lib/algorithms/Makefile.am                         |    2 +
 lib/algorithms/ciphersuites.c                      |    2 +-
 lib/auth/Makefile.am                               |    2 +
 lib/auth/cert.c                                    |    4 +
 lib/auth/ecdh_common.c                             |   21 +-
 lib/auth/srp.c                                     |  123 +-
 lib/auth/srp_passwd.c                              |    9 +-
 lib/crypto-backend.h                               |   46 +-
 lib/debug.c                                        |    3 +-
 lib/ext/Makefile.am                                |    2 +
 lib/gcrypt/Makefile.am                             |   34 -
 lib/gcrypt/cipher.c                                |  166 --
 lib/gcrypt/init.c                                  |   82 -
 lib/gcrypt/mac.c                                   |  183 --
 lib/gcrypt/mpi.c                                   |  415 ---
 lib/gcrypt/pk.c                                    |  859 ------
 lib/gcrypt/rnd.c                                   |   60 -
 lib/gnutls_cert.c                                  |    2 +-
 lib/gnutls_cipher.c                                |    4 +-
 lib/gnutls_cipher_int.c                            |   38 +-
 lib/gnutls_cipher_int.h                            |    5 +-
 lib/gnutls_compress.c                              |   48 +-
 lib/gnutls_compress.h                              |   12 +-
 lib/gnutls_constate.c                              |   30 +-
 lib/gnutls_db.c                                    |  209 +-
 lib/gnutls_db.h                                    |    9 -
 lib/gnutls_dtls.c                                  |    2 +-
 lib/gnutls_ecc.c                                   |   20 +-
 lib/gnutls_errors.c                                |    5 -
 lib/gnutls_global.c                                |    2 +-
 lib/gnutls_handshake.c                             |    8 +-
 lib/gnutls_hash_int.c                              |   47 +-
 lib/gnutls_int.h                                   |   22 +-
 lib/gnutls_pcert.c                                 |    4 +
 lib/gnutls_priority.c                              |    4 +-
 lib/gnutls_privkey.c                               |   69 +-
 lib/gnutls_pubkey.c                                |   12 +-
 lib/gnutls_record.c                                |   14 +-
 lib/gnutls_session.c                               |    3 +-
 lib/gnutls_sig.c                                   |   36 +-
 lib/gnutls_srp.c                                   |    4 +-
 lib/gnutls_state.c                                 |    6 +-
 lib/gnutls_str.c                                   |   56 +-
 lib/gnutls_str.h                                   |   14 +
 lib/gnutls_str_array.h                             |    1 +
 lib/gnutls_ui.c                                    |    2 +-
 lib/gnutls_x509.c                                  |   80 +-
 lib/includes/gnutls/abstract.h                     |   29 +-
 lib/includes/gnutls/compat.h                       |    2 +-
 lib/includes/gnutls/gnutls.h.in                    |   17 +-
 lib/includes/gnutls/pkcs11.h                       |    2 +-
 lib/libgnutls.map                                  |    6 +
 lib/minitasn1/Makefile.am                          |    1 +
 lib/minitasn1/coding.c                             |   25 +-
 lib/minitasn1/decoding.c                           |    7 +-
 lib/minitasn1/element.c                            |   39 +-
 lib/minitasn1/element.h                            |    4 +-
 lib/minitasn1/errors.c                             |    6 +-
 lib/minitasn1/gstr.c                               |    2 +-
 lib/minitasn1/gstr.h                               |    2 +-
 lib/minitasn1/int.h                                |    4 +-
 lib/minitasn1/libtasn1.h                           |    6 +-
 lib/minitasn1/parser_aux.c                         |    4 +-
 lib/minitasn1/parser_aux.h                         |    4 +-
 lib/minitasn1/structure.c                          |   49 +-
 lib/minitasn1/structure.h                          |    2 +-
 lib/minitasn1/version.c                            |    4 +-
 lib/nettle/Makefile.am                             |    4 +-
 lib/nettle/cipher.c                                |    1 +
 lib/nettle/ecc.h                                   |    9 +-
 lib/nettle/ecc_free.c                              |    2 +-
 lib/nettle/ecc_make_key.c                          |   16 +-
 lib/nettle/ecc_mulmod.c                            |   27 +-
 lib/nettle/ecc_projective_add_point.c              |    2 +-
 lib/nettle/ecc_projective_check_point.c            |  106 +
 lib/nettle/ecc_projective_dbl_point.c              |  207 --
 lib/nettle/ecc_projective_dbl_point_3.c            |    2 +-
 lib/nettle/ecc_sign_hash.c                         |    2 +-
 lib/nettle/egd.c                                   |   15 +-
 lib/nettle/mac.c                                   |  162 +-
 lib/nettle/pk.c                                    |   38 +-
 lib/nettle/rnd.c                                   |    6 +-
 lib/opencdk/Makefile.am                            |    2 +
 lib/opencdk/main.c                                 |    3 -
 lib/opencdk/opencdk.h                              |    3 +-
 lib/opencdk/read-packet.c                          |    2 +-
 lib/opencdk/stream.c                               |    2 +-
 lib/openpgp/Makefile.am                            |    2 +
 lib/openpgp/output.c                               |   57 +-
 lib/pkcs11.c                                       |    2 +-
 lib/pkcs11_privkey.c                               |    2 +-
 lib/pkcs11_secret.c                                |    2 +-
 lib/pkcs11_write.c                                 |    4 +-
 lib/system.c                                       |    1 +
 lib/x509/Makefile.am                               |    2 +-
 lib/x509/common.c                                  |   42 +-
 lib/x509/common.h                                  |    2 +
 lib/x509/crq.c                                     |  106 +-
 lib/x509/extensions.c                              |    3 +-
 lib/x509/key_decode.c                              |    4 +-
 lib/x509/key_encode.c                              |    4 +-
 lib/x509/mpi.c                                     |    4 +-
 lib/x509/output.c                                  |  131 +-
 lib/x509/output.h                                  |   31 -
 lib/x509/privkey.c                                 |   53 +-
 lib/x509/privkey_pkcs8.c                           |    1 +
 lib/x509/verify-high.c                             |    3 +-
 lib/x509/x509.c                                    |  124 +-
 lib/x509/x509_int.h                                |   27 -
 lib/x509_b64.c                                     |   37 +-
 lib/x509_b64.h                                     |    4 -
 libextra/Makefile.am                               |  110 -
 libextra/fipsmd5.c                                 |  206 --
 libextra/gnutls-extra.pc.in                        |   26 -
 libextra/gnutls_extra.c                            |  110 -
 libextra/includes/Makefile.am                      |   28 -
 libextra/includes/gnutls/extra.h                   |   54 -
 libextra/libgnutls-extra.map                       |   33 -
 m4/hooks.m4                                        |   12 +-
 maint.mk                                           |   60 +-
 po/it.po.in                                        |  724 +++--
 src/Makefile.am                                    |    7 +-
 src/benchmark-cipher.c                             |   16 +-
 src/benchmark.c                                    |   31 +-
 src/benchmark.h                                    |    5 +-
 src/certtool-cfg.c                                 |    7 +-
 src/certtool-common.c                              |    1 -
 src/certtool.c                                     |    2 +-
 src/cli-gaa.c                                      |   89 +-
 src/cli-gaa.h                                      |    2 +-
 src/cli.c                                          |    9 +-
 src/cli.gaa                                        |    3 +-
 src/common.h                                       |    8 +-
 src/p11common.c                                    |    3 +
 src/pkcs11.c                                       |    1 -
 src/prime.c                                        |   14 +-
 src/psk.c                                          |    1 -
 src/serv.c                                         |    8 +-
 src/srptool.c                                      |   20 +-
 src/tests.c                                        |   96 +-
 src/tests.h                                        |    8 +-
 src/tls_test.c                                     |   30 +-
 src/udp-serv.c                                     |   32 +-
 tests/Makefile.am                                  |   28 +-
 tests/cipher-test.c                                |  919 ++++---
 tests/cve-2009-1416.c                              |    2 -
 tests/dsa/testdsa                                  |    4 +-
 tests/libgcrypt.supp                               |  187 --
 tests/mpi.c                                        |    2 +-
 tests/nist-pkits/build-chain                       |    4 +-
 tests/openpgp-certs/testcerts                      |    4 +-
 tests/openpgp-keyring.c                            |    5 -
 tests/pathlen/ca-no-pathlen.pem                    |    2 +-
 tests/pathlen/no-ca-or-pathlen.pem                 |    2 +-
 tests/rng-fork.c                                   |    4 +-
 tests/rsa-md5-collision/README                     |   12 +-
 tests/safe-renegotiation/Makefile.am               |    2 +-
 .../safe-renegotiation/suppressions.valgrind       |    0
 tests/suite/Makefile.am                            |   75 +-
 tests/suite/testcompat-main                        |   33 +-
 tests/suite/testsrn                                |    4 +-
 tests/suppressions.valgrind                        |  203 ++
 tests/utils.c                                      |    3 +-
 tests/x509cert-tl.c                                |    2 +-
 tests/x509cert.c                                   |    2 +-
 448 files changed, 35394 insertions(+), 17271 deletions(-)
 delete mode 100644 .gitattributes
 rename lib/COPYING => COPYING.LESSER (100%)
 delete mode 100644 doc/cha-tls-app.texi
 delete mode 100644 doc/examples/ex-client2.c
 create mode 100644 doc/examples/verify.c
 create mode 100644 doc/reference/version.xml.in
 create mode 100644 doc/sec-tls-app.texi
 create mode 100644 extra/Makefile.am
 rename {libextra => extra}/gnutls_openssl.c (100%)
 create mode 100644 extra/includes/Makefile.am
 rename {libextra => extra}/includes/gnutls/openssl.h (100%)
 rename {libextra => extra}/openssl_compat.c (100%)
 rename {libextra => extra}/openssl_compat.h (100%)
 create mode 100644 gl/accept.c
 delete mode 100644 gl/alignof.h
 create mode 100644 gl/arpa_inet.in.h
 create mode 100644 gl/bind.c
 create mode 100644 gl/close.c
 create mode 100644 gl/connect.c
 create mode 100644 gl/fstat.c
 create mode 100644 gl/getpeername.c
 delete mode 100644 gl/hmac-md5.c
 delete mode 100644 gl/hmac.h
 create mode 100644 gl/inet_ntop.c
 create mode 100644 gl/inet_pton.c
 create mode 100644 gl/itold.c
 create mode 100644 gl/listen.c
 create mode 100644 gl/m4/arpa_inet_h.m4
 create mode 100644 gl/m4/close.m4
 create mode 100644 gl/m4/fdopen.m4
 create mode 100644 gl/m4/fstat.m4
 create mode 100644 gl/m4/ftruncate.m4
 create mode 100644 gl/m4/inet_ntop.m4
 create mode 100644 gl/m4/inet_pton.m4
 create mode 100644 gl/m4/ioctl.m4
 delete mode 100644 gl/m4/md5.m4
 delete mode 100644 gl/m4/memxor.m4
 create mode 100644 gl/m4/msvc-nothrow.m4
 create mode 100644 gl/m4/perror.m4
 create mode 100644 gl/m4/pipe.m4
 create mode 100644 gl/m4/select.m4
 create mode 100644 gl/m4/signal_h.m4
 create mode 100644 gl/m4/stdalign.m4
 create mode 100644 gl/m4/strerror_r.m4
 create mode 100644 gl/m4/sys_ioctl_h.m4
 create mode 100644 gl/m4/sys_select_h.m4
 create mode 100644 gl/m4/thread.m4
 create mode 100644 gl/m4/yield.m4
 delete mode 100644 gl/md5.c
 delete mode 100644 gl/md5.h
 delete mode 100644 gl/memxor.c
 delete mode 100644 gl/memxor.h
 create mode 100644 gl/msvc-inval.c
 create mode 100644 gl/msvc-inval.h
 create mode 100644 gl/msvc-nothrow.c
 create mode 100644 gl/msvc-nothrow.h
 delete mode 100644 gl/override/lib/gettext.h.diff
 delete mode 100644 gl/override/lib/hmac-md5.c.diff
 delete mode 100644 gl/override/lib/memxor.c.diff
 delete mode 100644 gl/override/lib/memxor.h.diff
 create mode 100644 gl/recv.c
 create mode 100644 gl/recvfrom.c
 create mode 100644 gl/select.c
 create mode 100644 gl/send.c
 create mode 100644 gl/sendto.c
 create mode 100644 gl/setsockopt.c
 create mode 100644 gl/shutdown.c
 create mode 100644 gl/signal.in.h
 create mode 100644 gl/socket.c
 create mode 100644 gl/stdalign.in.h
 create mode 100644 gl/sys_select.in.h
 create mode 100644 gl/tests/fdopen.c
 create mode 100644 gl/tests/ftruncate.c
 create mode 100644 gl/tests/glthread/lock.c
 create mode 100644 gl/tests/glthread/lock.h
 create mode 100644 gl/tests/glthread/thread.c
 create mode 100644 gl/tests/glthread/thread.h
 create mode 100644 gl/tests/glthread/threadlib.c
 create mode 100644 gl/tests/glthread/yield.h
 create mode 100644 gl/tests/ioctl.c
 delete mode 100644 gl/tests/msvc-inval.c
 delete mode 100644 gl/tests/msvc-inval.h
 create mode 100644 gl/tests/perror.c
 create mode 100644 gl/tests/pipe.c
 create mode 100644 gl/tests/strerror_r.c
 create mode 100644 gl/tests/sys_ioctl.in.h
 create mode 100644 gl/tests/test-accept.c
 create mode 100644 gl/tests/test-arpa_inet.c
 create mode 100644 gl/tests/test-bind.c
 create mode 100644 gl/tests/test-close.c
 create mode 100644 gl/tests/test-connect.c
 create mode 100644 gl/tests/test-fputc.c
 create mode 100644 gl/tests/test-fread.c
 create mode 100644 gl/tests/test-ftruncate.c
 create mode 100755 gl/tests/test-ftruncate.sh
 create mode 100644 gl/tests/test-fwrite.c
 create mode 100644 gl/tests/test-getpeername.c
 delete mode 100644 gl/tests/test-hmac-md5.c
 create mode 100644 gl/tests/test-inet_ntop.c
 create mode 100644 gl/tests/test-inet_pton.c
 create mode 100644 gl/tests/test-ioctl.c
 create mode 100644 gl/tests/test-listen.c
 create mode 100644 gl/tests/test-lock.c
 delete mode 100644 gl/tests/test-md5.c
 create mode 100644 gl/tests/test-perror.c
 create mode 100755 gl/tests/test-perror.sh
 create mode 100644 gl/tests/test-perror2.c
 create mode 100644 gl/tests/test-pipe.c
 create mode 100644 gl/tests/test-recv.c
 create mode 100644 gl/tests/test-recvfrom.c
 create mode 100644 gl/tests/test-select-fd.c
 create mode 100755 gl/tests/test-select-in.sh
 create mode 100755 gl/tests/test-select-out.sh
 create mode 100644 gl/tests/test-select-stdin.c
 create mode 100644 gl/tests/test-select.c
 create mode 100644 gl/tests/test-select.h
 create mode 100644 gl/tests/test-send.c
 create mode 100644 gl/tests/test-sendto.c
 create mode 100644 gl/tests/test-setsockopt.c
 create mode 100644 gl/tests/test-shutdown.c
 create mode 100644 gl/tests/test-signal-h.c
 create mode 100644 gl/tests/test-stdalign.c
 create mode 100644 gl/tests/test-strerror_r.c
 create mode 100644 gl/tests/test-sys_ioctl.c
 create mode 100644 gl/tests/test-sys_select.c
 create mode 100644 gl/tests/test-thread_create.c
 create mode 100644 gl/tests/test-thread_self.c
 create mode 100644 gl/tests/w32sock.h
 create mode 100644 guile/modules/gnutls.in
 delete mode 100644 guile/modules/gnutls.scm
 delete mode 100644 guile/src/extra.c
 delete mode 100644 lib/accelerated/intel/Makefile.am
 delete mode 100644 lib/accelerated/intel/README
 delete mode 100644 lib/accelerated/intel/aes-gcm-padlock.c
 delete mode 100644 lib/accelerated/intel/aes-padlock.c
 delete mode 100644 lib/accelerated/intel/aes-padlock.h
 delete mode 100644 lib/accelerated/intel/asm/appro-aes-gcm-x86-64.s
 delete mode 100644 lib/accelerated/intel/asm/appro-aes-x86-64.s
 delete mode 100644 lib/accelerated/intel/asm/appro-aes-x86.s
 delete mode 100644 lib/accelerated/intel/asm/cpuid-x86-64.s
 delete mode 100644 lib/accelerated/intel/asm/cpuid-x86.s
 delete mode 100644 lib/accelerated/intel/asm/padlock-x86-64.s
 delete mode 100644 lib/accelerated/intel/asm/padlock-x86.s
 delete mode 100644 lib/accelerated/x86.h
 rename lib/accelerated/{intel => x86}/.gitignore (100%)
 create mode 100644 lib/accelerated/x86/Makefile.am
 create mode 100644 lib/accelerated/x86/README
 create mode 100644 lib/accelerated/x86/aes-gcm-padlock.c
 rename lib/accelerated/{intel => x86}/aes-gcm-x86.c (100%)
 create mode 100644 lib/accelerated/x86/aes-padlock.c
 create mode 100644 lib/accelerated/x86/aes-padlock.h
 rename lib/accelerated/{intel => x86}/aes-x86.c (100%)
 rename lib/accelerated/{intel => x86}/aes-x86.h (100%)
 create mode 100644 lib/accelerated/x86/asm-coff/appro-aes-gcm-x86-64-coff.s
 create mode 100644 lib/accelerated/x86/asm-coff/appro-aes-x86-64-coff.s
 create mode 100644 lib/accelerated/x86/asm-coff/appro-aes-x86-coff.s
 create mode 100644 lib/accelerated/x86/asm-coff/cpuid-x86-64-coff.s
 create mode 100644 lib/accelerated/x86/asm-coff/cpuid-x86-coff.s
 create mode 100644 lib/accelerated/x86/asm-coff/padlock-x86-64-coff.s
 create mode 100644 lib/accelerated/x86/asm-coff/padlock-x86-coff.s
 create mode 100644 lib/accelerated/x86/asm/appro-aes-gcm-x86-64.s
 create mode 100644 lib/accelerated/x86/asm/appro-aes-x86-64.s
 create mode 100644 lib/accelerated/x86/asm/appro-aes-x86.s
 create mode 100644 lib/accelerated/x86/asm/cpuid-x86-64.s
 create mode 100644 lib/accelerated/x86/asm/cpuid-x86.s
 create mode 100644 lib/accelerated/x86/asm/padlock-x86-64.s
 create mode 100644 lib/accelerated/x86/asm/padlock-x86.s
 create mode 100644 lib/accelerated/x86/hmac-padlock.c
 rename lib/accelerated/{intel => x86}/license.txt (100%)
 create mode 100644 lib/accelerated/x86/sha-padlock.c
 create mode 100644 lib/accelerated/x86/sha-padlock.h
 create mode 100644 lib/accelerated/x86/x86.h
 delete mode 100644 lib/gcrypt/Makefile.am
 delete mode 100644 lib/gcrypt/cipher.c
 delete mode 100644 lib/gcrypt/init.c
 delete mode 100644 lib/gcrypt/mac.c
 delete mode 100644 lib/gcrypt/mpi.c
 delete mode 100644 lib/gcrypt/pk.c
 delete mode 100644 lib/gcrypt/rnd.c
 create mode 100644 lib/nettle/ecc_projective_check_point.c
 delete mode 100644 lib/nettle/ecc_projective_dbl_point.c
 delete mode 100644 lib/x509/output.h
 delete mode 100644 libextra/Makefile.am
 delete mode 100644 libextra/fipsmd5.c
 delete mode 100644 libextra/gnutls-extra.pc.in
 delete mode 100644 libextra/gnutls_extra.c
 delete mode 100644 libextra/includes/Makefile.am
 delete mode 100644 libextra/includes/gnutls/extra.h
 delete mode 100644 libextra/libgnutls-extra.map
 delete mode 100644 tests/libgcrypt.supp
 copy doc/reference/gnutls.types => 
tests/safe-renegotiation/suppressions.valgrind (100%)
 create mode 100644 tests/suppressions.valgrind

diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index eeea19a..0000000
--- a/.gitattributes
+++ /dev/null
@@ -1 +0,0 @@
-libextra/gl/override/lib/md5.c.diff -whitespace
diff --git a/.gitignore b/.gitignore
index b669e45..02caaed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
+*.gcda
+*.gcno
+*.gcov
 *.lo
 *.o
 *~
@@ -7,8 +10,10 @@ ABOUT-NLS
 INSTALL
 Makefile
 Makefile.in
+TAGS
 aclocal.m4
 autom4te.cache/
+build-aux/compile
 build-aux/config.guess
 build-aux/config.sub
 build-aux/depcomp
@@ -26,6 +31,7 @@ doc/Makefile
 doc/Makefile.in
 doc/algorithms.texi
 doc/core.c.texi
+doc/coverage/
 doc/credentials/Makefile
 doc/credentials/Makefile.in
 doc/credentials/openpgp/Makefile
@@ -36,16 +42,23 @@ doc/credentials/x509/Makefile
 doc/credentials/x509/Makefile.in
 doc/cyclo/Makefile
 doc/cyclo/Makefile.in
+doc/cyclo/cyclo-gnutls.html
 doc/doxygen/Doxyfile
+doc/doxygen/html/
+doc/doxygen/latex/
+doc/enums.texi
+doc/enums/
 doc/errcodes
 doc/error_codes.texi
 doc/examples/Makefile
 doc/examples/Makefile.in
 doc/examples/ex-cert-select
+doc/examples/ex-cert-select-pkcs11
 doc/examples/ex-client-psk
 doc/examples/ex-client-resume
 doc/examples/ex-client-srp
 doc/examples/ex-client-tlsia
+doc/examples/ex-client-udp
 doc/examples/ex-client1
 doc/examples/ex-client2
 doc/examples/ex-crq
@@ -62,6 +75,7 @@ doc/extra-api.texi
 doc/extra.c.texi
 doc/gnutls-api.texi
 doc/gnutls-extra-api.texi
+doc/gnutls-guile.html
 doc/gnutls.aux
 doc/gnutls.cp
 doc/gnutls.cps
@@ -83,7 +97,10 @@ doc/gnutls.tp
 doc/gnutls.vr
 doc/gnutls.vrs
 doc/ia-api.texi
-doc/manpages/*.3
+doc/latex/enums
+doc/latex/gnutls-enums.tex
+doc/latex/gnutls.lof
+doc/latex/gnutls.lot
 doc/manpages/Makefile
 doc/manpages/Makefile.in
 doc/pgp-api.texi
@@ -109,25 +126,39 @@ doc/reference/html/
 doc/reference/pdf-build.stamp
 doc/reference/pdf.stamp
 doc/reference/scan-build.stamp
+doc/reference/setup-build.stamp
 doc/reference/sgml-build.stamp
 doc/reference/sgml.stamp
 doc/reference/tmpl-build.stamp
 doc/reference/tmpl.stamp
 doc/reference/tmpl/
+doc/reference/version.xml
 doc/reference/xml/
 doc/scripts/Makefile
 doc/scripts/Makefile.in
+doc/stamp-1
 doc/stamp-vti
+doc/version-guile.texi
 doc/version.texi
 doc/x509-api.texi
+extra/Makefile
+extra/Makefile.in
+extra/includes/Makefile
+extra/includes/Makefile.in
+extra/libgnutls-openssl.la
 gl/Makefile
 gl/Makefile.in
 gl/alloca.h
 gl/arg-nonnull.h
 gl/arpa/
 gl/c++defs.h
+gl/dirent.h
+gl/getopt.h
 gl/libgnu.la
+gl/math.h
 gl/netdb.h
+gl/signal.h
+gl/stdalign.h
 gl/stdio.h
 gl/stdlib.h
 gl/string.h
@@ -136,125 +167,167 @@ gl/sys/
 gl/tests/Makefile
 gl/tests/Makefile.in
 gl/tests/arg-nonnull.h
+gl/tests/arpa/
 gl/tests/c++defs.h
 gl/tests/fcntl.h
+gl/tests/glthread/.dirstamp
+gl/tests/glthread/glthread
+gl/tests/inttypes.h
+gl/tests/inttypes.h 
 gl/tests/libtests.a
 gl/tests/sys/
+gl/tests/test-accept
 gl/tests/test-alignof
 gl/tests/test-alloca-opt
+gl/tests/test-argp
 gl/tests/test-arpa_inet
 gl/tests/test-binary-io
+gl/tests/test-bind
+gl/tests/test-byteswap
 gl/tests/test-c-ctype
+gl/tests/test-close
+gl/tests/test-connect
+gl/tests/test-dirent
+gl/tests/test-dup2
+gl/tests/test-environ
 gl/tests/test-errno
+gl/tests/test-fcntl-h
+gl/tests/test-fdopen
+gl/tests/test-fgetc
+gl/tests/test-float
+gl/tests/test-fputc
+gl/tests/test-fread
+gl/tests/test-frexp-nolibm
+gl/tests/test-frexpl-nolibm
+gl/tests/test-fseek
 gl/tests/test-fseeko
+gl/tests/test-fseeko3
+gl/tests/test-fseeko4
+gl/tests/test-fseterr
+gl/tests/test-fstat
+gl/tests/test-ftell
+gl/tests/test-ftell3
 gl/tests/test-ftello
 gl/tests/test-ftello3
+gl/tests/test-ftello4
+gl/tests/test-ftruncate
+gl/tests/test-func
+gl/tests/test-fwrite
 gl/tests/test-getaddrinfo
+gl/tests/test-getcwd-lgpl
 gl/tests/test-getdelim
 gl/tests/test-getline
+gl/tests/test-getopt
+gl/tests/test-getpeername
 gl/tests/test-gettimeofday
+gl/tests/test-hmac-md5
+gl/tests/test-ignore-value
 gl/tests/test-inet_ntop
 gl/tests/test-inet_pton
+gl/tests/test-intprops
+gl/tests/test-intprops 
+gl/tests/test-inttypes
+gl/tests/test-inttypes 
+gl/tests/test-ioctl
+gl/tests/test-isnand-nolibm
+gl/tests/test-isnanf-nolibm
+gl/tests/test-isnanl-nolibm
+gl/tests/test-listen
+gl/tests/test-lock
 gl/tests/test-lseek
+gl/tests/test-lstat
+gl/tests/test-malloc-gnu
+gl/tests/test-malloca
+gl/tests/test-math
+gl/tests/test-md5
 gl/tests/test-memchr
 gl/tests/test-netdb
 gl/tests/test-netinet_in
+gl/tests/test-open
+gl/tests/test-pathmax
 gl/tests/test-perror
+gl/tests/test-perror2
+gl/tests/test-pipe
+gl/tests/test-printf-frexp
+gl/tests/test-printf-frexpl
+gl/tests/test-rawmemchr
 gl/tests/test-read-file
+gl/tests/test-recv
+gl/tests/test-recvfrom
 gl/tests/test-select
 gl/tests/test-select-fd
 gl/tests/test-select-stdin
+gl/tests/test-send
+gl/tests/test-sendto
+gl/tests/test-setenv
+gl/tests/test-setsockopt
+gl/tests/test-shutdown
+gl/tests/test-signal-h
+gl/tests/test-signbit
+gl/tests/test-sleep
 gl/tests/test-snprintf
 gl/tests/test-sockets
+gl/tests/test-stat
+gl/tests/test-stdalign
 gl/tests/test-stdbool
 gl/tests/test-stddef
 gl/tests/test-stdint
 gl/tests/test-stdio
 gl/tests/test-stdlib
+gl/tests/test-strchrnul
 gl/tests/test-strerror
+gl/tests/test-strerror_r
 gl/tests/test-string
+gl/tests/test-strings
+gl/tests/test-strnlen
+gl/tests/test-strverscmp
+gl/tests/test-symlink
 gl/tests/test-sys_ioctl
 gl/tests/test-sys_select
 gl/tests/test-sys_socket
 gl/tests/test-sys_stat
 gl/tests/test-sys_time
+gl/tests/test-sys_types
+gl/tests/test-sys_uio
+gl/tests/test-sysexits
+gl/tests/test-thread_create
+gl/tests/test-thread_self
 gl/tests/test-time
+gl/tests/test-u64
 gl/tests/test-unistd
+gl/tests/test-unsetenv
 gl/tests/test-vasnprintf
+gl/tests/test-vasprintf
 gl/tests/test-verify
 gl/tests/test-version-etc
-gl/tests/test-wchar
-gl/tests/warn-on-use.h
-gl/tests/test-float
-gl/tests/test-fseek
-gl/tests/test-ftell
-gl/tests/test-ftell3
-gl/tests/test-intprops
-gl/tests/test-inttypes
-gl/tests/test-argp
-gl/tests/test-dirent
-gl/tests/test-dup2
-gl/tests/test-environ
-gl/tests/test-frexp-nolibm
-gl/tests/test-frexpl-nolibm
-gl/tests/test-fseeko3
-gl/tests/test-fseterr
-gl/tests/test-getcwd-lgpl
-gl/tests/test-getopt
-gl/tests/test-ignore-value
-gl/tests/test-isnand-nolibm
-gl/tests/test-isnanf-nolibm
-gl/tests/test-isnanl-nolibm
-gl/tests/test-lstat
-gl/tests/test-malloc-gnu
-gl/tests/test-malloca
-gl/tests/test-math
-gl/tests/test-open
-gl/tests/test-printf-frexp
-gl/tests/test-printf-frexpl
-gl/tests/test-rawmemchr
-gl/tests/test-setenv
-gl/tests/test-signbit
-gl/tests/test-sleep
-gl/tests/test-stat
-gl/tests/test-strchrnul
-gl/tests/test-strnlen
-gl/tests/test-symlink
-gl/tests/test-sysexits
-gl/tests/test-unsetenv
 gl/tests/test-vfprintf-posix
 gl/tests/test-vprintf-posix
+gl/tests/test-vsnprintf
+gl/tests/test-wchar
+gl/tests/warn-on-use.h
+gl/time.h
 gl/time.h
 gl/unistd.h
 gl/warn-on-use.h
 gl/wchar.h
+gnutls-*.tar.*
 guile/Makefile
 guile/Makefile.in
 guile/modules/Makefile
 guile/modules/Makefile.in
+guile/modules/gnutls.scm
 guile/src/Makefile
 guile/src/Makefile.in
-guile/src/libguile-gnutls-extra-v-1.la
-guile/src/libguile-gnutls-v-1.la
+guile/src/guile-gnutls-v-2.la
 guile/tests/Makefile
 guile/tests/Makefile.in
-lib/ABOUT-NLS
-lib/INSTALL
 lib/Makefile
 lib/Makefile.in
-lib/aclocal.m4
-lib/autom4te.cache/
-lib/build-aux/config.guess
-lib/build-aux/config.sub
-lib/build-aux/depcomp
-lib/build-aux/install-sh
-lib/build-aux/ltmain.sh
-lib/build-aux/missing
-lib/config.h
-lib/config.h.in
-lib/config.log
-lib/config.status
-lib/configure
+lib/accelerated/libaccelerated.la
+lib/accelerated/x86/libx86.la
+lib/algorithms/libgnutls_alg.la
+lib/auth/libgnutls_auth.la
+lib/ext/libgnutls_ext.la
 lib/gcrypt/libcrypto.la
 lib/gnutls-api.texi
 lib/gnutls.pc
@@ -263,8 +336,24 @@ lib/includes/Makefile.in
 lib/includes/gnutls/gnutls.h
 lib/libgnutls.la
 lib/libgnutlsxx.la
-lib/libtool
+lib/minitasn1/Makefile
+lib/minitasn1/Makefile.in
+lib/minitasn1/libminitasn1.la
+lib/nettle/libcrypto.la
+lib/opencdk/Makefile
+lib/opencdk/Makefile.in
+lib/opencdk/libminiopencdk.la
+lib/openpgp/Makefile
+lib/openpgp/Makefile.in
+lib/openpgp/libgnutls_openpgp.la
+lib/openpgp/pgp-api.texi
+lib/x509/Makefile
+lib/x509/Makefile.in
+lib/x509/libgnutls_x509.la
+lib/x509/x509-api.texi
+libtool
 m4/codeset.m4
+m4/fcntl-o.m4
 m4/gettext.m4
 m4/glibc2.m4
 m4/glibc21.m4
@@ -281,11 +370,16 @@ m4/lib-ld.m4
 m4/lib-link.m4
 m4/lib-prefix.m4
 m4/libtool.m4
+m4/libtool.m4
 m4/lock.m4
 m4/longlong.m4
 m4/ltoptions.m4
+m4/ltoptions.m4
+m4/ltsugar.m4
 m4/ltsugar.m4
 m4/ltversion.m4
+m4/ltversion.m4
+m4/lt~obsolete.m4
 m4/lt~obsolete.m4
 m4/nls.m4
 m4/po.m4
@@ -293,22 +387,12 @@ m4/printf-posix.m4
 m4/progtest.m4
 m4/size_max.m4
 m4/stdint_h.m4
+m4/threadlib.m4
 m4/uintmax_t.m4
 m4/visibility.m4
 m4/wchar_t.m4
 m4/wint_t.m4
 m4/xsize.m4
-lib/minitasn1/Makefile
-lib/minitasn1/Makefile.in
-lib/minitasn1/libminitasn1.la
-lib/nettle/libcrypto.la
-lib/opencdk/Makefile
-lib/opencdk/Makefile.in
-lib/opencdk/libminiopencdk.la
-lib/openpgp/Makefile
-lib/openpgp/Makefile.in
-lib/openpgp/libgnutls_openpgp.la
-lib/openpgp/pgp-api.texi
 po/*.gmo
 po/*.po
 po/Makefile
@@ -322,51 +406,17 @@ po/address@hidden
 po/address@hidden
 po/address@hidden
 po/address@hidden
-po/insert-header.sin
 po/gnutls.pot
+po/insert-header.sin
 po/quot.sed
 po/remove-potcdate.sed
 po/remove-potcdate.sin
 po/stamp-po
-lib/stamp-h1
-lib/x509/Makefile
-lib/x509/Makefile.in
-lib/x509/libgnutls_x509.la
-lib/x509/x509-api.texi
-libextra/INSTALL
-libextra/Makefile
-libextra/Makefile.in
-libextra/aclocal.m4
-libextra/autom4te.cache/
-libextra/build-aux/config.guess
-libextra/build-aux/config.sub
-libextra/build-aux/depcomp
-libextra/build-aux/install-sh
-libextra/build-aux/ltmain.sh
-libextra/build-aux/missing
-libextra/config.h
-libextra/config.h.in
-libextra/config.log
-libextra/config.status
-libextra/configure
-libextra/gnutls-extra-api.texi
-libextra/gnutls-extra.pc
-libextra/ia-api.texi
-libextra/includes/Makefile
-libextra/includes/Makefile.in
-libextra/libgnutls-extra.la
-libextra/libgnutls-openssl.la
-libextra/libtool
-libextra/stamp-h1
-libtool
-m4/libtool.m4
-m4/ltoptions.m4
-m4/ltsugar.m4
-m4/ltversion.m4
-m4/lt~obsolete.m4
 src/Makefile
 src/Makefile.in
 src/benchmark
+src/benchmark-cipher
+src/benchmark-tls
 src/certtool
 src/cfg/Makefile
 src/cfg/Makefile.in
@@ -374,6 +424,8 @@ src/cfg/platon/Makefile
 src/cfg/platon/Makefile.in
 src/cfg/platon/str/Makefile
 src/cfg/platon/str/Makefile.in
+src/crywrap/crywrap
+src/gaa.skel
 src/gnutls-cli
 src/gnutls-cli-debug
 src/gnutls-serv
@@ -381,17 +433,19 @@ src/libcfg.la
 src/libcmd-certtool.la
 src/libcmd-cli-debug.la
 src/libcmd-cli.la
+src/libcmd-ocsp.la
 src/libcmd-p11tool.la
 src/libcmd-psk.la
 src/libcmd-serv.la
 src/libcmd-srp.la
+src/ocsptool
+src/ocsptool-gaa.c
+src/ocsptool-gaa.h
 src/p11tool
 src/psktool
 src/srptool
 stamp-h1
 tags
-tests/rng-fork
-tests/mini-eagain-dtls
 tests/*/out
 tests/Makefile
 tests/Makefile.in
@@ -400,6 +454,7 @@ tests/certder
 tests/certificate_set_x509_crl
 tests/certuniqueid
 tests/chainverify
+tests/cipher-test
 tests/crq_apis
 tests/crq_key_id
 tests/crypto_rng
@@ -413,18 +468,22 @@ tests/finished
 tests/gc
 tests/gendh
 tests/hostname-check
+tests/infoaccess
 tests/init_roundtrip
 tests/key-id/Makefile
 tests/key-id/Makefile.in
 tests/libutils.la
 tests/mini
+tests/mini-deflate
 tests/mini-eagain
+tests/mini-eagain-dtls
 tests/mini-x509
 tests/mini-x509-rehandshake
 tests/moredn
 tests/mpi
 tests/netconf-psk
 tests/nul-in-x509-names
+tests/ocsp
 tests/openpgp-auth
 tests/openpgp-auth2
 tests/openpgp-certs/Makefile
@@ -447,6 +506,7 @@ tests/pkcs8-decode/Makefile
 tests/pkcs8-decode/Makefile.in
 tests/pskself
 tests/resume
+tests/rng-fork
 tests/rsa-md5-collision/Makefile
 tests/rsa-md5-collision/Makefile.in
 tests/safe-renegotiation/Makefile
@@ -462,75 +522,15 @@ tests/sha2/Makefile.in
 tests/simple
 tests/suite/eagain-cli
 tests/suite/libecore.la
+tests/suite/x509paths/X509tests
 tests/tlsia
 tests/userid/Makefile
 tests/userid/Makefile.in
 tests/x509_altname
+tests/x509cert
+tests/x509cert-tl
 tests/x509dn
 tests/x509paths/
 tests/x509self
 tests/x509sign-verify
 tests/x509signself
-doc/examples/ex-cert-select-pkcs11
-doc/examples/ex-client-udp
-gl/tests/test-byteswap
-gl/tests/test-fcntl-h
-gl/tests/test-func
-gl/tests/test-hmac-md5
-gl/tests/test-md5
-gl/tests/test-strings
-gl/tests/test-strverscmp
-gl/tests/test-u64
-gl/tests/test-vasprintf
-gl/tests/test-vsnprintf
-gl/tests/test-intprops 
-gl/tests/test-inttypes 
-gl/tests/test-sys_uio
-gl/tests/inttypes.h 
-gl/time.h
-lib/accelerated/libaccelerated.la
-lib/accelerated/intel/libintel.la
-doc/cyclo/cyclo-gnutls.html
-lib/ext/libgnutls_ext.la
-lib/auth/libgnutls_auth.la
-tests/cipher-test
-tests/suite/x509paths/X509tests
-tests/x509cert
-src/benchmark-cipher
-src/benchmark-tls
-doc/gnutls-guile.html
-doc/version-guile.texi
-build-aux/compile
-doc/stamp-1
-lib/algorithms/libgnutls_alg.la
-gl/tests/inttypes.h
-src/crywrap/crywrap
-gl/dirent.h
-gl/getopt.h
-gl/math.h
-doc/doxygen/latex/
-doc/doxygen/html/
-doc/latex/gnutls-enums.tex
-doc/latex/enums
-doc/latex/gnutls.lof
-doc/latex/gnutls.lot
-tests/x509cert-tl
-doc/enums.texi
-doc/enums/
-tests/infoaccess
-gl/tests/test-fdopen
-gl/tests/test-fgetc
-gl/tests/test-fseeko4
-gl/tests/test-fstat
-gl/tests/test-ftello4
-gl/tests/test-pathmax
-gl/tests/test-sys_types
-tests/mini-deflate
-tests/ocsp
-TAGS
-src/ocsptool
-src/libcmd-ocsp.la
-src/ocsptool-gaa.c
-src/ocsptool-gaa.h
-doc/reference/gnutls-decl-list.txt.bak
-doc/reference/gnutls-decl.txt.bak
diff --git a/lib/COPYING b/COPYING.LESSER
similarity index 100%
rename from lib/COPYING
rename to COPYING.LESSER
diff --git a/GNUmakefile b/GNUmakefile
index 6e00ec8..86bc60f 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -45,12 +45,13 @@ include Makefile
 
 # Some projects override e.g., _autoreconf here.
 -include $(srcdir)/cfg.mk
-include $(srcdir)/maint.mk
 
 # Allow cfg.mk to override these.
 _build-aux ?= build-aux
 _autoreconf ?= autoreconf -v
 
+include $(srcdir)/maint.mk
+
 # Ensure that $(VERSION) is up to date for dist-related targets, but not
 # for others: rerunning autoreconf and recompiling everything isn't cheap.
 _have-git-version-gen := \
@@ -100,6 +101,11 @@ srcdir = .
 
 # The package can override .DEFAULT_GOAL to run actions like autoreconf.
 -include ./cfg.mk
+
+# Allow cfg.mk to override these.
+_build-aux ?= build-aux
+_autoreconf ?= autoreconf -v
+
 include ./maint.mk
 
 ifeq ($(.DEFAULT_GOAL),abort-due-to-no-makefile)
diff --git a/Makefile.am b/Makefile.am
index a02e9b7..14c2642 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,5 @@
 ## Process this file with automake to produce Makefile.in
-# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-# 2009, 2010  Free Software Foundation, Inc.
+# Copyright (C) 2000-2011 Free Software Foundation, Inc.
 #
 # Author: Nikos Mavrogiannopoulos
 #
@@ -20,9 +19,9 @@
 # along with this file; if not, write to the Free Software Foundation,
 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
-DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc
+DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc --disable-valgrind-tests
 
-SUBDIRS = gl lib libextra po src doc tests
+SUBDIRS = gl lib extra po src doc tests
 
 if HAVE_GUILE
 SUBDIRS += guile
diff --git a/NEWS b/NEWS
index e89105b..9f136bc 100644
--- a/NEWS
+++ b/NEWS
@@ -2,15 +2,117 @@ GnuTLS NEWS -- History of user-visible changes.              
  -*- outline -*-
 Copyright (C) 2000-2011 Free Software Foundation, Inc.
 See the end for copying conditions.
 
-* Version 3.0.4 (unreleased)
+* Version 3.0.8 (unreleased)
+
+** doc: man pages for API functions were removed.
+The reason was that the code that auto-generated the man pages missed
+many APIs and we couldn't fix it (volunteers welcome).  See the info
+manual or the GTK-DOC manual instead.
+
+* Version 3.0.7 (released 2011-11-08)
+
+** libgnutls: Corrected fix in gnutls_session_get_data()
+to report the actual session size when the provided buffer
+is not enough.
+
+** libgnutls: Fixed ciphersuite GNUTLS_ECDHE_RSA_AES_128_CBC_SHA256,
+which was using a wrong MAC algorithm. Reported by Fabrice Gautier.
+
+** API and ABI modifications:
+No changes since last version.
+
+
+* Version 3.0.6 (released 2011-11-07)
+
+** gnutls-guile: Compilation fixes.
+
+** libgnutls: Fixed possible buffer overflow in 
+gnutls_session_get_data(). Reported and fix by Alban Crequy.
+
+** libgnutls: Bug fixes in the ciphersuites with NULL cipher.
+Reported by Fabrice Gautier.
+
+** libgnutls: Bug fixes in ECC code for 64-bit MIPS systems. 
+Thanks to Joseph Graham for providing access to such a system.
+
+** libgnutls: Correctly report ECC private key parsing errors.
+Reported by Fabrice Gautier.
+
+** libgnutls: In ECDHE verify that the received point lies on
+the selected curve. The ECDHE ciphersuites now take precendence
+to plain DHE.
+
+** API and ABI modifications:
+No changes since last version.
+
+
+* Version 3.0.5 (released 2011-10-27)
+
+** libgnutls-extra: is no more
+
+** libgnutls: Corrections in order to compile with mingw32.
+
+** libgnutls: Corrections in VIA padlock code for VIA C5 processor
+and new detection of PHE with support for partial hashing.
+
+** libgnutls: Corrected bug in gnutls_x509_data2hex. Report and fix 
+by Vincent Untz.
+
+** minitasn1: Upgraded to libtasn1 version 2.10.
+
+** API and ABI modifications:
+No changes since last version.
+
+
+* Version 3.0.4 (released 2011-10-15)
+
+** libgnutls-extra: gnutls_register_md5_handler() was
+removed.
+
+** gnutls-cli-debug: Added more tests including AES-GCM,
+SHA256 and elliptic curves.
+
+** gnutls-cli: Added --benchmark-soft-ciphers to benchmark
+the software version of the ciphers instead of hw accelerated 
+(where available)
+
+** libgnutls: Public key ID calculation is consistent among
+all structures. It uses a SHA-1 hash of the subjectPublicKeyInfo.
+
+** libgnutls: gnutls_privkey_t allows setting external callback
+to perform signing or decryption. Can be set using
+gnutls_privkey_import_ext()
+
+** libgnutls: A certificate credentials structure can be
+used with a gnutls_privkey_t and a gnutls_pcert_st
+structure using gnutls_certificate_set_key().
+
+** libgnutls: Fixes to enable external signing callback to
+operate with TLS 1.2. 
+
+** libgnutls: Fixed crash when printing ECDSA certificate key 
+ID. Reported by Erik Jensen.
+
+** libgnutls: Corrected VIA padlock code for C3. In C3 benchmarks 
+show a 50x increase in AES speed and a 14x increase in VIA nano. Added 
+support for hashes and HMACs.
+
+** libgnutls: Compilation fixed when p11-kit is not detected.
+
+** libgnutls: Fixed the deflate compression code.
 
 ** libgnutls: Added gnutls_x509_crt_get_authority_info_access.
 Used to get the PKIX Authority Information Access (AIA) field.
 
 ** libgnutls: gnutls_x509_crt_print supports printing AIA fields.
 
+** libgnutls: Added ability to gnutls_privkey_t to operate with
+signing callback function.
+
 ** API and ABI modifications:
 gnutls_x509_crt_get_authority_info_access (x509.h): Added function.
+gnutls_privkey_import_ext: Added function.
+gnutls_certificate_set_key: Added function.
 gnutls_info_access_what_t (x509.h): Added enum.
 GNUTLS_OID_AIA (x509.h): Added symbol.
 GNUTLS_OID_AD_OCSP (x509.h): Added symbol.
diff --git a/README b/README
index 97c5ac1..9ab23d1 100644
--- a/README
+++ b/README
@@ -28,10 +28,9 @@ by running './configure --help'.
     make
     sudo make install
 
-The commands above build and install the static archives (libgnutls.a
-and libgnutls-extra.a), the shared object (libgnutls.so  and
-libgnutls-extra.so), and additional binaries such as certtool and
-gnutls-cli.
+The commands above build and install the static archive (libgnutls.a),
+the shared object (libgnutls.so), and additional binaries such as certtool 
+and gnutls-cli.
 
 The library depends on libnettle and p11-kit. Versions
 2.10.3 and prior used libgcrypt as the default cryptographic library.
@@ -93,10 +92,10 @@ Since GnuTLS version 3.0.0, the core library has been 
released under
 the GNU Lesser General Public License (LGPL) version 3 or later.
 
 The GNU LGPL applies to the main GnuTLS library, while the
-included applications as well as gnutls-extra and gnutls-openssl 
-libraries are under the GNU GPL version 3.  The gnutls library is 
+included applications as well as gnutls-openssl 
+library are under the GNU GPL version 3.  The gnutls library is 
 located in the lib/ directory, while the applications in src/ and
-gnutls-extra and gnutls-openssl library are at libextra/.
+gnutls-openssl library is at extra/.
 
 For any copyright year range specified as YYYY-ZZZZ in this package
 note that the range specifies every single year in that closed interval.
diff --git a/README-alpha b/README-alpha
index ff802e0..7939b38 100644
--- a/README-alpha
+++ b/README-alpha
@@ -1,5 +1,5 @@
 GnuTLS README-alpha -- Information for developers.              -*- outline -*-
-Copyright (C) 2009, 2010  Free Software Foundation, Inc.
+Copyright (C) 2009-2011  Free Software Foundation, Inc.
 See the end for copying conditions.
 
 This file contains instructions for developers and advanced users that
@@ -27,7 +27,8 @@ We require several tools to build the software, including:
 - Gaa <http://gaa.sf.net> (optional)
 - libtasn1 <http://josefsson.org/libtasn1/> (optional)
 - p11-kit <http://p11-glue.freedesktop.org/p11-kit.html>
-- datefudge <packages.debian.org/datefudge> (optional)
+- datefudge <http://packages.debian.org/datefudge> (optional)
+- Libidn <http://www.gnu.org/software/libidn/> (optional, for crywrap)
 
 The required software is typically distributed with your operating
 system, and the instructions for installing them differ.  Here are
@@ -38,7 +39,7 @@ sudo apt-get install git-core autoconf automake libtool 
gettext autopoint
 sudo apt-get install texinfo texlive texlive-generic-recommended 
texlive-extra-utils
 sudo apt-get install help2man gtk-doc-tools valgrind
 sudo apt-get install nettle-dev guile-1.8-dev libtasn1-3-dev libp11-kit-dev
-sudo apt-get install datefudge
+sudo apt-get install datefudge libidn11-dev
 
 To download the version controlled sources:
 
diff --git a/THANKS b/THANKS
index ca635ae..7252223 100644
--- a/THANKS
+++ b/THANKS
@@ -7,115 +7,123 @@ Here is a list of people, who helped in GnuTLS development. 
 Please
 help us to keep it complete and free of errors.  We apologise to those
 whom we no doubt have forgotten.
 
-Werner Koch                     <wk [at] gnupg.org>
-Tarun Upadhyay                  <tarun [at] poboxes.com>
-Neil Spring                     <nspring [at] saavie.org>
-Paul Sheer                      <psheer [at] icon.co.za>
-Jon Nelson                      <jnelson [at] securepipe.com>
-Simon Josefsson                 <jas [at] extundo.com>
-Marco d'Itri                    <md [at] linux.it>
-Mike Siers                      <mikes [at] poliac.com>
-Marc Huber                      <Marc.Huber [at] web.de>
-Guillaume Morin                 <guillaume [at] morinfr.org>
-Jeff Johnson                    <jbj [at] redhat.com>
-David Taylor                    <dtaylor [at] swiftdsl.com.au>
-Ivo Timmermans                  <ivo [at] o2w.nl>
-Ian Peters                      <itp [at] ximian.com>
-Arne Thomassen                  <arne [at] arne-thomassen.de>
-Casey Marshall                  <rsdio [at] metastatic.org>
-Dimitri        Papadopoulos-Orfanos    <papadopo [at] shfj.cea.fr>
-Michael Heironimus              <mkh01 [at] earthlink.net>
-Niels Bjergstrom                <njb [at] chi-publishing.com>
-Robey Pointer                   <robey [at] danger.com>
-Simon Posnjak                   <simon.posnjak [at] cetrtapot.si>
-Gerrit P. Haase                 <gp [at] familiehaase.de>
-Yoann Vandoorselaere            <yoann [at] prelude-ids.org>
-Joe Orton                       <joe [at] manyfish.co.uk>
-Stéphane LOEUILLET              <stephane.loeuillet [at] tiscali.fr>
-Aleix Conchillo Flaque          <aleix [at] member.fsf.org>
-Martijn Koster                  <mak [at] greenhills.co.uk>
-Marcin Garski                   <mgarski [at] post.pl>
-Martin Lambers                  <marlam [at] web.de>
-Michael Ringe                   <Michael.Ringe [at] aachen.utimaco.de>
-Daniel Black                    <dragonheart [at] gentoo.org>
-Scott Bronson                   <bronson [at] rinspin.com>
-Rupert Kittinger                <rkit [at] mur.at>
-Eric Leblond                    <eleblond [at] inl.fr>
-Adam Langley                    <alangley [at] gmail.com>
-Sergey Lipnevich                <sergey [at] optimaltec.com>
-Mike Castle                     <dalgoda [at] ix.netcom.com>
-Thomas Klausner                 <tk [at] giga.or.at>
-Matthias Urlichs                <smurf [at] smurf.noris.de>
-Ralph Giles                     <giles [at] onlinegamegroup.com>
-Daniel Stenberg                 <daniel [at] haxx.se>
-Jouni Malinen                   <jkmaline [at] cc.hut.fi>
-Evgeny Legerov                  <admin [at] gleg.net>
-John Heiden                     <JHeiden [at] UTNet.UToledo.Edu>
-Andreas Metzler                        <ametzler [at] downhill.at.eu.org>
-Mario Lenz                      <mario.lenz [at] gmx.net>
-Jefferson Ogata                 <Jefferson.Ogata [at] noaa.gov>
-Sascha Ziemann                  <sascha.ziemann [at] secunet.com>
-Roman Bogorodskiy               <novel [at] FreeBSD.org>
-Robert Millan                   <rmillan [at] ackstorm.es>
-Kataja Kai                      <kai.kataja [at] op.fi>
-Georg Schwarz                   <georg.schwarz [at] freenet.de>
-Michael C. Vergallen            <mvergall [at] telenet.be>
-Andrey Nosenko                  <andrew.w.nosenko [at] gmail.com>
-Nate Nielsen                    <nielsen-list [at] memberwebs.com>
-Max Kellermann                  <max [at] duempel.org>
-Ludovic Courtès                 <ludovic.courtes [at] laas.fr>
-Paul Millar                     <p.millar [at] physics.gla.ac.uk>
-Pavlov Konstantin               <thresh [at] altlinux.ru>
-Matthias Wimmer                 <m [at] tthias.eu>
-Howard Chu                      <hyc [at] symas.com>
-Dennis Vshivkov                 <walrus [at] amur.ru>
-Kristofer T. Karas              <ktk [at] enterprise.bidmc.harvard.edu>
-Marc Haber                      <mh+debian-bugs [at] zugschlus.de>
-Tim Mooney                     <tim [at] tim-the-enchanter.org>
-Daniel Kahn Gillmor             <dkg-debian.org [at] fifthhorseman.net>
-Rainer Gerhards                 <rgerhards [at] gmail.com>
-John Brooks                    <aspecialj [at] gmail.com>
-Massimo Gaspari                 <massimo.gaspari [at] alice.it>
-Marc F. Clemente                <marc [at] mclemente.net>
-Daniel Dehennin                 <nebuchadnezzar [at] asgardr.info>
-martin f krafft                 <madduck [at] debian.org>
-Sam Varshavchik                 <mrsam [at] courier-mta.com>
-Tomas Mraz                      <tmraz [at] redhat.com>
-Matthias Koenig                 <mkoenig [at] suse.de>
-Christian Grothoff              <christian [at] grothoff.org>
-James Westby                    <jw+debian [at] jameswestby.net>
-Kevin Quick                     <quick [at] sparq.org>
-Arfrever Frehtes Taifersar Arahesis <arfrever.fta [at] gmail.com>
-Jonathan Manktelow              <jonathan [at] dyalog.com>
-Thomas Viehmann                 <tv [at] beamnet.de>
-Aaron Ucko                      <ucko [at] ncbi.nlm.nih.gov>
-Anton Lavrentiev                <lavr [at] ncbi.nlm.nih.gov>
-Martin von Gagern               <Martin.vGagern [at] gmx.net>
-Douglas E. Engert               <deengert [at] anl.gov>
-Dagobert Michelsen              <dam [at] opencsw.org>
-Tom G. Christensen              <tgc [at] jupiterrise.com>
-Peter Hendrickson               <pdh [at] wiredyne.com>
-Tim Kosse                       <tim.kosse [at] filezilla-project.org>
-Fabian Keil                     <fk [at] fabiankeil.de>
-Brad Hards                      <bradh [at] frogmouth.net>
-Daiki Ueno                      <ueno [at] unixuser.org>
-Tomas Hoger                     <thoger [at] redhat.com>
-Fabian Keil                     <fk [at] fabiankeil.de>
-Jason Pettiss                   <jpettiss [at] yahoo.com>
-Ilari Liusvaara                 <ilari.liusvaara [at] elisanet.fi>
-Steve Dispensa                  <dispensa [at] phonefactor.com>
-Vitaly Mayatskikh               <v.mayatskih [at] gmail.com>
-Claudio Saavedra                <csaavedra [at] igalia.com>
-Vincent Torri                   <vincent.torri [at] gmail.com>
-Sjoerd Simons                   <sjoerd.simons [at] collabora.co.uk>
-Micah Anderson                 <micah [at] riseup.net>
-Michael Rommel                 <rommel [at] layer-7.net>
-Mark Brand                     <mabrand [at] mabrand.nl>
-Vitaly Kruglikov               <vitaly.kruglikov [at] palm.com>
-Kalle Olavi Niemitalo          <kon [at] iki.fi>
-Dash Shendy                     <admin [at] dash.za.net>
-Rickard Bellgrim                <rickard [at] opendnssec.org>
-Petr Písař                      <petr.pisar [at] atlas.cz>
+Werner Koch                     *wk [at] gnupg.org*
+Tarun Upadhyay                  *tarun [at] poboxes.com*
+Neil Spring                     *nspring [at] saavie.org*
+Paul Sheer                      *psheer [at] icon.co.za*
+Jon Nelson                      *jnelson [at] securepipe.com*
+Simon Josefsson                 *jas [at] extundo.com*
+Marco d'Itri                    *md [at] linux.it*
+Mike Siers                      *mikes [at] poliac.com*
+Marc Huber                      *Marc.Huber [at] web.de*
+Guillaume Morin                 *guillaume [at] morinfr.org*
+Jeff Johnson                    *jbj [at] redhat.com*
+David Taylor                    *dtaylor [at] swiftdsl.com.au*
+Ivo Timmermans                  *ivo [at] o2w.nl*
+Ian Peters                      *itp [at] ximian.com*
+Arne Thomassen                  *arne [at] arne-thomassen.de*
+Casey Marshall                  *rsdio [at] metastatic.org*
+Dimitri        Papadopoulos-Orfanos    *papadopo [at] shfj.cea.fr*
+Michael Heironimus              *mkh01 [at] earthlink.net*
+Niels Bjergstrom                *njb [at] chi-publishing.com*
+Robey Pointer                   *robey [at] danger.com*
+Simon Posnjak                   *simon.posnjak [at] cetrtapot.si*
+Gerrit P. Haase                 *gp [at] familiehaase.de*
+Yoann Vandoorselaere            *yoann [at] prelude-ids.org*
+Joe Orton                       *joe [at] manyfish.co.uk*
+Stéphane LOEUILLET              *stephane.loeuillet [at] tiscali.fr*
+Aleix Conchillo Flaque          *aleix [at] member.fsf.org*
+Martijn Koster                  *mak [at] greenhills.co.uk*
+Marcin Garski                   *mgarski [at] post.pl*
+Martin Lambers                  *marlam [at] web.de*
+Michael Ringe                   *Michael.Ringe [at] aachen.utimaco.de*
+Daniel Black                    *dragonheart [at] gentoo.org*
+Scott Bronson                   *bronson [at] rinspin.com*
+Rupert Kittinger                *rkit [at] mur.at*
+Eric Leblond                    *eleblond [at] inl.fr*
+Adam Langley                    *alangley [at] gmail.com*
+Sergey Lipnevich                *sergey [at] optimaltec.com*
+Mike Castle                     *dalgoda [at] ix.netcom.com*
+Thomas Klausner                 *tk [at] giga.or.at*
+Matthias Urlichs                *smurf [at] smurf.noris.de*
+Ralph Giles                     *giles [at] onlinegamegroup.com*
+Daniel Stenberg                 *daniel [at] haxx.se*
+Jouni Malinen                   *jkmaline [at] cc.hut.fi*
+Evgeny Legerov                  *admin [at] gleg.net*
+John Heiden                     *JHeiden [at] UTNet.UToledo.Edu*
+Andreas Metzler                        *ametzler [at] downhill.at.eu.org*
+Mario Lenz                      *mario.lenz [at] gmx.net*
+Jefferson Ogata                 *Jefferson.Ogata [at] noaa.gov*
+Sascha Ziemann                  *sascha.ziemann [at] secunet.com*
+Roman Bogorodskiy               *novel [at] FreeBSD.org*
+Robert Millan                   *rmillan [at] ackstorm.es*
+Kataja Kai                      *kai.kataja [at] op.fi*
+Georg Schwarz                   *georg.schwarz [at] freenet.de*
+Michael C. Vergallen            *mvergall [at] telenet.be*
+Andrey Nosenko                  *andrew.w.nosenko [at] gmail.com*
+Nate Nielsen                    *nielsen-list [at] memberwebs.com*
+Max Kellermann                  *max [at] duempel.org*
+Ludovic Courtès                 *ludovic.courtes [at] laas.fr*
+Paul Millar                     *p.millar [at] physics.gla.ac.uk*
+Pavlov Konstantin               *thresh [at] altlinux.ru*
+Matthias Wimmer                 *m [at] tthias.eu*
+Howard Chu                      *hyc [at] symas.com*
+Dennis Vshivkov                 *walrus [at] amur.ru*
+Kristofer T. Karas              *ktk [at] enterprise.bidmc.harvard.edu*
+Marc Haber                      *mh+debian-bugs [at] zugschlus.de*
+Tim Mooney                     *tim [at] tim-the-enchanter.org*
+Daniel Kahn Gillmor             *dkg-debian.org [at] fifthhorseman.net*
+Rainer Gerhards                 *rgerhards [at] gmail.com*
+John Brooks                    *aspecialj [at] gmail.com*
+Massimo Gaspari                 *massimo.gaspari [at] alice.it*
+Marc F. Clemente                *marc [at] mclemente.net*
+Daniel Dehennin                 *nebuchadnezzar [at] asgardr.info*
+martin f krafft                 *madduck [at] debian.org*
+Sam Varshavchik                 *mrsam [at] courier-mta.com*
+Tomas Mraz                      *tmraz [at] redhat.com*
+Matthias Koenig                 *mkoenig [at] suse.de*
+Christian Grothoff              *christian [at] grothoff.org*
+James Westby                    *jw+debian [at] jameswestby.net*
+Kevin Quick                     *quick [at] sparq.org*
+Arfrever Frehtes Taifersar Arahesis *arfrever.fta [at] gmail.com*
+Jonathan Manktelow              *jonathan [at] dyalog.com*
+Thomas Viehmann                 *tv [at] beamnet.de*
+Aaron Ucko                      *ucko [at] ncbi.nlm.nih.gov*
+Anton Lavrentiev                *lavr [at] ncbi.nlm.nih.gov*
+Martin von Gagern               *Martin.vGagern [at] gmx.net*
+Douglas E. Engert               *deengert [at] anl.gov*
+Dagobert Michelsen              *dam [at] opencsw.org*
+Tom G. Christensen              *tgc [at] jupiterrise.com*
+Peter Hendrickson               *pdh [at] wiredyne.com*
+Tim Kosse                       *tim.kosse [at] filezilla-project.org*
+Fabian Keil                     *fk [at] fabiankeil.de*
+Brad Hards                      *bradh [at] frogmouth.net*
+Daiki Ueno                      *ueno [at] unixuser.org*
+Tomas Hoger                     *thoger [at] redhat.com*
+Fabian Keil                     *fk [at] fabiankeil.de*
+Jason Pettiss                   *jpettiss [at] yahoo.com*
+Ilari Liusvaara                 *ilari.liusvaara [at] elisanet.fi*
+Steve Dispensa                  *dispensa [at] phonefactor.com*
+Vitaly Mayatskikh               *v.mayatskih [at] gmail.com*
+Claudio Saavedra                *csaavedra [at] igalia.com*
+Vincent Torri                   *vincent.torri [at] gmail.com*
+Sjoerd Simons                   *sjoerd.simons [at] collabora.co.uk*
+Micah Anderson                 *micah [at] riseup.net*
+Michael Rommel                 *rommel [at] layer-7.net*
+Mark Brand                     *mabrand [at] mabrand.nl*
+Vitaly Kruglikov               *vitaly.kruglikov [at] palm.com*
+Kalle Olavi Niemitalo          *kon [at] iki.fi*
+Dash Shendy                     *admin [at] dash.za.net*
+Rickard Bellgrim                *rickard [at] opendnssec.org*
+Petr Písař                      *petr.pisar [at] atlas.cz*
+Dan Winship                     *danw [at] gnome.org*
+Jonathan Nieder                 *jrnider [at] gmail.com*
+J. Cameijo Cerdeira             *cerdeira [at] co.sapo.pt*
+Benjamin Hof                    *benjamin.hof [at] stusta.net*
+Vincent Untz                    *vuntz [at] gnome.org*
+Jan Misiak                      *fijam [at] archlinux.us*
+David Hoyt                      *hoyt6 [at] llnl.gov*
+Joseph Graham                   *joe [at] t67.eu*
 
 ----------------------------------------------------------------------
 Copying and distribution of this file, with or without modification,
diff --git a/build-aux/pmccabe2html b/build-aux/pmccabe2html
index 1a4cdd1..c7cf3d0 100644
--- a/build-aux/pmccabe2html
+++ b/build-aux/pmccabe2html
@@ -1,6 +1,6 @@
 # pmccabe2html - AWK script to convert pmccabe output to html       -*- awk -*-
 
-# Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+# Copyright (C) 2007-2011 Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
diff --git a/cfg.mk b/cfg.mk
index c6b619d..5c87889 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -40,27 +40,26 @@ local-checks-to-skip = sc_GPL_version sc_bindtextdomain     
                \
        sc_require_config_h_first sc_texinfo_acronym sc_trailing_blank  \
        sc_unmarked_diagnostics sc_useless_cpp_parens
 
-VC_LIST_ALWAYS_EXCLUDE_REGEX = 
^maint.mk|(build-aux/|gl/|src/cfg/|tests/suite/ecore/|doc/protocol/).*
+VC_LIST_ALWAYS_EXCLUDE_REGEX = 
^maint.mk|(build-aux/|gl/|src/cfg/|tests/suite/ecore/|doc/protocol/).*$$
 
 # Explicit syntax-check exceptions.
-exclude_file_name_regexp--sc_cast_of_alloca_return_value = ^guile/
-exclude_file_name_regexp--sc_error_message_uppercase = 
^doc/examples/ex-cxx.cpp|guile/src/extra.c|src/certtool.c|tests/pkcs12_encode.c
+exclude_file_name_regexp--sc_cast_of_alloca_return_value = 
^guile/modules/gnutls/build/priorities.scm|guile/src/core.c$$
+exclude_file_name_regexp--sc_error_message_period = ^src/crywrap/crywrap.c$$
+exclude_file_name_regexp--sc_error_message_uppercase = 
^doc/examples/ex-cxx.cpp|guile/src/core.c|src/certtool.c|src/crywrap/crywrap.c|tests/pkcs12_encode.c$$
 exclude_file_name_regexp--sc_file_system = ^doc/doxygen/Doxyfile
-exclude_file_name_regexp--sc_prohibit_cvs_keyword = ^lib/nettle/
-exclude_file_name_regexp--sc_prohibit_doubled_word = 
^tests/rsa-md5-collision/README$$
-exclude_file_name_regexp--sc_prohibit_undesirable_word_seq = 
^tests/nist-pkits/gnutls-nist-tests.html
-exclude_file_name_regexp--sc_space_tab = 
^doc/.*.(pdf|png)|tests/nist-pkits/|tests/suite/x509paths/
+exclude_file_name_regexp--sc_prohibit_cvs_keyword = ^lib/nettle/.*$$
+exclude_file_name_regexp--sc_prohibit_undesirable_word_seq = 
^tests/nist-pkits/gnutls-nist-tests.html$$
+exclude_file_name_regexp--sc_space_tab = 
^gtk-doc.make|doc/.*.(pdf|png)|tests/nist-pkits/|tests/suite/x509paths/.*$$
 exclude_file_name_regexp--sc_two_space_separator_in_usage = 
^doc/cha-programs.texi|tests/sha2/sha2|tests/sha2/sha2-dsa$$
-exclude_file_name_regexp--sc_error_message_period = ^src/crywrap/crywrap.c$$
-exclude_file_name_regexp--sc_error_message_uppercase = 
^doc/examples/ex-cxx.cpp|guile/src/extra.c|src/certtool.c|src/crywrap/crywrap.c|tests/pkcs12_encode.c$$
 
 autoreconf:
        for f in $(PODIR)/*.po.in; do \
                cp $$f `echo $$f | sed 's/.in//'`; \
        done
        mv build-aux/config.rpath build-aux/config.rpath-
-       test -f ./configure || autoreconf --install
-       test `hostname` = "gaggia" && cp gl/m4/size_max.m4 m4/ || true
+       autopoint
+       rm -f m4/codeset.m4 m4/gettext.m4 m4/glibc21.m4 m4/glibc2.m4 
m4/iconv.m4 m4/intdiv0.m4 m4/intldir.m4 m4/intl.m4 m4/intlmacosx.m4 
m4/intmax.m4 m4/inttypes_h.m4 m4/inttypes-pri.m4 m4/lcmessage.m4 m4/lib-ld.m4 
m4/lib-link.m4 m4/lib-prefix.m4 m4/lock.m4 m4/longlong.m4 m4/nls.m4 m4/po.m4 
m4/printf-posix.m4 m4/progtest.m4 m4/size_max.m4 m4/stdint_h.m4 m4/uintmax_t.m4 
m4/wchar_t.m4 m4/wint_t.m4 m4/visibility.m4 m4/xsize.m4
+       test -f ./configure || AUTOPOINT=true autoreconf --install
        mv build-aux/config.rpath- build-aux/config.rpath
 
 update-po: refresh-po
@@ -79,6 +78,8 @@ glimport:
 # Code Coverage
 
 pre-coverage:
+       ./configure --disable-cxx
+       ln -s . gl/tests/glthread/glthread
        ln -sf /usr/local/share/gaa/gaa.skel src/gaa.skel
 
 web-coverage:
diff --git a/configure.ac b/configure.ac
index 5855f53..b92f7f8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -21,7 +21,7 @@ dnl Process this file with autoconf to produce a configure 
script.
 # USA
 
 AC_PREREQ(2.61)
-AC_INIT([GnuTLS], [3.0.3], address@hidden)
+AC_INIT([GnuTLS], [3.0.7], address@hidden)
 AC_CONFIG_AUX_DIR([build-aux])
 AC_CONFIG_MACRO_DIR([m4])
 
@@ -68,6 +68,16 @@ fi
 AM_CONDITIONAL(ENABLE_CXX, test "$use_cxx" != "no")
 AM_CONDITIONAL(WANT_TEST_SUITE, [test -f tests/suite/mini-eagain2.c])
 
+dnl Detect windows build
+case "$host" in
+  *mingw32* | *mingw64*)
+    have_win=yes
+  ;;
+  *)
+  ;;
+esac
+
+AM_CONDITIONAL(WINDOWS, test "$have_win" = yes)
 
 dnl Hardware Acceleration
 AC_ARG_ENABLE(hardware-acceleration,
@@ -75,6 +85,7 @@ AC_ARG_ENABLE(hardware-acceleration,
     use_accel=$enableval, use_accel=yes)
 hw_accel=none
 
+
 if test "$use_accel" != "no"; then
 case $host_cpu in
   i?86 | x86_64 | amd64)
@@ -96,6 +107,7 @@ fi
 
 AM_CONDITIONAL(ASM_X86_64, test x"$hw_accel" = x"x86-64")
 AM_CONDITIONAL(ASM_X86_32, test x"$hw_accel" = x"x86")
+AM_CONDITIONAL(ASM_X86, test x"$hw_accel" = x"x86" || test x"$hw_accel" = 
x"x86-64")
 AM_CONDITIONAL(HAVE_GCC_GNU89_INLINE_OPTION, test "$gnu89_inline" = "yes"])
 AM_CONDITIONAL(HAVE_GCC, test "$GCC" = "yes")
 
@@ -105,7 +117,7 @@ LIBGNUTLS_EXTRA_HOOKS
 
 GTK_DOC_CHECK(1.1)
 AM_GNU_GETTEXT([external])
-AM_GNU_GETTEXT_VERSION([0.17])
+AM_GNU_GETTEXT_VERSION([0.18])
 
 AC_C_BIGENDIAN
 
@@ -127,14 +139,13 @@ if test "$with_p11_kit" != "no"; then
        PKG_CHECK_MODULES(P11_KIT, [p11-kit-1 >= 0.4], [with_p11_kit=yes], 
[with_p11_kit=no])
        if test "$with_p11_kit" != "no";then
                AC_DEFINE([ENABLE_PKCS11], 1, [Build PKCS#11 support])
-               CFLAGS="$CFLAGS $P11_KIT_CFLAGS"
-               LIBS="$LIBS $P11_KIT_LIBS"
                if test "x$GNUTLS_REQUIRES_PRIVATE" = "x"; then
                        GNUTLS_REQUIRES_PRIVATE="Requires.private: p11-kit-1"
                else
                        GNUTLS_REQUIRES_PRIVATE="${GNUTLS_REQUIRES_PRIVATE}, 
p11-kit-1"
                fi
        else
+               with_p11_kit=no
                AC_MSG_WARN([[
 *** 
 *** p11-kit was not found. PKCS #11 support will be disabled.
@@ -205,7 +216,7 @@ if test x$ac_zlib != xno; then
     if test "x$GNUTLS_REQUIRES_PRIVATE" = x; then
       GNUTLS_REQUIRES_PRIVATE="Requires.private: zlib"
     else
-      GNUTLS_REQUIRES_PRIVATE="$GNUTLS_REQUIRES_PRIVATE , zlib"
+      GNUTLS_REQUIRES_PRIVATE="$GNUTLS_REQUIRES_PRIVATE, zlib"
     fi
   else
     GNUTLS_ZLIB_LIBS_PRIVATE="$LTLIBZ"
@@ -364,6 +375,13 @@ if test "$opt_guile_bindings" = "yes"; then
        AC_CHECK_FUNCS([scm_gc_malloc_pointerless])
        CFLAGS="$save_CFLAGS"
        LIBS="$save_LIBS"
+
+       # The place where guile-gnutls.la will go.
+       AC_MSG_CHECKING([the Guile effective version])
+       guile_effective_version="`$GUILE -c '(display (effective-version))'`"
+       AC_MSG_RESULT([$guile_effective_version])
+       guileextensiondir="$libdir/guile/$guile_effective_version"
+       AC_SUBST([guileextensiondir])
       else
         AC_MSG_RESULT([no])
         AC_MSG_WARN([A sufficiently recent GNU Guile not found.  Guile 
bindings not built.])
@@ -373,12 +391,6 @@ if test "$opt_guile_bindings" = "yes"; then
 fi
 AM_CONDITIONAL(HAVE_GUILE, test "$opt_guile_bindings" = "yes")
 
-
-LIBGNUTLS_EXTRA_LIBS="-L${libdir} -lgnutls-extra $LIBGNUTLS_LIBS"
-LIBGNUTLS_EXTRA_CFLAGS="-I${includedir}"
-AC_SUBST(LIBGNUTLS_EXTRA_LIBS)
-AC_SUBST(LIBGNUTLS_EXTRA_CFLAGS)
-
 LIBGNUTLS_LIBS="-L${libdir} -lgnutls $LIBS"
 LIBGNUTLS_CFLAGS="-I${includedir}"
 AC_SUBST(LIBGNUTLS_LIBS)
@@ -388,6 +400,10 @@ AC_SUBST(LIBGNUTLS_CFLAGS)
 AC_DEFINE([GNUTLS_COMPAT_H], 1, [Make sure we don't use old features in code.])
 AC_DEFINE([GNUTLS_INTERNAL_BUILD], 1, [We allow temporarily usage of 
deprecated functions - until they are removed.])
 
+AC_DEFINE([fread_file], [_gnutls_fread_file], [static lib rename])
+AC_DEFINE([read_file], [_gnutls_read_file], [static lib rename])
+AC_DEFINE([read_binary_file], [_gnutls_read_binary_file], [static lib rename])
+
 dnl Crywrap dependencies
    AC_MSG_RESULT([***
 *** Checking dependencies for crywrap...
@@ -433,6 +449,7 @@ AC_CONFIG_FILES([
   doc/examples/Makefile
   doc/manpages/Makefile
   doc/reference/Makefile
+  doc/reference/version.xml
   doc/scripts/Makefile
   gl/Makefile
   gl/tests/Makefile
@@ -458,9 +475,8 @@ AC_CONFIG_FILES([
   tests/rsa-md5-collision/Makefile
   tests/sha2/Makefile
   tests/userid/Makefile
-  libextra/Makefile
-  libextra/gnutls-extra.pc
-  libextra/includes/Makefile
+  extra/Makefile
+  extra/includes/Makefile
   lib/Makefile
   lib/gnutls.pc
   lib/includes/Makefile
@@ -470,11 +486,10 @@ AC_CONFIG_FILES([
   lib/openpgp/Makefile
   po/Makefile.in
   lib/x509/Makefile
-  lib/gcrypt/Makefile
   lib/nettle/Makefile
   tests/suite/Makefile
   lib/accelerated/Makefile
-  lib/accelerated/intel/Makefile
+  lib/accelerated/x86/Makefile
   lib/ext/Makefile
   lib/algorithms/Makefile
   lib/auth/Makefile
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 8f4d121..1625209 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -35,10 +35,10 @@ gnutls_TEXINFOS = gnutls.texi fdl-1.3.texi lgpl-2.1.texi 
gpl-3.0.texi       \
        cha-ciphersuites.texi cha-copying.texi cha-functions.texi       \
        cha-gtls-app.texi cha-internals.texi cha-intro-tls.texi         \
        cha-library.texi cha-preface.texi cha-programs.texi             \
-       cha-tls-app.texi cha-errors.texi cha-support.texi
+       sec-tls-app.texi cha-errors.texi cha-support.texi
 
 # Examples.
-gnutls_TEXINFOS += examples/ex-client1.c examples/ex-client2.c         \
+gnutls_TEXINFOS += examples/ex-client1.c                               \
        examples/ex-session-info.c examples/ex-verify.c                 \
        examples/ex-cert-select.c examples/ex-client-resume.c           \
        examples/ex-client-srp.c examples/ex-rfc2818.c                  \
@@ -88,9 +88,9 @@ MAINTAINERCLEANFILES =
 
 # Generated texinfos.
 
-gnutls_TEXINFOS += gnutls-api.texi extra-api.texi \
+gnutls_TEXINFOS += gnutls-api.texi \
        x509-api.texi pgp-api.texi
-MAINTAINERCLEANFILES += gnutls-api.texi extra-api.texi \
+MAINTAINERCLEANFILES += gnutls-api.texi \
        x509-api.texi pgp-api.texi
 
 gnutls-api.texi: $(srcdir)/../lib/*.c $(srcdir)/../lib/ext/*.c 
$(srcdir)/../lib/auth/*.c $(srcdir)/../lib/algorithms/*.c
@@ -126,25 +126,15 @@ pgp-api.texi: $(srcdir)/../lib/openpgp/*.c
        rm -f address@hidden
        mv -f address@hidden $@
 
-extra-api.texi: $(srcdir)/../libextra/gnutls_extra.c
-       echo "" > address@hidden
-       for i in $^; do \
-               echo -n "Creating documentation for file $$i... " && \
-               $(srcdir)/scripts/gdoc -texinfo $$i >> address@hidden && \
-               echo "ok"; \
-       done
-       $(srcdir)/scripts/sort2.pl < address@hidden > address@hidden
-       rm -f address@hidden
-       mv -f address@hidden $@
-
 # Generated texinfos.
 
 gnutls_TEXINFOS += error_codes.texi algorithms.texi alerts.texi  enums.texi
 MAINTAINERCLEANFILES += error_codes.texi algorithms.texi enums.texi
 
-AM_CPPFLAGS = -I$(top_srcdir)/lib/includes -I$(top_builddir)/lib/includes
+AM_CPPFLAGS = \
+       -I$(top_srcdir)/lib/includes -I$(top_builddir)/lib/includes
 
-noinst_PROGRAMS = errcodes printlist alert-printlist
+EXTRA_PROGRAMS = errcodes printlist alert-printlist
 
 errcodes_SOURCES = errcodes.c
 errcodes_LDADD = ../lib/libgnutls.la ../gl/libgnu.la
@@ -168,7 +158,7 @@ alerts.texi: alert-printlist
        $(builddir)/alert-printlist > address@hidden
        mv -f address@hidden $@
 
-enums.texi: $(srcdir)/../lib/includes/gnutls/*.h
+enums.texi: $(srcdir)/../lib/includes/gnutls/*.h 
$(builddir)/../lib/includes/gnutls/*.h
        echo "" > address@hidden
        for i in $^; do \
                echo -n "Creating documentation for file $$i... " && \
@@ -180,7 +170,7 @@ enums.texi: $(srcdir)/../lib/includes/gnutls/*.h
 
 # Guile texinfos.
 
-guile_texi = core.c.texi extra.c.texi
+guile_texi = core.c.texi
 BUILT_SOURCES        = $(guile_texi)
 MAINTAINERCLEANFILES += $(guile_texi)
 EXTRA_DIST           += $(guile_texi) extract-guile-c-doc.scm
@@ -194,7 +184,7 @@ GUILE_FOR_BUILD =                           \
 
 SNARF_CPPFLAGS = -I$(top_srcdir) -I$(top_builddir)                     \
         -I$(top_srcdir)/lib/includes -I$(top_builddir)/lib/includes    \
-        -I$(top_srcdir)/libextra/includes                              \
+        -I$(top_srcdir)/extra/includes                         \
          -I$(top_srcdir)/guile/src -I$(top_builddir)/guile/src         \
         $(GUILE_CFLAGS)
 
@@ -205,23 +195,11 @@ core.c.texi: $(top_srcdir)/guile/src/core.c
           -- "$^" "$(CPP)" "$(SNARF_CPPFLAGS) $(CPPFLAGS)"             \
           > "$@"
 
-extra.c.texi: $(top_srcdir)/guile/src/extra.c
-       $(MAKE) -C ../guile/src built-sources &&                        \
-       $(GUILE_FOR_BUILD) -l "$(srcdir)/extract-guile-c-doc.scm"       \
-          -e '(apply main (cdr (command-line)))'                       \
-          -- "$^" "$(CPP)" "$(SNARF_CPPFLAGS) $(CPPFLAGS)"             \
-          > "$@"
-
-
 else !HAVE_GUILE
 
 core.c.texi:
        echo "(Guile not available, documentation not generated.)" > $@
 
-extra.c.texi:
-       echo "(Guile not available, documentation not generated.)" > $@
-
-
 endif !HAVE_GUILE
 
 clean-am:
diff --git a/doc/cha-auth.texi b/doc/cha-auth.texi
index 1cfa08d..fcbe26b 100644
--- a/doc/cha-auth.texi
+++ b/doc/cha-auth.texi
@@ -83,7 +83,8 @@ certificate certifies the one before it. The trusted 
authority's
 certificate need not to be included, since the peer should possess it
 already.
 
address@hidden,gnutls_certificate_set_x509_key_mem,gnutls_certificate_set_openpgp_key,gnutls_certificate_set_openpgp_key_file,gnutls_certificate_set_openpgp_key_mem}
address@hidden,gnutls_certificate_set_openpgp_key,gnutls_certificate_set_openpgp_key_file,gnutls_certificate_set_openpgp_key_mem}
address@hidden,gnutls_certificate_set_key}
 
 @showfuncdesc{gnutls_certificate_set_x509_key_file}
 
diff --git a/doc/cha-cert-auth.texi b/doc/cha-cert-auth.texi
index f1309bd..26a23e7 100644
--- a/doc/cha-cert-auth.texi
+++ b/doc/cha-cert-auth.texi
@@ -588,7 +588,7 @@ are not extractable.
 
 @showfuncdesc{gnutls_privkey_import_x509}
 
address@hidden,gnutls_privkey_import_pkcs11}
address@hidden,gnutls_privkey_import_pkcs11,gnutls_privkey_import_ext}
 @showfuncdesc{gnutls_privkey_get_pk_algorithm}
 @showfuncdesc{gnutls_privkey_get_type}
 
diff --git a/doc/cha-functions.texi b/doc/cha-functions.texi
index 3e2f712..4df9a59 100644
--- a/doc/cha-functions.texi
+++ b/doc/cha-functions.texi
@@ -5,7 +5,6 @@
 @menu
 * Core functions::
 * X509 certificate functions::
-* GnuTLS-extra functions::
 * OpenPGP functions::
 @end menu
 
@@ -26,16 +25,6 @@ Their prototypes lie in @file{gnutls/x509.h}.
 
 @include x509-api.texi
 
address@hidden GnuTLS-extra functions
address@hidden @acronym{GnuTLS-extra} Functions
address@hidden GnuTLS-extra functions
-
-These functions are only available in the GPLv3+ version of the
-library called @code{gnutls-extra}. The prototypes for this library
-lie in @file{gnutls/extra.h}.
-
address@hidden extra-api.texi
-
 @node OpenPGP functions
 @section @acronym{OpenPGP} Functions
 @cindex OpenPGP functions
diff --git a/doc/cha-gtls-app.texi b/doc/cha-gtls-app.texi
index 5f097f4..a8b8dcc 100644
--- a/doc/cha-gtls-app.texi
+++ b/doc/cha-gtls-app.texi
@@ -37,10 +37,6 @@ defined in the header file @file{gnutls/gnutls.h}.  This 
must be
 included in all programs that make use of the @acronym{GnuTLS}
 library.
 
-The extra functionality of the @acronym{GnuTLS-extra} library is
-available by including the header file @file{gnutls/extra.h} in your
-programs.
-
 @node Initialization
 @subsection Initialization
 
@@ -50,9 +46,6 @@ allocated by the initialization process can be released if the
 application no longer has a need to call GnuTLS functions, this is
 done by calling @funcref{gnutls_global_deinit}.
 
-The extra functionality of the @acronym{GnuTLS-extra} library is
-available after calling @funcref{gnutls_global_init_extra}.
-
 In order to take advantage of the internationalization features in
 GnuTLS, such as translated error messages, the application must set
 the current locale using @code{setlocale} before initializing GnuTLS.
@@ -224,9 +217,11 @@ messages may arrive out of order.
 
 @showfuncdesc{gnutls_record_recv_seq}
 
-A helper function is available to check whether data
-to be read are pending in a @acronym{GnuTLS} session.
-This is the equivalent of @code{select} in @acronym{POSIX} systems.
+The @funcref{gnutls_record_check_pending} helper function is available to 
+allow checking whether data are available to be read in a @acronym{GnuTLS} 
session 
+buffers. Note that this function complements but does not replace 
@code{select()},
+i.e., @funcref{gnutls_record_check_pending} reports no data to be read, 
@code{select()}
+should be called to check for data in the network buffers.
 
 @showfuncdesc{gnutls_record_check_pending}
 
@@ -278,8 +273,9 @@ to generate a secret key that is used to sign a 
address@hidden key of 128 bit
 That cookie is sent to the client using @funcref{gnutls_dtls_cookie_send}, and 
 the client must reply using the correct cookie. The server side
 should verify the initial message sent by client using 
@funcref{gnutls_dtls_cookie_verify}.
-If successful a the session should be initialization and associated with
-the cookie using @funcref{gnutls_dtls_prestate_set}.
+If successful the session should be initialized and associated with
+the cookie using @funcref{gnutls_dtls_prestate_set}, before proceeding to
+the handshake.
 
 
@showfuncD{gnutls_key_generate,gnutls_dtls_cookie_send,gnutls_dtls_cookie_verify,gnutls_dtls_prestate_set}
 
@@ -486,7 +482,6 @@ implemented by another example.
 * Simple client example with X.509 certificate support::
 * Simple Datagram TLS client example::
 * Obtaining session information::
-* Verifying peer's certificate::
 * Using a callback to select the certificate to use::
 * Verifying a certificate::
 * Client using a PKCS 11 token with TLS::
@@ -509,16 +504,17 @@ However, the data is integrity and privacy protected.
 
 @node Simple client example with X.509 certificate support
 @subsection Simple client example with @acronym{X.509} certificate support
address@hidden:verify}
 
 Let's assume now that we want to create a TCP client which
 communicates with servers that use @acronym{X.509} or
 @acronym{OpenPGP} certificate authentication. The following client is
-a very simple @acronym{TLS} client, it does not support session
-resuming, not even certificate verification. The TCP functions defined
-in this example are used in most of the other examples below, without
-redefining them.
+a very simple @acronym{TLS} client, which uses the high level verification
+functions for certificates, but does not support session
+resumption. The TCP functions defined in this example are used 
+in most of the other examples below, without redefining them.
 
address@hidden examples/ex-client2.c
address@hidden examples/ex-rfc2818.c
 
 @node Simple Datagram TLS client example
 @subsection Simple datagram @acronym{TLS} client example
@@ -540,19 +536,6 @@ if called after a successful @funcref{gnutls_handshake}.
 
 @verbatiminclude examples/ex-session-info.c
 
address@hidden Verifying peer's certificate
address@hidden Verifying peer's certificate
address@hidden:verify}
-
-A @acronym{TLS} session is not secure just after the handshake
-procedure has finished.  It must be considered secure, only after the
-peer's certificate and identity have been verified. That is, you have
-to verify the signature in peer's certificate, the hostname in the
-certificate, and expiration dates.  Just after this step you should
-treat the connection as being a secure one.
-
address@hidden examples/ex-rfc2818.c
-
 @node Using a callback to select the certificate to use
 @subsection Using a callback to select the certificate to use
 
diff --git a/doc/cha-internals.texi b/doc/cha-internals.texi
index ddd2808..2347efd 100644
--- a/doc/cha-internals.texi
+++ b/doc/cha-internals.texi
@@ -314,8 +314,7 @@ as long as the LGPLv3+ applies.
 The implementation of the function should lie in the @code{ext/@-foobar.c} 
file.
 
 To make the API available in the shared library you need to add the
-symbol in @code{lib/@-libgnutls.map} or
address@hidden/@address@hidden as appropriate, so that the symbol
+symbol in @code{lib/@-libgnutls.map}, so that the symbol
 is exported properly.
 
 When writing GTK-DOC style documentation for your new APIs, don't
diff --git a/doc/cha-intro-tls.texi b/doc/cha-intro-tls.texi
index 7ede515..c25cfe1 100644
--- a/doc/cha-intro-tls.texi
+++ b/doc/cha-intro-tls.texi
@@ -29,6 +29,7 @@ noted otherwise.
 * The TLS Handshake Protocol::
 * TLS Extensions::
 * Selecting cryptographic key sizes::
+* How to use TLS in application protocols::
 * On SSL 2 and older protocols::
 @end menu
 
@@ -435,9 +436,9 @@ NORMAL:-VERS-TLS-ALL:+VERS-TLS1.0:+VERS-SSL3.0:%COMPAT
 @end verbatim
 This priority string will only enable SSL 3.0 and TLS 1.0 as protocols and
 will disable, via the @code{%COMPAT} keyword, several @acronym{TLS} protocol
-options that are known to cause compatibility problems.
-We suggest however only to use this mode if compatibility is preferred over
-security.
+options that are known to cause compatibility problems. Note however that
+there are known attacks against those protocol versions and
+if mode is used security is traded for compatibility.
 
 @node TLS Extensions
 @section TLS extensions
@@ -505,8 +506,7 @@ Clients can enable support for TLS tickets with
 @funcref{gnutls_session_ticket_enable_client} and servers use
 @funcref{gnutls_session_ticket_key_generate} to generate a key and
 @funcref{gnutls_session_ticket_enable_server} to enable the extension.
-Clients resume sessions using the ticket using the normal session
-resume functions, @ref{resume}.
+Clients resume sessions using the normal session resumption procedure (see 
@ref{resume}).
 
 @showfuncdesc{gnutls_session_ticket_key_generate}
 
@@ -697,6 +697,8 @@ Those functions will convert a human understandable 
security parameter
 of @code{gnutls_sec_param_t} type, to a number of bits suitable for a public 
 key algorithm.
 
address@hidden sec-tls-app.texi
+
 @node On SSL 2 and older protocols
 @section On SSL 2 and older protocols
 @cindex SSL 2
diff --git a/doc/cha-library.texi b/doc/cha-library.texi
index 31f9558..de34820 100644
--- a/doc/cha-library.texi
+++ b/doc/cha-library.texi
@@ -23,27 +23,23 @@ include:
 
 @item Support for handling and verification of certificates.
 
address@hidden Support for @acronym{SRP} for TLS authentication.
address@hidden Support for password authentication using @acronym{TLS-SRP}.
 
address@hidden Support for @acronym{PSK} for TLS authentication.
address@hidden Support for keyed authentication using @acronym{TLS-PSK}.
 
address@hidden Support for TLS safe renegotiation.
-
address@hidden Support for @acronym{PKCS} #11 tokens.
address@hidden Support for @acronym{PKCS} #11 tokens and smart-cards.
 
 @end itemize
 
address@hidden consists of three independent parts, namely the ``TLS
+The @acronym{GnuTLS} library consists of three independent parts, namely the 
``TLS
 protocol part'', the ``Certificate part'', and the ``Cryptographic
 back-end'' part.  The ``TLS protocol part'' is the actual protocol
 implementation, and is entirely implemented within the
 @acronym{GnuTLS} library.  The ``Certificate part'' consists of the
-certificate parsing, and verification functions which is partially
-implemented in the @acronym{GnuTLS} library.  The
address@hidden@url{http://www.gnu.org/software/libtasn1/}},
-a library which offers @acronym{ASN.1} parsing capabilities, is used
-for the @acronym{X.509} certificate parsing functions.  
-The ``Cryptographic back-end'' is provided by 
address@hidden@url{http://www.lysator.liu.se/~nisse/nettle/}}
+certificate parsing, and verification functions and it uses
+functionality from the
address@hidden@url{http://www.gnu.org/software/libtasn1/}} library.
+The ``Cryptographic back-end'' is provided by the 
address@hidden@url{http://www.lysator.liu.se/~nisse/nettle/}}
 library. 
 @menu
 * Downloading and installing::
@@ -114,10 +110,10 @@ having seen the examples at @ref{examples}.
 As shown in the figure, there is a read-only global state that is
 initialized once by the global initialization function.  This global
 structure, among others, contains the memory allocation functions
-used, and some structures needed for the @acronym{ASN.1} parser.  This
+used, and structures needed for the @acronym{ASN.1} parser.  This
 structure is never modified by any @acronym{GnuTLS} function, except
-for the deinitialization function which frees all memory allocated in
-the global structure and is called after the program has permanently
+for the deinitialization function which frees all allocated memory
+and is called after the program has permanently
 finished using @acronym{GnuTLS}.
 
 @float Figure,fig:gnutls-design
@@ -125,29 +121,23 @@ finished using @acronym{GnuTLS}.
 @caption{High level design of GnuTLS.}
 @end float
 
-The credentials structure is used by some authentication methods, such
-as certificate authentication.  A
-credentials structure may contain certificates, private keys,
-temporary parameters for Diffie-Hellman or RSA key exchange, and other
-stuff that may be shared between several TLS sessions.
-
-This structure should be initialized using the appropriate
-initialization functions. For example an application which uses
-certificate authentication would probably initialize the credentials,
-using the appropriate functions, and put its trusted certificates in
-this structure. The next step is to associate the credentials
-structure with each @acronym{TLS} session.
-
-A @acronym{GnuTLS} session contains all the required information for a
-session to handle one secure connection. This session calls directly
-to the transport layer functions, in order to communicate with the
-peer.  Every session has a unique session ID shared with the peer.
-
-Since TLS sessions can be resumed, servers would probably need a
+The credentials structures are used by the authentication methods, such
+as certificate authentication. They store certificates, privates keys,
+and other information that is needed to prove the identity to the peer,
+and/or verify the indentity of the peer. The information stored in
+the credentials structures is initialized once and then can be 
+shared by many @acronym{TLS} sessions.
+
+A @acronym{GnuTLS} session contains all the required information
+to handle one secure connection. The session communicates with the
+peers using the provided functions of the transport layer.
+Every session has a unique session ID shared with the peer.
+
+Since TLS sessions can be resumed, servers need a
 database back-end to hold the session's parameters.  Every
 @acronym{GnuTLS} session after a successful handshake calls the
-appropriate back-end function (see @ref{resume}, for information on
-initialization) to store the newly negotiated session. The session
+appropriate back-end function (see @ref{resume})
+to store the newly negotiated session. The session
 database is examined by the server just after having received the
 client address@hidden first message in a @acronym{TLS} handshake},
 and if the session ID sent by the client, matches a stored session,
@@ -192,8 +182,8 @@ verbose information on the @acronym{GnuTLS} functions 
internal flow.
 When debugging is not required, important issues, such as detected
 attacks on the protocol still need to be logged. This is provided
 by the logging function set by
address@hidden The set function
-accepts the detected error message and the corresponding
address@hidden The provided function
+will receive an message and the corresponding
 TLS session. The session information might be used to derive IP addresses
 or other information about the peer involved.
 
@@ -202,30 +192,25 @@ or other information about the peer involved.
 @node Thread safety
 @section Thread safety
 
-Although the @acronym{GnuTLS} library is thread safe by design, some
-parts of the cryptographic back-end, such as the random generator, are not.
-Applications can either call @funcref{gnutls_global_init} which will use the 
default
+The @acronym{GnuTLS} library is thread safe by design, meaning that
+objects of the library such as TLS sessions, can be safely divided across
+threads as long as a single thread accesses a single object. This is
+sufficient to support a server which handles several sessions per thread.
+If, however, an object needs to be shared across threads then access must be 
+protected with a mutex. Read-only access to objects, for example the
+credentials holding structures (see @ref{Authentication methods}), is also 
thread-safe. 
+
+The random generator of the cryptographic back-end, is not thread safe and 
requires
+mutex locks which are setup by @acronym{GnuTLS}.
+Applications can either call @funcref{gnutls_global_init} which will 
initialize the default
 operating system provided locks (i.e. @code{pthreads} on GNU/Linux and
 @code{CriticalSection} on Windows), or specify manually the locking system 
using 
 the function @funcref{gnutls_global_set_mutex} before calling 
@funcref{gnutls_global_init}. 
 Setting manually mutexes is recommended
 only to applications that have full control of the underlying libraries. If 
this
-is not the case, the use of the operating system defaults is recommended. An 
of 
-native thread usage is shown below.
-
address@hidden
-#include <gnutls.h>
-
-/* Native threads
- */
-
-int main()
address@hidden
-   gnutls_global_init();
address@hidden
address@hidden example
+is not the case, the use of the operating system defaults is recommended. An 
example of 
+non-native thread usage is shown below.
 
-When other thread packages are required the following example is applicable.
 @example
 #include <gnutls.h>
 
diff --git a/doc/cha-tls-app.texi b/doc/cha-tls-app.texi
deleted file mode 100644
index b8e83ed..0000000
--- a/doc/cha-tls-app.texi
+++ /dev/null
@@ -1,127 +0,0 @@
address@hidden How to use TLS in application protocols
address@hidden How to use @acronym{TLS} in application protocols
-
-This chapter is intended to provide some hints on how to use the
address@hidden over simple custom made application protocols.  The
-discussion below mainly refers to the @acronym{TCP/IP} transport layer
-but may be extended to other ones too.
-
address@hidden
-* Separate ports::
-* Upward negotiation::
address@hidden menu
-
address@hidden Separate ports
address@hidden Separate ports
-
-Traditionally @acronym{SSL} was used in application protocols by
-assigning a new port number for the secure services. That way two
-separate ports were assigned, one for the non secure sessions, and one
-for the secured ones. This has the benefit that if a user requests a
-secure session then the client will try to connect to the secure port
-and fail otherwise. The only possible attack with this method is a
-denial of service one. The most famous example of this method is the
-famous ``HTTP over TLS'' or @acronym{HTTPS} protocol @xcite{RFC2818}.
-
-Despite its wide use, this method is not as good as it seems.  This
-approach starts the @acronym{TLS} Handshake procedure just after the
-client connects on the ---so called--- secure port.  That way the
address@hidden protocol does not know anything about the client, and
-popular methods like the host advertising in HTTP do not
address@hidden also the Server Name Indication extension on
address@hidden  There is no way for the client to say ``I
-connected to YYY server'' before the Handshake starts, so the server
-cannot possibly know which certificate to use.
-
-Other than that it requires two separate ports to run a single
-service, which is unnecessary complication. Due to the fact that there
-is a limitation on the available privileged ports, this approach was
-soon obsoleted.
-
address@hidden Upward negotiation
address@hidden Upward negotiation
-
-Other application address@hidden LDAP, IMAP etc.}  use a
-different approach to enable the secure layer.  They use something
-often called as the ``TLS upgrade'' method. This method is quite tricky but it
-is more flexible. The idea is to extend the application protocol to
-have a ``STARTTLS'' request, whose purpose it to start the TLS
-protocols just after the client requests it.  This approach
-does not require any extra port to be reserved.
-There is even an extension to HTTP protocol to support 
-that method @xcite{RFC2817}.
-
-The tricky part, in this method, is that the ``STARTTLS'' request is
-sent in the clear, thus is vulnerable to modifications.  A typical
-attack is to modify the messages in a way that the client is fooled
-and thinks that the server does not have the ``STARTTLS'' capability.
-See a typical conversation of a hypothetical protocol:
-
address@hidden
-(client connects to the server)
-
-CLIENT: HELLO I'M MR. XXX
-
-SERVER: NICE TO MEET YOU XXX
-
-CLIENT: PLEASE START TLS
-
-SERVER: OK
-
-*** TLS STARTS
-
-CLIENT: HERE ARE SOME CONFIDENTIAL DATA
address@hidden quotation
-
-And see an example of a conversation where someone is acting
-in between:
-
address@hidden
-(client connects to the server)
-
-CLIENT: HELLO I'M MR. XXX
-
-SERVER: NICE TO MEET YOU XXX
-
-CLIENT: PLEASE START TLS
-
-(here someone inserts this message)
-
-SERVER: SORRY I DON'T HAVE THIS CAPABILITY
-
-CLIENT: HERE ARE SOME CONFIDENTIAL DATA
address@hidden quotation
-
-As you can see above the client was fooled, and was dummy enough to
-send the confidential data in the clear.
-
-How to avoid the above attack? As you may have already noticed this
-one is easy to avoid. The client has to ask the user before it
-connects whether the user requests @acronym{TLS} or not. If the user
-answered that he certainly wants the secure layer the last
-conversation should be:
-
address@hidden
-(client connects to the server)
-
-CLIENT: HELLO I'M MR. XXX
-
-SERVER: NICE TO MEET YOU XXX
-
-CLIENT: PLEASE START TLS
-
-(here someone inserts this message)
-
-SERVER: SORRY I DON'T HAVE THIS CAPABILITY
-
-CLIENT: BYE
-
-(the client notifies the user that the secure connection was not possible)
address@hidden quotation
-
-This method, if implemented properly, is far better than the
-traditional method, and the security properties remain the same, since
-only denial of service is possible. The benefit is that the server may
-request additional data before the @acronym{TLS} Handshake protocol
-starts, in order to send the correct certificate, use the correct
-password file, or anything else!
diff --git a/doc/cyclo/Makefile.am b/doc/cyclo/Makefile.am
index 31680c9..295ef2b 100644
--- a/doc/cyclo/Makefile.am
+++ b/doc/cyclo/Makefile.am
@@ -1,6 +1,5 @@
 ## Process this file with automake to produce Makefile.in
-# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2010 Free Software
-# Foundation, Inc.
+# Copyright (C) 2008-2011 Free Software Foundation, Inc.
 #
 # Author: Simon Josefsson
 #
@@ -22,13 +21,17 @@
 
 EXTRA_DIST = cyclo-gnutls.html
 
+vcurl = 
"http://git.savannah.gnu.org/gitweb/?p=gnutls.git;a=blob;f=lib/%FILENAME%;hb=HEAD";
+
 cyclo-gnutls.html:
-       $(PMCCABE) ${top_srcdir}/lib/*.[ch] ${top_srcdir}/lib/x509/*.[ch] 
${top_srcdir}/lib/openpgp/*.[ch] ${top_srcdir}/lib/opencdk/*.[ch] \
+       (cd ${top_srcdir}/lib && \
+               $(PMCCABE) `find . -type f -name \*.[ch] \
+                               | grep -v /minitasn1/ | sed 's,^./,,'` \
                | sort -nr \
-               | $(AWK) -f ${top_srcdir}/build-aux/pmccabe2html \
-                       -v lang=html -v name="$(PACKAGE_NAME)" \
-                       -v 
vcurl="http://git.savannah.gnu.org/gitweb/?p=gnutls.git;a=blob;f=%FILENAME%;hb=HEAD";
 \
+               | LANG=C $(AWK) -f ${abs_top_srcdir}/build-aux/pmccabe2html \
+                       -v lang=html -v name="$(PACKAGE_STRING)" \
+                       -v vcurl=$(vcurl) \
                        -v url="http://www.gnu.org/software/gnutls/"; \
-                       -v css=../../build-aux/pmccabe.css \
+                       -v css=${abs_top_srcdir}/build-aux/pmccabe.css) \
                        > tmp
        mv tmp $@
diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am
index 692ac6b..0ed1eae 100644
--- a/doc/examples/Makefile.am
+++ b/doc/examples/Makefile.am
@@ -23,8 +23,9 @@
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
 AM_CPPFLAGS = \
        -I$(top_srcdir)/lib/includes -I$(top_builddir)/lib/includes     \
-       -I$(top_srcdir)/libextra/includes \
-       -I$(top_srcdir)/gl
+       -I$(top_srcdir)/extra/includes \
+       -I$(top_srcdir)/gl \
+       -I$(top_builddir)/gl
 
 # Gnulib warns and suggests use of fseeko instead of fseek, which is
 # used in ex-cert-select.c, but certificate files will not be > 4 GB,
@@ -34,14 +35,13 @@ AM_CPPFLAGS += -D_GL_NO_LARGE_FILES
 AM_LDFLAGS = -no-install
 LDADD = libexamples.la                         \
        ../../lib/libgnutls.la                  \
-       ../../libextra/libgnutls-extra.la       \
        ../../gl/libgnu.la                      \
        $(LIBSOCKET) $(INET_NTOP_LIB) $(INET_PTON_LIB)
 
 CXX_LDADD = $(LDADD) \
        ../../lib/libgnutlsxx.la
 
-noinst_PROGRAMS = ex-client2 ex-client-resume ex-client-udp
+noinst_PROGRAMS = ex-client-resume ex-client-udp
 noinst_PROGRAMS += ex-cert-select ex-rfc2818
 
 if ENABLE_PKI
@@ -81,4 +81,4 @@ noinst_LTLIBRARIES = libexamples.la
 
 libexamples_la_SOURCES = examples.h ex-alert.c ex-pkcs12.c             \
        ex-session-info.c ex-x509-info.c ex-verify.c    \
-       tcp.c udp.c ex-pkcs11-list.c
+       tcp.c udp.c ex-pkcs11-list.c verify.c
diff --git a/doc/examples/ex-client-udp.c b/doc/examples/ex-client-udp.c
index a2e6ccc..7a0721a 100644
--- a/doc/examples/ex-client-udp.c
+++ b/doc/examples/ex-client-udp.c
@@ -23,6 +23,7 @@
 
 extern int udp_connect (void);
 extern void udp_close (int sd);
+extern int verify_certificate_callback (gnutls_session_t session);
 
 int
 main (void)
@@ -40,6 +41,7 @@ main (void)
 
   /* sets the trusted cas file */
   gnutls_certificate_set_x509_trust_file (xcred, CAFILE, GNUTLS_X509_FMT_PEM);
+  gnutls_certificate_set_verify_function (xcred, verify_certificate_callback);
 
   /* Initialize TLS session */
   gnutls_init (&session, GNUTLS_CLIENT | GNUTLS_DATAGRAM);
diff --git a/doc/examples/ex-client2.c b/doc/examples/ex-client2.c
deleted file mode 100644
index e58c910..0000000
--- a/doc/examples/ex-client2.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/* This example code is placed in the public domain. */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <unistd.h>
-#include <gnutls/gnutls.h>
-
-/* A very basic TLS client, with X.509 authentication.
- */
-
-#define MAX_BUF 1024
-#define CAFILE "ca.pem"
-#define MSG "GET / HTTP/1.0\r\n\r\n"
-
-extern int tcp_connect (void);
-extern void tcp_close (int sd);
-
-int
-main (void)
-{
-  int ret, sd, ii;
-  gnutls_session_t session;
-  char buffer[MAX_BUF + 1];
-  const char *err;
-  gnutls_certificate_credentials_t xcred;
-
-  gnutls_global_init ();
-
-  /* X509 stuff */
-  gnutls_certificate_allocate_credentials (&xcred);
-
-  /* sets the trusted cas file
-   */
-  gnutls_certificate_set_x509_trust_file (xcred, CAFILE, GNUTLS_X509_FMT_PEM);
-
-  /* Initialize TLS session 
-   */
-  gnutls_init (&session, GNUTLS_CLIENT);
-
-  /* Use default priorities */
-  ret = gnutls_priority_set_direct (session, "PERFORMANCE", &err);
-  if (ret < 0)
-    {
-      if (ret == GNUTLS_E_INVALID_REQUEST)
-        {
-          fprintf (stderr, "Syntax error at: %s\n", err);
-        }
-      exit (1);
-    }
-
-  /* put the x509 credentials to the current session
-   */
-  gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
-
-  /* connect to the peer
-   */
-  sd = tcp_connect ();
-
-  gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd);
-
-  /* Perform the TLS handshake
-   */
-  ret = gnutls_handshake (session);
-
-  if (ret < 0)
-    {
-      fprintf (stderr, "*** Handshake failed\n");
-      gnutls_perror (ret);
-      goto end;
-    }
-  else
-    {
-      printf ("- Handshake was completed\n");
-    }
-
-  gnutls_record_send (session, MSG, strlen (MSG));
-
-  ret = gnutls_record_recv (session, buffer, MAX_BUF);
-  if (ret == 0)
-    {
-      printf ("- Peer has closed the TLS connection\n");
-      goto end;
-    }
-  else if (ret < 0)
-    {
-      fprintf (stderr, "*** Error: %s\n", gnutls_strerror (ret));
-      goto end;
-    }
-
-  printf ("- Received %d bytes: ", ret);
-  for (ii = 0; ii < ret; ii++)
-    {
-      fputc (buffer[ii], stdout);
-    }
-  fputs ("\n", stdout);
-
-  gnutls_bye (session, GNUTLS_SHUT_RDWR);
-
-end:
-
-  tcp_close (sd);
-
-  gnutls_deinit (session);
-
-  gnutls_certificate_free_credentials (xcred);
-
-  gnutls_global_deinit ();
-
-  return 0;
-}
diff --git a/doc/examples/ex-pkcs11-list.c b/doc/examples/ex-pkcs11-list.c
index c8b4547..650ccf8 100644
--- a/doc/examples/ex-pkcs11-list.c
+++ b/doc/examples/ex-pkcs11-list.c
@@ -1,3 +1,4 @@
+#include <config.h>
 #include <gnutls/gnutls.h>
 #include <gnutls/pkcs11.h>
 #include <stdio.h>
diff --git a/doc/examples/ex-rfc2818.c b/doc/examples/ex-rfc2818.c
index 04114f4..f7aa08d 100644
--- a/doc/examples/ex-rfc2818.c
+++ b/doc/examples/ex-rfc2818.c
@@ -21,94 +21,9 @@
 
 extern int tcp_connect (void);
 extern void tcp_close (int sd);
+static int _verify_certificate_callback (gnutls_session_t session);
 
-/* This function will try to verify the peer's certificate, and
- * also check if the hostname matches, and the activation, expiration dates.
- */
-static int
-verify_certificate_callback (gnutls_session_t session)
-{
-  unsigned int status;
-  const gnutls_datum_t *cert_list;
-  unsigned int cert_list_size;
-  int ret;
-  gnutls_x509_crt_t cert;
-  const char *hostname;
-
-  /* read hostname */
-  hostname = gnutls_session_get_ptr (session);
-
-  /* This verification function uses the trusted CAs in the credentials
-   * structure. So you must have installed one or more CA certificates.
-   */
-  ret = gnutls_certificate_verify_peers2 (session, &status);
-  if (ret < 0)
-    {
-      printf ("Error\n");
-      return GNUTLS_E_CERTIFICATE_ERROR;
-    }
-
-  if (status & GNUTLS_CERT_INVALID)
-    printf ("The certificate is not trusted.\n");
-
-  if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
-    printf ("The certificate hasn't got a known issuer.\n");
-
-  if (status & GNUTLS_CERT_REVOKED)
-    printf ("The certificate has been revoked.\n");
-
-  if (status & GNUTLS_CERT_EXPIRED)
-    printf ("The certificate has expired\n");
-
-  if (status & GNUTLS_CERT_NOT_ACTIVATED)
-    printf ("The certificate is not yet activated\n");
-
-  /* Up to here the process is the same for X.509 certificates and
-   * OpenPGP keys. From now on X.509 certificates are assumed. This can
-   * be easily extended to work with openpgp keys as well.
-   */
-  if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509)
-    return GNUTLS_E_CERTIFICATE_ERROR;
-
-  if (gnutls_x509_crt_init (&cert) < 0)
-    {
-      printf ("error in initialization\n");
-      return GNUTLS_E_CERTIFICATE_ERROR;
-    }
-
-  cert_list = gnutls_certificate_get_peers (session, &cert_list_size);
-  if (cert_list == NULL)
-    {
-      printf ("No certificate was found!\n");
-      return GNUTLS_E_CERTIFICATE_ERROR;
-    }
-
-  /* This is not a real world example, since we only check the first 
-   * certificate in the given chain.
-   */
-  if (gnutls_x509_crt_import (cert, &cert_list[0], GNUTLS_X509_FMT_DER) < 0)
-    {
-      printf ("error parsing certificate\n");
-      return GNUTLS_E_CERTIFICATE_ERROR;
-    }
-
-
-  if (!gnutls_x509_crt_check_hostname (cert, hostname))
-    {
-      printf ("The certificate's owner does not match hostname '%s'\n",
-              hostname);
-      return GNUTLS_E_CERTIFICATE_ERROR;
-    }
-
-  gnutls_x509_crt_deinit (cert);
-
-  /* notify gnutls to continue handshake normally */
-  return 0;
-}
-
-
-int
-main (void)
+int main (void)
 {
   int ret, sd, ii;
   gnutls_session_t session;
@@ -124,9 +39,7 @@ main (void)
   /* sets the trusted cas file
    */
   gnutls_certificate_set_x509_trust_file (xcred, CAFILE, GNUTLS_X509_FMT_PEM);
-  gnutls_certificate_set_verify_function (xcred, verify_certificate_callback);
-  gnutls_certificate_set_verify_flags (xcred,
-                                       GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT);
+  gnutls_certificate_set_verify_function (xcred, _verify_certificate_callback);
 
   /* Initialize TLS session 
    */
@@ -135,7 +48,7 @@ main (void)
   gnutls_session_set_ptr (session, (void *) "my_host_name");
 
   /* Use default priorities */
-  ret = gnutls_priority_set_direct (session, "PERFORMANCE", &err);
+  ret = gnutls_priority_set_direct (session, "NORMAL", &err);
   if (ret < 0)
     {
       if (ret == GNUTLS_E_INVALID_REQUEST)
@@ -205,3 +118,88 @@ end:
 
   return 0;
 }
+
+/* This function will verify the peer's certificate, and check
+ * if the hostname matches, as well as the activation, expiration dates.
+ */
+static int
+_verify_certificate_callback (gnutls_session_t session)
+{
+  unsigned int status;
+  const gnutls_datum_t *cert_list;
+  unsigned int cert_list_size;
+  int ret;
+  gnutls_x509_crt_t cert;
+  const char *hostname;
+
+  /* read hostname */
+  hostname = gnutls_session_get_ptr (session);
+
+  /* This verification function uses the trusted CAs in the credentials
+   * structure. So you must have installed one or more CA certificates.
+   */
+  ret = gnutls_certificate_verify_peers2 (session, &status);
+  if (ret < 0)
+    {
+      printf ("Error\n");
+      return GNUTLS_E_CERTIFICATE_ERROR;
+    }
+
+  if (status & GNUTLS_CERT_INVALID)
+    printf ("The certificate is not trusted.\n");
+
+  if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
+    printf ("The certificate hasn't got a known issuer.\n");
+
+  if (status & GNUTLS_CERT_REVOKED)
+    printf ("The certificate has been revoked.\n");
+
+  if (status & GNUTLS_CERT_EXPIRED)
+    printf ("The certificate has expired\n");
+
+  if (status & GNUTLS_CERT_NOT_ACTIVATED)
+    printf ("The certificate is not yet activated\n");
+
+  /* Up to here the process is the same for X.509 certificates and
+   * OpenPGP keys. From now on X.509 certificates are assumed. This can
+   * be easily extended to work with openpgp keys as well.
+   */
+  if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509)
+    return GNUTLS_E_CERTIFICATE_ERROR;
+
+  if (gnutls_x509_crt_init (&cert) < 0)
+    {
+      printf ("error in initialization\n");
+      return GNUTLS_E_CERTIFICATE_ERROR;
+    }
+
+  cert_list = gnutls_certificate_get_peers (session, &cert_list_size);
+  if (cert_list == NULL)
+    {
+      printf ("No certificate was found!\n");
+      return GNUTLS_E_CERTIFICATE_ERROR;
+    }
+
+  /* This is not a real world example, since we only check the first 
+   * certificate in the given chain.
+   */
+  if (gnutls_x509_crt_import (cert, &cert_list[0], GNUTLS_X509_FMT_DER) < 0)
+    {
+      printf ("error parsing certificate\n");
+      return GNUTLS_E_CERTIFICATE_ERROR;
+    }
+
+
+  if (!gnutls_x509_crt_check_hostname (cert, hostname))
+    {
+      printf ("The certificate's owner does not match hostname '%s'\n",
+              hostname);
+      return GNUTLS_E_CERTIFICATE_ERROR;
+    }
+
+  gnutls_x509_crt_deinit (cert);
+
+  /* notify gnutls to continue handshake normally */
+  return 0;
+}
+
diff --git a/doc/examples/examples.h b/doc/examples/examples.h
index 286f4ff..e96cb26 100644
--- a/doc/examples/examples.h
+++ b/doc/examples/examples.h
@@ -3,8 +3,7 @@
 
 void check_alert (gnutls_session_t session, int ret);
 
-int
-write_pkcs12 (const gnutls_datum_t * cert,
+int write_pkcs12 (const gnutls_datum_t * cert,
               const gnutls_datum_t * pkcs8_key, const char *password);
 
 void verify_certificate (gnutls_session_t session, const char *hostname);
@@ -18,4 +17,6 @@ verify_certificate_chain (const char *hostname,
                           const gnutls_datum_t * cert_chain,
                           int cert_chain_length);
 
+int verify_certificate_callback (gnutls_session_t session);
+
 #endif /* EXAMPLES_H */
diff --git a/doc/examples/verify.c b/doc/examples/verify.c
new file mode 100644
index 0000000..d02440a
--- /dev/null
+++ b/doc/examples/verify.c
@@ -0,0 +1,91 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <gnutls/gnutls.h>
+#include <gnutls/x509.h>
+
+#include "examples.h"
+
+int verify_certificate_callback (gnutls_session_t session)
+{
+  unsigned int status;
+  const gnutls_datum_t *cert_list;
+  unsigned int cert_list_size;
+  int ret;
+  gnutls_x509_crt_t cert;
+  const char *hostname;
+
+  /* read hostname */
+  hostname = gnutls_session_get_ptr (session);
+
+  /* This verification function uses the trusted CAs in the credentials
+   * structure. So you must have installed one or more CA certificates.
+   */
+  ret = gnutls_certificate_verify_peers2 (session, &status);
+  if (ret < 0)
+    {
+      printf ("Error\n");
+      return GNUTLS_E_CERTIFICATE_ERROR;
+    }
+
+  if (status & GNUTLS_CERT_INVALID)
+    printf ("The certificate is not trusted.\n");
+
+  if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
+    printf ("The certificate hasn't got a known issuer.\n");
+
+  if (status & GNUTLS_CERT_REVOKED)
+    printf ("The certificate has been revoked.\n");
+
+  if (status & GNUTLS_CERT_EXPIRED)
+    printf ("The certificate has expired\n");
+
+  if (status & GNUTLS_CERT_NOT_ACTIVATED)
+    printf ("The certificate is not yet activated\n");
+
+  /* Up to here the process is the same for X.509 certificates and
+   * OpenPGP keys. From now on X.509 certificates are assumed. This can
+   * be easily extended to work with openpgp keys as well.
+   */
+  if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509)
+    return GNUTLS_E_CERTIFICATE_ERROR;
+
+  if (gnutls_x509_crt_init (&cert) < 0)
+    {
+      printf ("error in initialization\n");
+      return GNUTLS_E_CERTIFICATE_ERROR;
+    }
+
+  cert_list = gnutls_certificate_get_peers (session, &cert_list_size);
+  if (cert_list == NULL)
+    {
+      printf ("No certificate was found!\n");
+      return GNUTLS_E_CERTIFICATE_ERROR;
+    }
+
+  /* This is not a real world example, since we only check the first 
+   * certificate in the given chain.
+   */
+  if (gnutls_x509_crt_import (cert, &cert_list[0], GNUTLS_X509_FMT_DER) < 0)
+    {
+      printf ("error parsing certificate\n");
+      return GNUTLS_E_CERTIFICATE_ERROR;
+    }
+
+
+  if (!gnutls_x509_crt_check_hostname (cert, hostname))
+    {
+      printf ("The certificate's owner does not match hostname '%s'\n",
+              hostname);
+      return GNUTLS_E_CERTIFICATE_ERROR;
+    }
+
+  gnutls_x509_crt_deinit (cert);
+
+  /* notify gnutls to continue handshake normally */
+  return 0;
+}
diff --git a/doc/gnutls-guile.texi b/doc/gnutls-guile.texi
index 915aa97..eff631c 100644
--- a/doc/gnutls-guile.texi
+++ b/doc/gnutls-guile.texi
@@ -83,11 +83,13 @@ a large subset thereof is available.
 @node Guile Preparations
 @chapter Guile Preparations
 
-The GnuTLS Guile bindings are by default installed under the GnuTLS
-installation directory (e.g., typically
address@hidden/usr/local/share/guile/site/}).  Normally Guile will not find
-the module there without help.  You may experience something like
-this:
+The GnuTLS Guile bindings are available for both the 1.8 and 2.0 stable
+series of Guile.
+
+By default they are installed under the GnuTLS installation directory,
+typically @file{/usr/local/share/guile/site/}).  Normally Guile
+will not find the module there without help.  You may experience
+something like this:
 
 @example
 $ guile
@@ -196,7 +198,7 @@ of the wrong type on the Scheme side: such errors are 
automatically
 detected by type-checking.
 
 The enumerate values are bound to variables exported by the
address@hidden(gnutls)} and @code{(gnutls extra)} modules.  These variables
address@hidden(gnutls)} module.  These variables
 are named according to the following convention:
 
 @itemize
@@ -532,8 +534,7 @@ This is it!
 @node OpenPGP Authentication Guile Example
 @section OpenPGP Authentication Guile Example
 
-GnuTLS allows users to authenticate using OpenPGP certificates.  The
-relevant procedures are provided by the @code{(gnutls extra)} module.
+GnuTLS allows users to authenticate using OpenPGP certificates.
 Using OpenPGP-based authentication is not more complicated than using
 anonymous authentication.  It requires a bit of extra work, though, to
 import the OpenPGP public and private key of the client/server.  Key
@@ -603,7 +604,8 @@ Similarly, server-side code would be along these lines:
 
 In practice, generating RSA parameters (and Diffie-Hellman parameters)
 can time a long time.  Thus, you may want to generate them once and
-store them in a file for future re-use (@pxref{Core Interface, 
@code{pkcs1-export-rsa-parameters} and @code{pkcs1-import-rsa-parameters}}).
+store them in a file for future re-use (@pxref{Guile Reference,
address@hidden and @code{pkcs1-import-rsa-parameters}}).
 
 @node Importing OpenPGP Keys Guile Example
 @section Importing OpenPGP Keys Guile Example
@@ -611,14 +613,14 @@ store them in a file for future re-use (@pxref{Core 
Interface, @code{pkcs1-expor
 The following example provides a simple way of importing
 ``ASCII-armored'' OpenPGP keys from files, using the
 @code{import-openpgp-certificate} and @code{import-openpgp-private-key}
-procedures provided by the @code{(gnutls extra)} module.
+procedures.
 
 @vindex openpgp-certificate-format/base64
 @vindex openpgp-certificate-format/raw
 
 @example
 (use-modules (srfi srfi-4)
-             (gnutls extra))
+             (gnutls))
 
 (define (import-key-from-file import-proc file)
   ;; Import OpenPGP key from FILE using IMPORT-PROC.
@@ -645,46 +647,19 @@ procedures provided by the @code{(gnutls extra)} module.
 The procedures @code{import-public-key-from-file} and
 @code{import-private-key-from-file} can be passed a file name.  They
 return an OpenPGP public key and private key object, respectively
-(@pxref{Extra Interface, OpenPGP key objects}).
+(@pxref{Guile Reference, OpenPGP key objects}).
 
 
 @c *********************************************************************
 @node Guile Reference
 @chapter Guile Reference
 
-This chapter documents GnuTLS Scheme procedures available to Guile
-programmers.
-
address@hidden
-* Core Interface::              Bindings for core GnuTLS.
-* Extra Interface::             Bindings for GnuTLS-Extra.
address@hidden menu
-
address@hidden Core Interface
address@hidden Core Interface
-
-This section lists the Scheme procedures exported by the
+This chapter lists the GnuTLS Scheme procedures exported by the
 @code{(gnutls)} module (@pxref{The Guile module system,,, guile, The
-GNU Guile Reference Manual}).  This module is licenced under the GNU
-Lesser General Public Licence, version 2.1 or later.
+GNU Guile Reference Manual}).
 
 @include core.c.texi
 
address@hidden Extra Interface
address@hidden Extra Interface
-
-This section lists the Scheme procedures exported by the @code{(gnutls
-extra)} module.  This module is licenced under the GNU General Public
-Licence, version 3 or later.
-
address@hidden extra.c.texi
-
-
-
address@hidden
-;;; arch-tag: ee5f2081-9153-48fc-b4ee-2024381c65d7
address@hidden ignore
-
 @c Local Variables:
 @c ispell-local-dictionary: "american"
 @c End:
diff --git a/doc/gnutls.texi b/doc/gnutls.texi
index 07bf825..fa27d27 100644
--- a/doc/gnutls.texi
+++ b/doc/gnutls.texi
@@ -17,7 +17,7 @@
 This manual is last updated @value{UPDATED} for version
 @value{VERSION} of GnuTLS.
 
-Copyright @copyright{} 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 
2010, 2011 Free Software Foundation, Inc.
+Copyright @copyright{} 2001-2011 Free Software Foundation, Inc.
 
 @quotation
 Permission is granted to copy, distribute and/or modify this document
@@ -152,7 +152,6 @@ Documentation License''.
 * Authentication methods::
 * More on certificate authentication::
 * How to use GnuTLS in applications::
-* How to use TLS in application protocols::
 * Included programs::
 * Internal architecture of GnuTLS::
 * Support::
@@ -178,8 +177,6 @@ Documentation License''.
 
 @include cha-gtls-app.texi
 
address@hidden cha-tls-app.texi
-
 @include cha-programs.texi
 
 @include cha-internals.texi
diff --git a/doc/latex/.gitignore b/doc/latex/.gitignore
index 21a5a9c..6d679f3 100644
--- a/doc/latex/.gitignore
+++ b/doc/latex/.gitignore
@@ -34,3 +34,4 @@ gnutls.4tc
 gnutls.dvi
 gnutls.tmp
 gnutls.xref
+sec-tls-app.tex
diff --git a/doc/latex/Makefile.am b/doc/latex/Makefile.am
index 3a030d1..0d8ded7 100644
--- a/doc/latex/Makefile.am
+++ b/doc/latex/Makefile.am
@@ -2,7 +2,7 @@ TEX_OBJECTS = gnutls.tex macros.tex macros-epub.tex fdl.tex 
cover.tex gnutls.bib
        cover-epub.tex
 
 GEN_TEX_OBJECTS = cha-preface.tex cha-library.tex cha-intro-tls.tex 
cha-auth.tex \
-  cha-cert-auth.tex cha-gtls-app.tex cha-tls-app.tex cha-programs.tex 
cha-support.tex \
+  cha-cert-auth.tex cha-gtls-app.tex sec-tls-app.tex cha-programs.tex 
cha-support.tex \
   cha-functions.tex error_codes.tex cha-ciphersuites.tex algorithms.tex \
   cha-errors.tex alerts.tex cha-internals.tex
 
@@ -24,7 +24,7 @@ cha-cert-auth.tex: ../cha-cert-auth.texi
 cha-gtls-app.tex: ../cha-gtls-app.texi
        ../scripts/mytexi2latex $< > $@
 
-cha-tls-app.tex: ../cha-tls-app.texi
+sec-tls-app.tex: ../sec-tls-app.texi
        ../scripts/mytexi2latex $< > $@
 
 cha-programs.tex: ../cha-programs.texi
@@ -106,19 +106,7 @@ pgp-api.tex: $(srcdir)/../../lib/openpgp/*.c
        rm -f address@hidden
        mv -f address@hidden $@
 
-extra-api.tex: $(srcdir)/../../libextra/gnutls_extra.c
-       echo "" > address@hidden
-       for i in $^; do \
-               echo -n "Creating documentation for file $$i... " && \
-               $(srcdir)/../scripts/gdoc -tex $$i >> address@hidden && \
-               echo "ok"; \
-       done
-       $(srcdir)/../scripts/sort1.pl < address@hidden > address@hidden
-       $(srcdir)/../scripts/split.pl functions < address@hidden 
-       rm -f address@hidden
-       mv -f address@hidden $@
-
-SOURCE_GEN_FILES =  extra-api.tex pgp-api.tex x509-api.tex gnutls-api.tex 
gnutls-enums.tex
+SOURCE_GEN_FILES =  pgp-api.tex x509-api.tex gnutls-api.tex gnutls-enums.tex
 
 PDF_FILES = gnutls-client-server-use-case.pdf gnutls-crypto-layers.pdf \
        gnutls-handshake-sequence.pdf gnutls-handshake-state.pdf \
diff --git a/doc/latex/gnutls.tex b/doc/latex/gnutls.tex
index 89b92e5..bf4aaaf 100644
--- a/doc/latex/gnutls.tex
+++ b/doc/latex/gnutls.tex
@@ -68,8 +68,6 @@
 
 \input{cha-gtls-app}
 
-\input{cha-tls-app}
-
 \input{cha-programs}
 
 \input{cha-internals}
diff --git a/doc/manpages/Makefile.am b/doc/manpages/Makefile.am
index c97d906..081cb98 100644
--- a/doc/manpages/Makefile.am
+++ b/doc/manpages/Makefile.am
@@ -1,6 +1,5 @@
 ## Process this file with automake to produce Makefile.in
-# Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
-# Software Foundation, Inc.
+# Copyright (C) 2003-2011 Free Software Foundation, Inc.
 #
 # Author: Nikos Mavroyanopoulos, Simon Josefsson
 #
@@ -26,751 +25,3 @@ dist_man_MANS = gnutls-cli.1 gnutls-cli-debug.1 
gnutls-serv.1       \
 if ENABLE_SRP
 dist_man_MANS += srptool.1
 endif
-
-APIMANS =
-APIMANS += gnutls_cipher_init.3
-APIMANS += gnutls_cipher_tag.3
-APIMANS += gnutls_cipher_add_auth.3
-APIMANS += gnutls_cipher_set_iv.3
-APIMANS += gnutls_cipher_encrypt.3
-APIMANS += gnutls_cipher_decrypt.3
-APIMANS += gnutls_cipher_encrypt2.3
-APIMANS += gnutls_cipher_decrypt2.3
-APIMANS += gnutls_cipher_deinit.3
-APIMANS += gnutls_hmac_init.3
-APIMANS += gnutls_hmac.3
-APIMANS += gnutls_hmac_output.3
-APIMANS += gnutls_hmac_deinit.3
-APIMANS += gnutls_hmac_get_len.3
-APIMANS += gnutls_hmac_fast.3
-APIMANS += gnutls_hash_init.3
-APIMANS += gnutls_hash.3
-APIMANS += gnutls_hash_output.3
-APIMANS += gnutls_hash_deinit.3
-APIMANS += gnutls_hash_get_len.3
-APIMANS += gnutls_hash_fast.3
-APIMANS += gnutls_key_generate.3
-APIMANS += gnutls_alert_get_name.3
-APIMANS += gnutls_alert_get_strname.3
-APIMANS += gnutls_alert_send.3
-APIMANS += gnutls_error_to_alert.3
-APIMANS += gnutls_alert_send_appropriate.3
-APIMANS += gnutls_alert_get.3
-APIMANS += gnutls_anon_free_server_credentials.3
-APIMANS += gnutls_anon_allocate_server_credentials.3
-APIMANS += gnutls_anon_free_client_credentials.3
-APIMANS += gnutls_anon_allocate_client_credentials.3
-APIMANS += gnutls_anon_set_server_dh_params.3
-APIMANS += gnutls_anon_set_server_params_function.3
-APIMANS += gnutls_credentials_clear.3
-APIMANS += gnutls_credentials_set.3
-APIMANS += gnutls_auth_get_type.3
-APIMANS += gnutls_auth_server_get_type.3
-APIMANS += gnutls_auth_client_get_type.3
-APIMANS += gnutls_record_check_pending.3
-APIMANS += gnutls_certificate_free_keys.3
-APIMANS += gnutls_certificate_free_cas.3
-APIMANS += gnutls_certificate_get_issuer.3
-APIMANS += gnutls_certificate_free_ca_names.3
-APIMANS += gnutls_certificate_free_credentials.3
-APIMANS += gnutls_certificate_allocate_credentials.3
-APIMANS += gnutls_certificate_server_set_request.3
-APIMANS += gnutls_certificate_client_set_retrieve_function.3
-APIMANS += gnutls_certificate_server_set_retrieve_function.3
-APIMANS += gnutls_certificate_set_retrieve_function.3
-APIMANS += gnutls_certificate_set_retrieve_function2.3
-APIMANS += gnutls_certificate_set_verify_function.3
-APIMANS += gnutls_certificate_verify_peers2.3
-APIMANS += gnutls_certificate_expiration_time_peers.3
-APIMANS += gnutls_certificate_activation_time_peers.3
-APIMANS += gnutls_sign_callback_set.3
-APIMANS += gnutls_sign_callback_get.3
-APIMANS += gnutls_compression_get_name.3
-APIMANS += gnutls_compression_get_id.3
-APIMANS += gnutls_compression_list.3
-APIMANS += gnutls_db_set_retrieve_function.3
-APIMANS += gnutls_db_set_remove_function.3
-APIMANS += gnutls_db_set_store_function.3
-APIMANS += gnutls_db_set_ptr.3
-APIMANS += gnutls_db_get_ptr.3
-APIMANS += gnutls_db_set_cache_expiration.3
-APIMANS += gnutls_db_check_entry.3
-APIMANS += gnutls_db_remove_session.3
-APIMANS += gnutls_dh_params_import_raw.3
-APIMANS += gnutls_dh_params_init.3
-APIMANS += gnutls_dh_params_deinit.3
-APIMANS += gnutls_dh_params_cpy.3
-APIMANS += gnutls_dh_params_generate2.3
-APIMANS += gnutls_dh_params_import_pkcs3.3
-APIMANS += gnutls_dh_params_export_pkcs3.3
-APIMANS += gnutls_dh_params_export_raw.3
-APIMANS += gnutls_dtls_set_timeouts.3
-APIMANS += gnutls_dtls_set_mtu.3
-APIMANS += gnutls_dtls_get_data_mtu.3
-APIMANS += gnutls_dtls_get_mtu.3
-APIMANS += gnutls_dtls_cookie_send.3
-APIMANS += gnutls_dtls_cookie_verify.3
-APIMANS += gnutls_dtls_prestate_set.3
-APIMANS += gnutls_record_get_discarded.3
-APIMANS += gnutls_error_is_fatal.3
-APIMANS += gnutls_perror.3
-APIMANS += gnutls_strerror.3
-APIMANS += gnutls_strerror_name.3
-APIMANS += gnutls_global_set_log_function.3
-APIMANS += gnutls_global_set_audit_log_function.3
-APIMANS += gnutls_global_set_time_function.3
-APIMANS += gnutls_global_set_log_level.3
-APIMANS += gnutls_global_set_mem_functions.3
-APIMANS += gnutls_global_init.3
-APIMANS += gnutls_global_deinit.3
-APIMANS += gnutls_check_version.3
-APIMANS += gnutls_rehandshake.3
-APIMANS += gnutls_handshake.3
-APIMANS += gnutls_handshake_set_max_packet_length.3
-APIMANS += gnutls_handshake_get_last_in.3
-APIMANS += gnutls_handshake_get_last_out.3
-APIMANS += gnutls_malloc.3
-APIMANS += gnutls_free.3
-APIMANS += gnutls_pcert_import_x509.3
-APIMANS += gnutls_pcert_list_import_x509_raw.3
-APIMANS += gnutls_pcert_import_x509_raw.3
-APIMANS += gnutls_pcert_import_openpgp.3
-APIMANS += gnutls_pcert_import_openpgp_raw.3
-APIMANS += gnutls_pcert_deinit.3
-APIMANS += gnutls_cipher_set_priority.3
-APIMANS += gnutls_kx_set_priority.3
-APIMANS += gnutls_mac_set_priority.3
-APIMANS += gnutls_compression_set_priority.3
-APIMANS += gnutls_protocol_set_priority.3
-APIMANS += gnutls_certificate_type_set_priority.3
-APIMANS += gnutls_priority_set.3
-APIMANS += gnutls_priority_init.3
-APIMANS += gnutls_priority_deinit.3
-APIMANS += gnutls_priority_set_direct.3
-APIMANS += gnutls_set_default_priority.3
-APIMANS += gnutls_set_default_export_priority.3
-APIMANS += gnutls_privkey_get_type.3
-APIMANS += gnutls_privkey_get_pk_algorithm.3
-APIMANS += gnutls_privkey_init.3
-APIMANS += gnutls_privkey_deinit.3
-APIMANS += gnutls_privkey_import_pkcs11.3
-APIMANS += gnutls_privkey_import_x509.3
-APIMANS += gnutls_privkey_import_openpgp.3
-APIMANS += gnutls_privkey_sign_data.3
-APIMANS += gnutls_privkey_sign_hash.3
-APIMANS += gnutls_privkey_decrypt_data.3
-APIMANS += gnutls_psk_free_client_credentials.3
-APIMANS += gnutls_psk_allocate_client_credentials.3
-APIMANS += gnutls_psk_set_client_credentials.3
-APIMANS += gnutls_psk_free_server_credentials.3
-APIMANS += gnutls_psk_allocate_server_credentials.3
-APIMANS += gnutls_psk_set_server_credentials_file.3
-APIMANS += gnutls_psk_set_server_credentials_hint.3
-APIMANS += gnutls_psk_set_server_credentials_function.3
-APIMANS += gnutls_psk_set_client_credentials_function.3
-APIMANS += gnutls_psk_server_get_username.3
-APIMANS += gnutls_psk_client_get_hint.3
-APIMANS += gnutls_hex_decode.3
-APIMANS += gnutls_hex_encode.3
-APIMANS += gnutls_psk_set_server_dh_params.3
-APIMANS += gnutls_psk_set_server_params_function.3
-APIMANS += gnutls_pubkey_get_pk_algorithm.3
-APIMANS += gnutls_pubkey_get_key_usage.3
-APIMANS += gnutls_pubkey_init.3
-APIMANS += gnutls_pubkey_deinit.3
-APIMANS += gnutls_pubkey_import_x509.3
-APIMANS += gnutls_pubkey_import_privkey.3
-APIMANS += gnutls_pubkey_get_preferred_hash_algorithm.3
-APIMANS += gnutls_pubkey_import_pkcs11.3
-APIMANS += gnutls_pubkey_import_openpgp.3
-APIMANS += gnutls_pubkey_get_openpgp_key_id.3
-APIMANS += gnutls_pubkey_export.3
-APIMANS += gnutls_pubkey_get_key_id.3
-APIMANS += gnutls_pubkey_get_pk_rsa_raw.3
-APIMANS += gnutls_pubkey_get_pk_dsa_raw.3
-APIMANS += gnutls_pubkey_get_pk_ecc_raw.3
-APIMANS += gnutls_pubkey_get_pk_ecc_x962.3
-APIMANS += gnutls_pubkey_import.3
-APIMANS += gnutls_x509_crt_set_pubkey.3
-APIMANS += gnutls_x509_crq_set_pubkey.3
-APIMANS += gnutls_pubkey_set_key_usage.3
-APIMANS += gnutls_pubkey_import_pkcs11_url.3
-APIMANS += gnutls_pubkey_import_rsa_raw.3
-APIMANS += gnutls_pubkey_import_ecc_raw.3
-APIMANS += gnutls_pubkey_import_ecc_x962.3
-APIMANS += gnutls_pubkey_import_dsa_raw.3
-APIMANS += gnutls_pubkey_verify_data.3
-APIMANS += gnutls_pubkey_verify_data2.3
-APIMANS += gnutls_pubkey_verify_hash.3
-APIMANS += gnutls_pubkey_get_verify_algorithm.3
-APIMANS += gnutls_protocol_get_version.3
-APIMANS += gnutls_record_disable_padding.3
-APIMANS += gnutls_transport_set_ptr.3
-APIMANS += gnutls_transport_set_ptr2.3
-APIMANS += gnutls_transport_get_ptr.3
-APIMANS += gnutls_transport_get_ptr2.3
-APIMANS += gnutls_bye.3
-APIMANS += gnutls_record_send.3
-APIMANS += gnutls_record_recv.3
-APIMANS += gnutls_record_recv_seq.3
-APIMANS += gnutls_rsa_params_import_raw.3
-APIMANS += gnutls_rsa_params_init.3
-APIMANS += gnutls_rsa_params_deinit.3
-APIMANS += gnutls_rsa_params_cpy.3
-APIMANS += gnutls_rsa_params_generate2.3
-APIMANS += gnutls_rsa_params_import_pkcs1.3
-APIMANS += gnutls_rsa_params_export_pkcs1.3
-APIMANS += gnutls_rsa_params_export_raw.3
-APIMANS += gnutls_session_get_data.3
-APIMANS += gnutls_session_get_data2.3
-APIMANS += gnutls_session_get_id.3
-APIMANS += gnutls_session_set_data.3
-APIMANS += gnutls_cipher_get.3
-APIMANS += gnutls_certificate_type_get.3
-APIMANS += gnutls_kx_get.3
-APIMANS += gnutls_mac_get.3
-APIMANS += gnutls_compression_get.3
-APIMANS += gnutls_init.3
-APIMANS += gnutls_deinit.3
-APIMANS += gnutls_openpgp_send_cert.3
-APIMANS += gnutls_certificate_send_x509_rdn_sequence.3
-APIMANS += gnutls_handshake_set_private_extensions.3
-APIMANS += gnutls_prf_raw.3
-APIMANS += gnutls_prf.3
-APIMANS += gnutls_session_is_resumed.3
-APIMANS += gnutls_session_get_ptr.3
-APIMANS += gnutls_session_set_ptr.3
-APIMANS += gnutls_record_get_direction.3
-APIMANS += gnutls_handshake_set_post_client_hello_function.3
-APIMANS += gnutls_session_enable_compatibility_mode.3
-APIMANS += gnutls_session_channel_binding.3
-APIMANS += gnutls_ecc_curve_get.3
-APIMANS += gnutls_hex2bin.3
-APIMANS += gnutls_supplemental_get_name.3
-APIMANS += gnutls_dh_set_prime_bits.3
-APIMANS += gnutls_dh_get_group.3
-APIMANS += gnutls_dh_get_pubkey.3
-APIMANS += gnutls_rsa_export_get_pubkey.3
-APIMANS += gnutls_dh_get_secret_bits.3
-APIMANS += gnutls_dh_get_prime_bits.3
-APIMANS += gnutls_rsa_export_get_modulus_bits.3
-APIMANS += gnutls_dh_get_peers_public_bits.3
-APIMANS += gnutls_certificate_get_ours.3
-APIMANS += gnutls_certificate_get_peers.3
-APIMANS += gnutls_certificate_client_get_request_status.3
-APIMANS += gnutls_fingerprint.3
-APIMANS += gnutls_certificate_set_dh_params.3
-APIMANS += gnutls_certificate_set_params_function.3
-APIMANS += gnutls_certificate_set_verify_flags.3
-APIMANS += gnutls_certificate_set_verify_limits.3
-APIMANS += gnutls_certificate_set_rsa_export_params.3
-APIMANS += gnutls_psk_set_params_function.3
-APIMANS += gnutls_anon_set_params_function.3
-APIMANS += gnutls_certificate_set_x509_key_mem.3
-APIMANS += gnutls_certificate_set_x509_key.3
-APIMANS += gnutls_certificate_set_x509_key_file.3
-APIMANS += gnutls_certificate_set_x509_trust_mem.3
-APIMANS += gnutls_certificate_set_x509_trust.3
-APIMANS += gnutls_certificate_set_x509_trust_file.3
-APIMANS += gnutls_certificate_set_x509_crl_mem.3
-APIMANS += gnutls_certificate_set_x509_crl.3
-APIMANS += gnutls_certificate_set_x509_crl_file.3
-APIMANS += gnutls_certificate_set_x509_simple_pkcs12_file.3
-APIMANS += gnutls_certificate_set_x509_simple_pkcs12_mem.3
-APIMANS += gnutls_certificate_free_crls.3
-APIMANS += gnutls_global_set_mutex.3
-APIMANS += gnutls_pkcs11_add_provider.3
-APIMANS += gnutls_pkcs11_obj_get_info.3
-APIMANS += gnutls_pkcs11_init.3
-APIMANS += gnutls_pkcs11_deinit.3
-APIMANS += gnutls_pkcs11_set_pin_function.3
-APIMANS += gnutls_pkcs11_set_token_function.3
-APIMANS += gnutls_pkcs11_obj_init.3
-APIMANS += gnutls_pkcs11_obj_deinit.3
-APIMANS += gnutls_pkcs11_obj_export.3
-APIMANS += gnutls_pkcs11_obj_import_url.3
-APIMANS += gnutls_pkcs11_token_get_url.3
-APIMANS += gnutls_pkcs11_token_get_info.3
-APIMANS += gnutls_pkcs11_obj_export_url.3
-APIMANS += gnutls_pkcs11_obj_get_type.3
-APIMANS += gnutls_pkcs11_obj_list_import_url.3
-APIMANS += gnutls_x509_crt_import_pkcs11_url.3
-APIMANS += gnutls_x509_crt_import_pkcs11.3
-APIMANS += gnutls_x509_crt_list_import_pkcs11.3
-APIMANS += gnutls_pkcs11_token_get_flags.3
-APIMANS += gnutls_pkcs11_token_get_mechanism.3
-APIMANS += gnutls_pkcs11_type_get_name.3
-APIMANS += gnutls_pkcs11_privkey_init.3
-APIMANS += gnutls_pkcs11_privkey_deinit.3
-APIMANS += gnutls_pkcs11_privkey_get_pk_algorithm.3
-APIMANS += gnutls_pkcs11_privkey_get_info.3
-APIMANS += gnutls_pkcs11_privkey_import_url.3
-APIMANS += gnutls_pkcs11_privkey_export_url.3
-APIMANS += gnutls_pkcs11_privkey_generate.3
-APIMANS += gnutls_pkcs11_copy_secret_key.3
-APIMANS += gnutls_pkcs11_copy_x509_crt.3
-APIMANS += gnutls_pkcs11_copy_x509_privkey.3
-APIMANS += gnutls_pkcs11_delete_url.3
-APIMANS += gnutls_pkcs11_token_init.3
-APIMANS += gnutls_pkcs11_token_set_pin.3
-APIMANS += gnutls_rnd.3
-APIMANS += gnutls_transport_set_errno.3
-APIMANS += gnutls_transport_set_pull_function.3
-APIMANS += gnutls_transport_set_pull_timeout_function.3
-APIMANS += gnutls_transport_set_push_function.3
-APIMANS += gnutls_transport_set_vec_push_function.3
-APIMANS += gnutls_transport_set_errno_function.3
-APIMANS += gnutls_pem_base64_encode.3
-APIMANS += gnutls_pem_base64_encode_alloc.3
-APIMANS += gnutls_pem_base64_decode.3
-APIMANS += gnutls_pem_base64_decode_alloc.3
-APIMANS += gnutls_register_md5_handler.3
-APIMANS += gnutls_global_init_extra.3
-APIMANS += gnutls_extra_check_version.3
-APIMANS += gnutls_x509_dn_oid_known.3
-APIMANS += gnutls_x509_crl_init.3
-APIMANS += gnutls_x509_crl_deinit.3
-APIMANS += gnutls_x509_crl_import.3
-APIMANS += gnutls_x509_crl_get_issuer_dn.3
-APIMANS += gnutls_x509_crl_get_issuer_dn_by_oid.3
-APIMANS += gnutls_x509_crl_get_dn_oid.3
-APIMANS += gnutls_x509_crl_get_signature_algorithm.3
-APIMANS += gnutls_x509_crl_get_signature.3
-APIMANS += gnutls_x509_crl_get_version.3
-APIMANS += gnutls_x509_crl_get_this_update.3
-APIMANS += gnutls_x509_crl_get_next_update.3
-APIMANS += gnutls_x509_crl_get_crt_count.3
-APIMANS += gnutls_x509_crl_get_crt_serial.3
-APIMANS += gnutls_x509_crl_get_raw_issuer_dn.3
-APIMANS += gnutls_x509_crl_export.3
-APIMANS += gnutls_x509_crl_get_authority_key_id.3
-APIMANS += gnutls_x509_crl_get_number.3
-APIMANS += gnutls_x509_crl_get_extension_oid.3
-APIMANS += gnutls_x509_crl_get_extension_info.3
-APIMANS += gnutls_x509_crl_get_extension_data.3
-APIMANS += gnutls_x509_crl_list_import2.3
-APIMANS += gnutls_x509_crl_list_import.3
-APIMANS += gnutls_x509_crl_set_version.3
-APIMANS += gnutls_x509_crl_sign2.3
-APIMANS += gnutls_x509_crl_sign.3
-APIMANS += gnutls_x509_crl_set_this_update.3
-APIMANS += gnutls_x509_crl_set_next_update.3
-APIMANS += gnutls_x509_crl_set_crt_serial.3
-APIMANS += gnutls_x509_crl_set_crt.3
-APIMANS += gnutls_x509_crl_set_authority_key_id.3
-APIMANS += gnutls_x509_crl_set_number.3
-APIMANS += gnutls_x509_crl_privkey_sign.3
-APIMANS += gnutls_x509_crq_init.3
-APIMANS += gnutls_x509_crq_deinit.3
-APIMANS += gnutls_x509_crq_import.3
-APIMANS += gnutls_x509_crq_get_dn.3
-APIMANS += gnutls_x509_crq_get_dn_by_oid.3
-APIMANS += gnutls_x509_crq_get_dn_oid.3
-APIMANS += gnutls_x509_crq_get_challenge_password.3
-APIMANS += gnutls_x509_crq_set_attribute_by_oid.3
-APIMANS += gnutls_x509_crq_get_attribute_by_oid.3
-APIMANS += gnutls_x509_crq_set_dn_by_oid.3
-APIMANS += gnutls_x509_crq_set_version.3
-APIMANS += gnutls_x509_crq_get_version.3
-APIMANS += gnutls_x509_crq_set_key.3
-APIMANS += gnutls_x509_crq_get_key_rsa_raw.3
-APIMANS += gnutls_x509_crq_set_key_rsa_raw.3
-APIMANS += gnutls_x509_crq_set_challenge_password.3
-APIMANS += gnutls_x509_crq_sign2.3
-APIMANS += gnutls_x509_crq_sign.3
-APIMANS += gnutls_x509_crq_export.3
-APIMANS += gnutls_x509_crq_get_pk_algorithm.3
-APIMANS += gnutls_x509_crq_get_attribute_info.3
-APIMANS += gnutls_x509_crq_get_attribute_data.3
-APIMANS += gnutls_x509_crq_get_extension_info.3
-APIMANS += gnutls_x509_crq_get_extension_data.3
-APIMANS += gnutls_x509_crq_get_key_usage.3
-APIMANS += gnutls_x509_crq_get_basic_constraints.3
-APIMANS += gnutls_x509_crq_get_subject_alt_name.3
-APIMANS += gnutls_x509_crq_get_subject_alt_othername_oid.3
-APIMANS += gnutls_x509_crq_get_extension_by_oid.3
-APIMANS += gnutls_x509_crq_set_subject_alt_name.3
-APIMANS += gnutls_x509_crq_set_basic_constraints.3
-APIMANS += gnutls_x509_crq_set_key_usage.3
-APIMANS += gnutls_x509_crq_get_key_purpose_oid.3
-APIMANS += gnutls_x509_crq_set_key_purpose_oid.3
-APIMANS += gnutls_x509_crq_get_key_id.3
-APIMANS += gnutls_x509_crq_privkey_sign.3
-APIMANS += gnutls_x509_crq_verify.3
-APIMANS += gnutls_x509_dn_init.3
-APIMANS += gnutls_x509_dn_import.3
-APIMANS += gnutls_x509_dn_deinit.3
-APIMANS += gnutls_x509_rdn_get.3
-APIMANS += gnutls_x509_rdn_get_by_oid.3
-APIMANS += gnutls_x509_rdn_get_oid.3
-APIMANS += gnutls_x509_dn_export.3
-APIMANS += gnutls_ocsp_req_init.3
-APIMANS += gnutls_ocsp_req_deinit.3
-APIMANS += gnutls_ocsp_resp_init.3
-APIMANS += gnutls_ocsp_resp_deinit.3
-APIMANS += gnutls_ocsp_req_import.3
-APIMANS += gnutls_ocsp_resp_import.3
-APIMANS += gnutls_ocsp_req_export.3
-APIMANS += gnutls_ocsp_resp_export.3
-APIMANS += gnutls_ocsp_req_get_version.3
-APIMANS += gnutls_ocsp_req_get_certid.3
-APIMANS += gnutls_ocsp_req_add_certid.3
-APIMANS += gnutls_ocsp_req_add_cert.3
-APIMANS += gnutls_ocsp_req_get_nonce.3
-APIMANS += gnutls_ocsp_req_get_extension.3
-APIMANS += gnutls_ocsp_req_set_extension.3
-APIMANS += gnutls_ocsp_req_set_nonce.3
-APIMANS += gnutls_ocsp_resp_get_status.3
-APIMANS += gnutls_ocsp_resp_get_response.3
-APIMANS += gnutls_ocsp_resp_get_version.3
-APIMANS += gnutls_ocsp_resp_get_responderid_dn.3
-APIMANS += gnutls_ocsp_resp_get_produceat.3
-APIMANS += gnutls_ocsp_resp_get_singleresponse.3
-APIMANS += gnutls_ocsp_resp_get_extension.3
-APIMANS += gnutls_ocsp_resp_get_nonce.3
-APIMANS += gnutls_ocsp_resp_get_signature_algorithm.3
-APIMANS += gnutls_ocsp_resp_get_signature.3
-APIMANS += gnutls_ocsp_resp_get_certs.3
-APIMANS += gnutls_ocsp_resp_verify.3
-APIMANS += gnutls_ocsp_req_print.3
-APIMANS += gnutls_ocsp_resp_print.3
-APIMANS += gnutls_x509_crt_print.3
-APIMANS += gnutls_x509_crl_print.3
-APIMANS += gnutls_x509_crq_print.3
-APIMANS += gnutls_pkcs12_init.3
-APIMANS += gnutls_pkcs12_deinit.3
-APIMANS += gnutls_pkcs12_import.3
-APIMANS += gnutls_pkcs12_export.3
-APIMANS += gnutls_pkcs12_get_bag.3
-APIMANS += gnutls_pkcs12_set_bag.3
-APIMANS += gnutls_pkcs12_generate_mac.3
-APIMANS += gnutls_pkcs12_verify_mac.3
-APIMANS += gnutls_pkcs12_bag_init.3
-APIMANS += gnutls_pkcs12_bag_deinit.3
-APIMANS += gnutls_pkcs12_bag_get_type.3
-APIMANS += gnutls_pkcs12_bag_get_count.3
-APIMANS += gnutls_pkcs12_bag_get_data.3
-APIMANS += gnutls_pkcs12_bag_set_data.3
-APIMANS += gnutls_pkcs12_bag_set_crt.3
-APIMANS += gnutls_pkcs12_bag_set_crl.3
-APIMANS += gnutls_pkcs12_bag_set_key_id.3
-APIMANS += gnutls_pkcs12_bag_get_key_id.3
-APIMANS += gnutls_pkcs12_bag_get_friendly_name.3
-APIMANS += gnutls_pkcs12_bag_set_friendly_name.3
-APIMANS += gnutls_pkcs12_bag_decrypt.3
-APIMANS += gnutls_pkcs12_bag_encrypt.3
-APIMANS += gnutls_pkcs7_init.3
-APIMANS += gnutls_pkcs7_deinit.3
-APIMANS += gnutls_pkcs7_import.3
-APIMANS += gnutls_pkcs7_get_crt_raw.3
-APIMANS += gnutls_pkcs7_get_crt_count.3
-APIMANS += gnutls_pkcs7_export.3
-APIMANS += gnutls_pkcs7_set_crt_raw.3
-APIMANS += gnutls_pkcs7_set_crt.3
-APIMANS += gnutls_pkcs7_delete_crt.3
-APIMANS += gnutls_pkcs7_get_crl_raw.3
-APIMANS += gnutls_pkcs7_get_crl_count.3
-APIMANS += gnutls_pkcs7_set_crl_raw.3
-APIMANS += gnutls_pkcs7_set_crl.3
-APIMANS += gnutls_pkcs7_delete_crl.3
-APIMANS += gnutls_x509_privkey_init.3
-APIMANS += gnutls_x509_privkey_deinit.3
-APIMANS += gnutls_x509_privkey_cpy.3
-APIMANS += gnutls_x509_privkey_import.3
-APIMANS += gnutls_x509_privkey_import_rsa_raw.3
-APIMANS += gnutls_x509_privkey_import_rsa_raw2.3
-APIMANS += gnutls_x509_privkey_import_dsa_raw.3
-APIMANS += gnutls_x509_privkey_import_ecc_raw.3
-APIMANS += gnutls_x509_privkey_get_pk_algorithm.3
-APIMANS += gnutls_x509_privkey_export.3
-APIMANS += gnutls_x509_privkey_sec_param.3
-APIMANS += gnutls_x509_privkey_export_ecc_raw.3
-APIMANS += gnutls_x509_privkey_export_rsa_raw.3
-APIMANS += gnutls_x509_privkey_export_rsa_raw2.3
-APIMANS += gnutls_x509_privkey_export_dsa_raw.3
-APIMANS += gnutls_x509_privkey_generate.3
-APIMANS += gnutls_x509_privkey_get_key_id.3
-APIMANS += gnutls_x509_privkey_sign_hash.3
-APIMANS += gnutls_x509_privkey_sign_data.3
-APIMANS += gnutls_x509_privkey_fix.3
-APIMANS += gnutls_x509_privkey_export_pkcs8.3
-APIMANS += gnutls_x509_privkey_import_pkcs8.3
-APIMANS += gnutls_x509_crt_check_hostname.3
-APIMANS += gnutls_x509_trust_list_init.3
-APIMANS += gnutls_x509_trust_list_deinit.3
-APIMANS += gnutls_x509_trust_list_add_cas.3
-APIMANS += gnutls_x509_trust_list_add_named_crt.3
-APIMANS += gnutls_x509_trust_list_add_crls.3
-APIMANS += gnutls_x509_trust_list_get_issuer.3
-APIMANS += gnutls_x509_trust_list_verify_crt.3
-APIMANS += gnutls_x509_trust_list_verify_named_crt.3
-APIMANS += gnutls_x509_crt_check_issuer.3
-APIMANS += gnutls_x509_crt_list_verify.3
-APIMANS += gnutls_x509_crt_verify.3
-APIMANS += gnutls_x509_crl_check_issuer.3
-APIMANS += gnutls_x509_crl_verify.3
-APIMANS += gnutls_x509_crt_init.3
-APIMANS += gnutls_x509_crt_deinit.3
-APIMANS += gnutls_x509_crt_import.3
-APIMANS += gnutls_x509_crt_get_issuer_dn.3
-APIMANS += gnutls_x509_crt_get_issuer_dn_by_oid.3
-APIMANS += gnutls_x509_crt_get_issuer_dn_oid.3
-APIMANS += gnutls_x509_crt_get_dn.3
-APIMANS += gnutls_x509_crt_get_dn_by_oid.3
-APIMANS += gnutls_x509_crt_get_dn_oid.3
-APIMANS += gnutls_x509_crt_get_signature_algorithm.3
-APIMANS += gnutls_x509_crt_get_signature.3
-APIMANS += gnutls_x509_crt_get_version.3
-APIMANS += gnutls_x509_crt_get_activation_time.3
-APIMANS += gnutls_x509_crt_get_expiration_time.3
-APIMANS += gnutls_x509_crt_get_serial.3
-APIMANS += gnutls_x509_crt_get_subject_key_id.3
-APIMANS += gnutls_x509_crt_get_authority_key_id.3
-APIMANS += gnutls_x509_crt_get_pk_algorithm.3
-APIMANS += gnutls_x509_crt_get_subject_alt_name.3
-APIMANS += gnutls_x509_crt_get_issuer_alt_name.3
-APIMANS += gnutls_x509_crt_get_subject_alt_name2.3
-APIMANS += gnutls_x509_crt_get_issuer_alt_name2.3
-APIMANS += gnutls_x509_crt_get_subject_alt_othername_oid.3
-APIMANS += gnutls_x509_crt_get_issuer_alt_othername_oid.3
-APIMANS += gnutls_x509_crt_get_basic_constraints.3
-APIMANS += gnutls_x509_crt_get_ca_status.3
-APIMANS += gnutls_x509_crt_get_key_usage.3
-APIMANS += gnutls_x509_crt_get_proxy.3
-APIMANS += gnutls_x509_crt_get_extension_by_oid.3
-APIMANS += gnutls_x509_crt_get_extension_oid.3
-APIMANS += gnutls_x509_crt_get_extension_info.3
-APIMANS += gnutls_x509_crt_get_extension_data.3
-APIMANS += gnutls_x509_crt_get_raw_issuer_dn.3
-APIMANS += gnutls_x509_crt_get_raw_dn.3
-APIMANS += gnutls_x509_crt_get_subject.3
-APIMANS += gnutls_x509_crt_get_issuer.3
-APIMANS += gnutls_x509_dn_get_rdn_ava.3
-APIMANS += gnutls_x509_crt_get_fingerprint.3
-APIMANS += gnutls_x509_crt_export.3
-APIMANS += gnutls_x509_crt_get_key_id.3
-APIMANS += gnutls_x509_crt_check_revocation.3
-APIMANS += gnutls_x509_crt_get_verify_algorithm.3
-APIMANS += gnutls_x509_crt_get_preferred_hash_algorithm.3
-APIMANS += gnutls_x509_crt_verify_data.3
-APIMANS += gnutls_x509_crt_verify_hash.3
-APIMANS += gnutls_x509_crt_get_crl_dist_points.3
-APIMANS += gnutls_x509_crt_get_key_purpose_oid.3
-APIMANS += gnutls_x509_crt_get_pk_rsa_raw.3
-APIMANS += gnutls_x509_crt_get_pk_dsa_raw.3
-APIMANS += gnutls_x509_crt_list_import2.3
-APIMANS += gnutls_x509_crt_list_import.3
-APIMANS += gnutls_x509_crt_get_subject_unique_id.3
-APIMANS += gnutls_x509_crt_get_issuer_unique_id.3
-APIMANS += gnutls_x509_crt_get_authority_info_access.3
-APIMANS += gnutls_x509_crt_set_dn_by_oid.3
-APIMANS += gnutls_x509_crt_set_issuer_dn_by_oid.3
-APIMANS += gnutls_x509_crt_set_proxy_dn.3
-APIMANS += gnutls_x509_crt_set_version.3
-APIMANS += gnutls_x509_crt_set_key.3
-APIMANS += gnutls_x509_crt_set_crq.3
-APIMANS += gnutls_x509_crt_set_crq_extensions.3
-APIMANS += gnutls_x509_crt_set_extension_by_oid.3
-APIMANS += gnutls_x509_crt_set_basic_constraints.3
-APIMANS += gnutls_x509_crt_set_ca_status.3
-APIMANS += gnutls_x509_crt_set_key_usage.3
-APIMANS += gnutls_x509_crt_set_subject_alternative_name.3
-APIMANS += gnutls_x509_crt_set_subject_alt_name.3
-APIMANS += gnutls_x509_crt_set_proxy.3
-APIMANS += gnutls_x509_crt_sign2.3
-APIMANS += gnutls_x509_crt_sign.3
-APIMANS += gnutls_x509_crt_set_activation_time.3
-APIMANS += gnutls_x509_crt_set_expiration_time.3
-APIMANS += gnutls_x509_crt_set_serial.3
-APIMANS += gnutls_x509_crt_set_crl_dist_points.3
-APIMANS += gnutls_x509_crt_set_crl_dist_points2.3
-APIMANS += gnutls_x509_crt_cpy_crl_dist_points.3
-APIMANS += gnutls_x509_crt_set_subject_key_id.3
-APIMANS += gnutls_x509_crt_set_authority_key_id.3
-APIMANS += gnutls_x509_crt_set_key_purpose_oid.3
-APIMANS += gnutls_x509_crt_privkey_sign.3
-APIMANS += gnutls_openpgp_keyring_init.3
-APIMANS += gnutls_openpgp_keyring_deinit.3
-APIMANS += gnutls_openpgp_keyring_check_id.3
-APIMANS += gnutls_openpgp_keyring_import.3
-APIMANS += gnutls_openpgp_keyring_get_crt_count.3
-APIMANS += gnutls_openpgp_keyring_get_crt.3
-APIMANS += gnutls_certificate_set_openpgp_key.3
-APIMANS += gnutls_certificate_set_openpgp_key_mem.3
-APIMANS += gnutls_certificate_set_openpgp_key_file.3
-APIMANS += gnutls_certificate_set_openpgp_key_mem2.3
-APIMANS += gnutls_certificate_set_openpgp_key_file2.3
-APIMANS += gnutls_certificate_set_openpgp_keyring_file.3
-APIMANS += gnutls_certificate_set_openpgp_keyring_mem.3
-APIMANS += gnutls_openpgp_set_recv_key_function.3
-APIMANS += gnutls_openpgp_crt_print.3
-APIMANS += gnutls_openpgp_crt_init.3
-APIMANS += gnutls_openpgp_crt_deinit.3
-APIMANS += gnutls_openpgp_crt_import.3
-APIMANS += gnutls_openpgp_crt_export.3
-APIMANS += gnutls_openpgp_crt_get_fingerprint.3
-APIMANS += gnutls_openpgp_crt_get_name.3
-APIMANS += gnutls_openpgp_crt_get_pk_algorithm.3
-APIMANS += gnutls_openpgp_crt_get_version.3
-APIMANS += gnutls_openpgp_crt_get_creation_time.3
-APIMANS += gnutls_openpgp_crt_get_expiration_time.3
-APIMANS += gnutls_openpgp_crt_get_key_id.3
-APIMANS += gnutls_openpgp_crt_get_revoked_status.3
-APIMANS += gnutls_openpgp_crt_check_hostname.3
-APIMANS += gnutls_openpgp_crt_get_key_usage.3
-APIMANS += gnutls_openpgp_crt_get_subkey_count.3
-APIMANS += gnutls_openpgp_crt_get_subkey_revoked_status.3
-APIMANS += gnutls_openpgp_crt_get_subkey_pk_algorithm.3
-APIMANS += gnutls_openpgp_crt_get_subkey_creation_time.3
-APIMANS += gnutls_openpgp_crt_get_subkey_expiration_time.3
-APIMANS += gnutls_openpgp_crt_get_subkey_id.3
-APIMANS += gnutls_openpgp_crt_get_subkey_fingerprint.3
-APIMANS += gnutls_openpgp_crt_get_subkey_idx.3
-APIMANS += gnutls_openpgp_crt_get_subkey_usage.3
-APIMANS += gnutls_openpgp_crt_get_pk_rsa_raw.3
-APIMANS += gnutls_openpgp_crt_get_pk_dsa_raw.3
-APIMANS += gnutls_openpgp_crt_get_subkey_pk_rsa_raw.3
-APIMANS += gnutls_openpgp_crt_get_subkey_pk_dsa_raw.3
-APIMANS += gnutls_openpgp_crt_get_preferred_key_id.3
-APIMANS += gnutls_openpgp_crt_set_preferred_key_id.3
-APIMANS += gnutls_openpgp_crt_get_auth_subkey.3
-APIMANS += gnutls_openpgp_crt_verify_ring.3
-APIMANS += gnutls_openpgp_crt_verify_self.3
-APIMANS += gnutls_openpgp_privkey_init.3
-APIMANS += gnutls_openpgp_privkey_deinit.3
-APIMANS += gnutls_openpgp_privkey_sec_param.3
-APIMANS += gnutls_openpgp_privkey_import.3
-APIMANS += gnutls_openpgp_privkey_export.3
-APIMANS += gnutls_openpgp_privkey_get_pk_algorithm.3
-APIMANS += gnutls_openpgp_privkey_get_revoked_status.3
-APIMANS += gnutls_openpgp_privkey_get_fingerprint.3
-APIMANS += gnutls_openpgp_privkey_get_key_id.3
-APIMANS += gnutls_openpgp_privkey_get_subkey_count.3
-APIMANS += gnutls_openpgp_privkey_get_subkey_revoked_status.3
-APIMANS += gnutls_openpgp_privkey_get_subkey_pk_algorithm.3
-APIMANS += gnutls_openpgp_privkey_get_subkey_idx.3
-APIMANS += gnutls_openpgp_privkey_get_subkey_creation_time.3
-APIMANS += gnutls_openpgp_privkey_get_subkey_expiration_time.3
-APIMANS += gnutls_openpgp_privkey_get_subkey_id.3
-APIMANS += gnutls_openpgp_privkey_get_subkey_fingerprint.3
-APIMANS += gnutls_openpgp_privkey_export_rsa_raw.3
-APIMANS += gnutls_openpgp_privkey_export_dsa_raw.3
-APIMANS += gnutls_openpgp_privkey_export_subkey_rsa_raw.3
-APIMANS += gnutls_openpgp_privkey_export_subkey_dsa_raw.3
-APIMANS += gnutls_openpgp_privkey_get_preferred_key_id.3
-APIMANS += gnutls_openpgp_privkey_set_preferred_key_id.3
-APIMANS += gnutls_openpgp_privkey_sign_hash.3
-
-SRPMANS =
-SRPMANS += gnutls_srp_free_client_credentials.3
-SRPMANS += gnutls_srp_allocate_client_credentials.3
-SRPMANS += gnutls_srp_set_client_credentials.3
-SRPMANS += gnutls_srp_free_server_credentials.3
-SRPMANS += gnutls_srp_allocate_server_credentials.3
-SRPMANS += gnutls_srp_set_server_credentials_file.3
-SRPMANS += gnutls_srp_set_server_credentials_function.3
-SRPMANS += gnutls_srp_set_client_credentials_function.3
-SRPMANS += gnutls_srp_server_get_username.3
-SRPMANS += gnutls_srp_verifier.3
-SRPMANS += gnutls_srp_set_prime_bits.3
-
-dist_man_MANS += $(APIMANS)
-if ENABLE_SRP
-dist_man_MANS += $(SRPMANS)
-endif
-
-$(APIMANS) $(SRPMANS):
-       make update-makefile
-       make Makefile
-       make doit
-
-update-makefile:
-       FUNCS=`$(top_srcdir)/doc/scripts/gdoc -listfunc \
-               $(top_srcdir)/{lib,libextra,lib/x509,lib/openpgp}/*.c`; \
-       MANS=""; \
-       SRPMANS=""; \
-       for i in $$FUNCS; do \
-               if echo $$i | grep gnutls_srp_ > /dev/null; then \
-                       SRPMANS="$$SRPMANS\nSRPMANS += $$i.3"; \
-               else \
-                       MANS="$$MANS\nAPIMANS += $$i.3"; \
-               fi \
-       done; \
-       grep -v -e '^APIMANS += ' -e '^SRPMANS += ' Makefile.am | \
-               perl -p -e "s/^APIMANS =/APIMANS =$$MANS/" | \
-               perl -p -e "s/^SRPMANS =/SRPMANS =$$SRPMANS/" > foo; \
-       mv foo Makefile.am
-
-doit:
-       @echo -n "Creating man pages for lib/" && \
-       for i in `$(top_srcdir)/doc/scripts/gdoc -listfunc 
$(top_srcdir)/lib/*.c`; do \
-               $(top_srcdir)/doc/scripts/gdoc -man \
-                       -module $(PACKAGE) -sourceversion $(VERSION) \
-                       -bugsto $(PACKAGE_BUGREPORT) \
-                       -pkg-name "$(PACKAGE_NAME)" \
-                       -include "gnutls/gnutls.h" \
-                       -seeinfo $(PACKAGE) -verbatimcopying \
-                       -copyright "2008 Free Software Foundation" \
-                       -function $$i \
-                       $(top_srcdir)/lib/*.c > $$i.3 && \
-               echo -n "."; \
-       done; \
-       echo ""; \
-       echo -n "Creating man pages for libextra/" && \
-       for i in `$(top_srcdir)/doc/scripts/gdoc -listfunc 
$(top_srcdir)/libextra/*.c`; do \
-               $(top_srcdir)/doc/scripts/gdoc -man \
-                       -module $(PACKAGE) -sourceversion $(VERSION) \
-                       -bugsto $(PACKAGE_BUGREPORT) \
-                       -pkg-name "$(PACKAGE_NAME)" \
-                       -include "gnutls/extra.h" \
-                       -seeinfo $(PACKAGE) -verbatimcopying \
-                       -copyright "2008 Free Software Foundation" \
-                       -function $$i \
-                       $(top_srcdir)/libextra/*.c > $$i.3 && \
-               echo -n "."; \
-       done; \
-       echo ""; \
-       echo -n "Creating man pages for lib/x509/" && \
-       for i in `$(top_srcdir)/doc/scripts/gdoc -listfunc 
$(top_srcdir)/lib/x509/*.c | grep -v gnutls_pkcs12`; do \
-               $(top_srcdir)/doc/scripts/gdoc -man \
-                       -module $(PACKAGE) -sourceversion $(VERSION) \
-                       -bugsto $(PACKAGE_BUGREPORT) \
-                       -pkg-name "$(PACKAGE_NAME)" \
-                       -include "gnutls/x509.h" \
-                       -seeinfo $(PACKAGE) -verbatimcopying \
-                       -copyright "2008 Free Software Foundation" \
-                       -function $$i \
-                       $(top_srcdir)/lib/x509/*.c > $$i.3 && \
-               echo -n "."; \
-       done; \
-       echo ""; \
-       echo -n "Creating man pages for lib/x509/ (pkcs12)" && \
-       for i in `$(top_srcdir)/doc/scripts/gdoc -listfunc 
$(top_srcdir)/lib/x509/*.c | grep gnutls_pkcs12`; do \
-               $(top_srcdir)/doc/scripts/gdoc -man \
-                       -module $(PACKAGE) -sourceversion $(VERSION) \
-                       -bugsto $(PACKAGE_BUGREPORT) \
-                       -pkg-name "$(PACKAGE_NAME)" \
-                       -include "gnutls/pkcs12.h" \
-                       -seeinfo $(PACKAGE) -verbatimcopying \
-                       -copyright "2008 Free Software Foundation" \
-                       -function $$i \
-                       $(top_srcdir)/lib/x509/*.c > $$i.3 && \
-               echo -n "."; \
-       done; \
-       echo ""; \
-       echo -n "Creating man pages for lib/openpgp/" && \
-       for i in `$(top_srcdir)/doc/scripts/gdoc -listfunc 
$(top_srcdir)/lib/openpgp/*.c`; do \
-               $(top_srcdir)/doc/scripts/gdoc -man \
-                       -module $(PACKAGE) -sourceversion $(VERSION) \
-                       -bugsto $(PACKAGE_BUGREPORT) \
-                       -pkg-name "$(PACKAGE_NAME)" \
-                       -include "gnutls/openpgp.h" \
-                       -seeinfo $(PACKAGE) -verbatimcopying \
-                       -copyright "2008 Free Software Foundation" \
-                       -function $$i \
-                       $(top_srcdir)/lib/openpgp/*.c > $$i.3 && \
-               echo -n "."; \
-       done; \
-       echo ""
-
-.PHONY: update-makefile doit
diff --git a/doc/reference/Makefile.am b/doc/reference/Makefile.am
index 5fdb00f..5825d07 100644
--- a/doc/reference/Makefile.am
+++ b/doc/reference/Makefile.am
@@ -18,11 +18,11 @@ DOC_MODULE=$(PACKAGE)
 # The top-level SGML file. You can change this if you want to.
 DOC_MAIN_SGML_FILE=$(DOC_MODULE)-docs.sgml
 
-# Directories containing the source code, relative to $(srcdir).
+# Directories containing the source code.
 # gtk-doc will search all .c and .h files beneath these paths
 # for inline comments documenting functions and macros.
-# e.g. DOC_SOURCE_DIR=../../../gtk ../../../gdk
-DOC_SOURCE_DIR=../../lib ../../libextra
+# e.g. DOC_SOURCE_DIR=$(top_srcdir)/gtk $(top_srcdir)/gdk
+DOC_SOURCE_DIR=../../lib
 
 # Extra options to pass to gtkdoc-scangobj. Not normally needed.
 SCANGOBJ_OPTIONS=
@@ -33,8 +33,8 @@ SCAN_OPTIONS=--ignore-decorators=ASN1_API \
        --deprecated-guards=ASN1_DISABLE_DEPRECATED
 
 # Extra options to supply to gtkdoc-mkdb.
-# e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml
-MKDB_OPTIONS=--sgml-mode --output-format=xml
+# e.g. MKDB_OPTIONS=--xml-mode --output-format=xml
+MKDB_OPTIONS=--xml-mode --output-format=xml
 
 # Extra options to supply to gtkdoc-mktmpl
 # e.g. MKTMPL_OPTIONS=--only-section-tmpl
@@ -51,32 +51,28 @@ FIXXREF_OPTIONS=
 # e.g. HFILE_GLOB=$(top_srcdir)/gtk/*.h
 # e.g. CFILE_GLOB=$(top_srcdir)/gtk/*.c
 HFILE_GLOB=$(top_srcdir)/lib/includes/gnutls/*.h \
-       $(top_builddir)/lib/includes/gnutls/*.h \
-       $(top_srcdir)/libextra/includes/gnutls/*.h
+       $(top_builddir)/lib/includes/gnutls/*.h
 CFILE_GLOB=$(top_srcdir)/lib/*.c \
        $(top_srcdir)/lib/x509/*.c \
        $(top_srcdir)/lib/openpgp/*.c \
-       $(top_srcdir)/libextra/*.c \
-       $(top_srcdir)/lib/minitasn1/*.c \
-       $(top_srcdir)/libextra/*.c
+       $(top_srcdir)/lib/minitasn1/*.c
 
 # Extra header to include when scanning, which are not under DOC_SOURCE_DIR
 # e.g. EXTRA_HFILES=$(top_srcdir}/contrib/extra.h
 EXTRA_HFILES=
 
-# Header files to ignore when scanning. Use base file name, no paths
-# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h
+# Header files or dirs to ignore when scanning. Use base file/dir names
+# e.g. IGNORE_HFILES=gtkdebug.h gtkintl.h private_code
 IGNORE_HFILES=
 
 # find lib -name \*.h -exec basename {} \; | grep -v -e ^abstract.h$ -e 
^crypto.h$ -e ^dtls.h$ -e ^gnutls.h$ -e ^openpgp.h$ -e ^pkcs11.h$ -e ^pkcs12.h$ 
-e ^x509.h$ | sort | uniq | sed -e 's/^/\t/' -e 's/$/ \\/'
 IGNORE_HFILES += \
        abstract_int.h \
        accelerated.h \
+       aes-padlock.h \
        aes-x86.h \
        algorithms.h \
        anon.h \
-       arg-nonnull.h \
-       c++defs.h \
        cert.h \
        cert_type.h \
        common.h \
@@ -123,6 +119,7 @@ IGNORE_HFILES += \
        gnutls_sig.h \
        gnutls_srp.h \
        gnutls_state.h \
+       gnutls_str_array.h \
        gnutls_str.h \
        gnutls_supplemental.h \
        gnutls_v2_compat.h \
@@ -148,6 +145,7 @@ IGNORE_HFILES += \
        safe_renegotiation.h \
        server_name.h \
        session_ticket.h \
+       sha-padlock.h \
        signature.h \
        srp.h \
        srp_passwd.h \
@@ -155,15 +153,10 @@ IGNORE_HFILES += \
        structure.h \
        system.h \
        types.h \
-       warn-on-use.h \
        x509_b64.h \
        x509_int.h \
        x86.h
 
-# find libextra -name \*.h -exec basename {} \; | grep -v -e extra.h -e 
openssl.h | sort | uniq | sed -e 's/^/\t/' -e 's/$/ \\/'
-IGNORE_HFILES += \
-       openssl_compat.h
-
 # Images to copy into HTML directory.
 # e.g. HTML_IMAGES=$(top_srcdir)/gtk/stock-icons/stock_about_24.png
 HTML_IMAGES=
@@ -197,8 +190,13 @@ EXTRA_DIST +=
 # for --rebuild-sections in $(SCAN_OPTIONS) e.g. $(DOC_MODULE)-sections.txt
 #DISTCLEANFILES +=
 
-# Comment this out if you want your docs-status tested during 'make check'
+# Comment this out if you want 'make check' to test you doc status
+# and run some sanity checks
 if ENABLE_GTK_DOC
-#TESTS_ENVIRONMENT = cd $(srcsrc) &&
+TESTS_ENVIRONMENT = cd $(srcdir) && \
+  DOC_MODULE=$(DOC_MODULE) DOC_MAIN_SGML_FILE=$(DOC_MAIN_SGML_FILE) \
+  SRCDIR=$(abs_srcdir) BUILDDIR=$(abs_builddir)
 #TESTS = $(GTKDOC_CHECK)
 endif
+
+-include $(top_srcdir)/git.mk
diff --git a/doc/reference/gnutls-docs.sgml b/doc/reference/gnutls-docs.sgml
index b6283a4..88f7fbc 100644
--- a/doc/reference/gnutls-docs.sgml
+++ b/doc/reference/gnutls-docs.sgml
@@ -1,9 +1,18 @@
 <?xml version="1.0"?>
-<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 
-               "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd";>
-<book id="index" xmlns:xi="http://www.w3.org/2003/XInclude";>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd";
+[
+  <!ENTITY % local.common.attrib "xmlns:xi  CDATA  #FIXED 
'http://www.w3.org/2003/XInclude'">
+  <!ENTITY version SYSTEM "version.xml">
+]>
+<book id="index">
   <bookinfo>
     <title>GnuTLS API Reference Manual</title>
+    <releaseinfo>
+      for GnuTLS &version;.
+      The latest version of this documentation can be found on-line at
+      <ulink role="online-location" 
url="https://www.gnu.org/software/gnutls/reference/";>https://www.gnu.org/software/gnutls/reference/</ulink>.
+    </releaseinfo>
   </bookinfo>
 
   <chapter id="intro">
@@ -22,19 +31,18 @@
 
     <xi:include href="xml/gnutls.xml"/>
     <xi:include href="xml/abstract.xml"/>
-    <xi:include href="xml/extra.xml"/>
     <xi:include href="xml/x509.xml"/>
-    <xi:include href="xml/pkcs11.xml"/>
-    <xi:include href="xml/pkcs12.xml"/>
     <xi:include href="xml/openpgp.xml"/>
-    <xi:include href="xml/crypto.xml"/>
     <xi:include href="xml/dtls.xml"/>
+    <xi:include href="xml/crypto.xml"/>
+    <xi:include href="xml/pkcs11.xml"/>
+    <xi:include href="xml/pkcs12.xml"/>
     <xi:include href="xml/ocsp.xml"/>
-    <xi:include href="xml/openssl.xml"/>
-  </chapter>
 
+  </chapter>
   <index id="api-index-full">
-    <title>Index of all symbols</title>
+    <title>API Index</title>
+    <xi:include href="xml/api-index-full.xml"><xi:fallback /></xi:include>
   </index>
   <index role="deprecated" id="api-index-deprecated">
     <title>Index of deprecated symbols</title>
diff --git a/doc/reference/version.xml.in b/doc/reference/version.xml.in
new file mode 100644
index 0000000..27323da
--- /dev/null
+++ b/doc/reference/version.xml.in
@@ -0,0 +1 @@
address@hidden@
\ No newline at end of file
diff --git a/doc/scripts/gdoc b/doc/scripts/gdoc
index 7485461..91d76c0 100755
--- a/doc/scripts/gdoc
+++ b/doc/scripts/gdoc
@@ -1,4 +1,6 @@
-#!/usr/bin/perl
+eval '(exit $?0)' && eval 'exec perl "$0" ${1+"$@"}'
+  & eval 'exec perl "$0" $argv:q'
+    if 0;
 
 ## Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Simon Josefsson
 ##                    added -texinfo, -listfunc, -pkg-name
@@ -314,7 +316,7 @@ sub repstr {
 
 #    print "pattern $pattern matched 1=$match1 2=$match2 3=$match3 4=$match4 
replace $repl yielded $output interpolated $return\n";
 
-    $return;
+    return;
 }
 
 sub just_highlight {
@@ -371,7 +373,7 @@ sub output_texinfo {
     }
     foreach $section (@{$args{'sectionlist'}}) {
        print "address@hidden:} " if $section ne $section_default;
-       $args{'sections'}{$section} =~ s:([{}]):address@hidden:gs;
+       $args{'sections'}{$section} =~ s:([{}]):address@hidden:gs;
        output_highlight($args{'sections'}{$section});
     }
     print "address@hidden deftypefun\n\n";
@@ -515,7 +517,7 @@ sub output_tex {
     foreach $section (@{$args{'sectionlist'}}) {
        $sec = $section;
        $sec =~ s/_/\\_/g;
-       $sec =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
+       $sec =~ s/#([a-zA-Z\_]+)/{\\it $1}/g;
 
        print "\n\\begin{function$sec}\n";
        $out = $args{'sections'}{$section};
@@ -528,7 +530,7 @@ sub output_tex {
        $out =~ s/\n\n/\n/g;
        $out =~ s/\\:/:/g;
        $out =~ s/\-\>/\$\\rightarrow\$/g;
-       $out =~ s/([0-9]+)\^([0-9]+)/\$\{\1\}\^\{\2\}\$/g;
+       $out =~ s/([0-9]+)\^([0-9]+)/\$\{$1\}\^\{$2\}\$/g;
 
        print $out;
        print "\\end{function$sec}\n";
@@ -547,8 +549,6 @@ sub output_enum_tex {
     my $check;
     my $type;
 
-    $func =~ s/_/\\_/g;
-
     print "\n\n\\begin{enum}\n";
     $name =~ s/_/\\_/g;
     print "\\enumTitle{". $name . "}\n";
diff --git a/doc/scripts/mytexi2latex b/doc/scripts/mytexi2latex
index 1ddce5d..4b9518e 100755
--- a/doc/scripts/mytexi2latex
+++ b/doc/scripts/mytexi2latex
@@ -1,4 +1,6 @@
-#!/usr/bin/perl
+eval '(exit $?0)' && eval 'exec perl -wST "$0" ${1+"$@"}'
+  & eval 'exec perl -wST "$0" $argv:q'
+    if 0;
 
 use constant NORMAL => 0;
 use constant SKIP => 1;
diff --git a/doc/scripts/sort1.pl b/doc/scripts/sort1.pl
index 504394d..0de8182 100755
--- a/doc/scripts/sort1.pl
+++ b/doc/scripts/sort1.pl
@@ -1,4 +1,6 @@
-#!/usr/bin/perl
+eval '(exit $?0)' && eval 'exec perl -wST "$0" ${1+"$@"}'
+  & eval 'exec perl -wST "$0" $argv:q'
+    if 0;
 
 sub key_of_record {
   local($record) = @_;
diff --git a/doc/scripts/split-texi.pl b/doc/scripts/split-texi.pl
index bd6e11e..a7ee518 100755
--- a/doc/scripts/split-texi.pl
+++ b/doc/scripts/split-texi.pl
@@ -1,4 +1,6 @@
-#!/usr/bin/perl
+eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}'
+  & eval 'exec perl -wS "$0" $argv:q'
+    if 0;
 
 $dir = shift;
 $param2 = shift;
@@ -19,9 +21,9 @@ sub key_of_record {
   my ($key) = $lines[$i]; 
 
   if ($enum == 1) {
-    while( !($key =~ m/address@hidden Table,(.*)$/) && ($i < 5)) { $i=$i+1; 
$key = $lines[$i]; }
+    while( !($key =~ m/address@hidden Table,(.*)$/) && ($i < 5)) { $i=$i+1; 
$key = $lines[$i]; }
   } else {
-    while( !($key =~ m/^$\\functionTitle\{(.*)\}/) && ($i < 5)) { $i=$i+1; 
$key = $lines[$i]; }
+    while( !($key =~ m/^\\functionTitle\{(.*)\}/) && ($i < 5)) { $i=$i+1; $key 
= $lines[$i]; }
   }
 
   return $key;
diff --git a/doc/scripts/split.pl b/doc/scripts/split.pl
index ed71634..f6e900c 100755
--- a/doc/scripts/split.pl
+++ b/doc/scripts/split.pl
@@ -1,4 +1,6 @@
-#!/usr/bin/perl
+eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}'
+  & eval 'exec perl -wS "$0" $argv:q'
+    if 0;
 
 $dir = shift;
 $param2 = shift;
@@ -19,9 +21,9 @@ sub key_of_record {
   my ($key) = $lines[$i]; 
 
   if ($enum == 1) {
-    while( !($key =~ m/^$\\enumTitle\{(.*)\}/) && ($i < 5)) { $i=$i+1; $key = 
$lines[$i]; }
+    while( !($key =~ m/^\\enumTitle\{(.*)\}/) && ($i < 5)) { $i=$i+1; $key = 
$lines[$i]; }
   } else {
-    while( !($key =~ m/^$\\functionTitle\{(.*)\}/) && ($i < 5)) { $i=$i+1; 
$key = $lines[$i]; }
+    while( !($key =~ m/^\\functionTitle\{(.*)\}/) && ($i < 5)) { $i=$i+1; $key 
= $lines[$i]; }
   }
 
   return $key;
diff --git a/doc/sec-tls-app.texi b/doc/sec-tls-app.texi
new file mode 100644
index 0000000..89a10e7
--- /dev/null
+++ b/doc/sec-tls-app.texi
@@ -0,0 +1,127 @@
address@hidden How to use TLS in application protocols
address@hidden How to use @acronym{TLS} in application protocols
+
+This chapter is intended to provide some hints on how to use the
address@hidden over simple custom made application protocols.  The
+discussion below mainly refers to the @acronym{TCP/IP} transport layer
+but may be extended to other ones too.
+
address@hidden
+* Separate ports::
+* Upward negotiation::
address@hidden menu
+
address@hidden Separate ports
address@hidden Separate ports
+
+Traditionally @acronym{SSL} was used in application protocols by
+assigning a new port number for the secure services. That way two
+separate ports were assigned, one for the non secure sessions, and one
+for the secured ones. This has the benefit that if a user requests a
+secure session then the client will try to connect to the secure port
+and fail otherwise. The only possible attack with this method is a
+denial of service one. The most famous example of this method is the
+famous ``HTTP over TLS'' or @acronym{HTTPS} protocol @xcite{RFC2818}.
+
+Despite its wide use, this method is not as good as it seems.  This
+approach starts the @acronym{TLS} Handshake procedure just after the
+client connects on the ---so called--- secure port.  That way the
address@hidden protocol does not know anything about the client, and
+popular methods like the host advertising in HTTP do not
address@hidden also the Server Name Indication extension on
address@hidden  There is no way for the client to say ``I
+connected to YYY server'' before the Handshake starts, so the server
+cannot possibly know which certificate to use.
+
+Other than that it requires two separate ports to run a single
+service, which is unnecessary complication. Due to the fact that there
+is a limitation on the available privileged ports, this approach was
+soon obsoleted.
+
address@hidden Upward negotiation
address@hidden Upward negotiation
+
+Other application address@hidden LDAP, IMAP etc.}  use a
+different approach to enable the secure layer.  They use something
+often called as the ``TLS upgrade'' method. This method is quite tricky but it
+is more flexible. The idea is to extend the application protocol to
+have a ``STARTTLS'' request, whose purpose it to start the TLS
+protocols just after the client requests it.  This approach
+does not require any extra port to be reserved.
+There is even an extension to HTTP protocol to support 
+that method @xcite{RFC2817}.
+
+The tricky part, in this method, is that the ``STARTTLS'' request is
+sent in the clear, thus is vulnerable to modifications.  A typical
+attack is to modify the messages in a way that the client is fooled
+and thinks that the server does not have the ``STARTTLS'' capability.
+See a typical conversation of a hypothetical protocol:
+
address@hidden
+(client connects to the server)
+
+CLIENT: HELLO I'M MR. XXX
+
+SERVER: NICE TO MEET YOU XXX
+
+CLIENT: PLEASE START TLS
+
+SERVER: OK
+
+*** TLS STARTS
+
+CLIENT: HERE ARE SOME CONFIDENTIAL DATA
address@hidden quotation
+
+And see an example of a conversation where someone is acting
+in between:
+
address@hidden
+(client connects to the server)
+
+CLIENT: HELLO I'M MR. XXX
+
+SERVER: NICE TO MEET YOU XXX
+
+CLIENT: PLEASE START TLS
+
+(here someone inserts this message)
+
+SERVER: SORRY I DON'T HAVE THIS CAPABILITY
+
+CLIENT: HERE ARE SOME CONFIDENTIAL DATA
address@hidden quotation
+
+As you can see above the client was fooled, and was dummy enough to
+send the confidential data in the clear.
+
+How to avoid the above attack? As you may have already noticed this
+one is easy to avoid. The client has to ask the user before it
+connects whether the user requests @acronym{TLS} or not. If the user
+answered that he certainly wants the secure layer the last
+conversation should be:
+
address@hidden
+(client connects to the server)
+
+CLIENT: HELLO I'M MR. XXX
+
+SERVER: NICE TO MEET YOU XXX
+
+CLIENT: PLEASE START TLS
+
+(here someone inserts this message)
+
+SERVER: SORRY I DON'T HAVE THIS CAPABILITY
+
+CLIENT: BYE
+
+(the client notifies the user that the secure connection was not possible)
address@hidden quotation
+
+This method, if implemented properly, is far better than the
+traditional method, and the security properties remain the same, since
+only denial of service is possible. The benefit is that the server may
+request additional data before the @acronym{TLS} Handshake protocol
+starts, in order to send the correct certificate, use the correct
+password file, or anything else!
diff --git a/extra/Makefile.am b/extra/Makefile.am
new file mode 100644
index 0000000..cfcdbd5
--- /dev/null
+++ b/extra/Makefile.am
@@ -0,0 +1,75 @@
+## Process this file with automake to produce Makefile.in
+# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+# Free Software Foundation, Inc.
+#
+# Author: Nikos Mavrogiannopoulos
+#
+# This file is part of GnuTLS-EXTRA.
+#
+# GnuTLS-extra is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3 of the
+# License, or (at your option) any later version.
+#
+# GnuTLS-extra is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GnuTLS-EXTRA; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+ACLOCAL_AMFLAGS = -I ../m4 -I ../gl/m4
+
+AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
+AM_CPPFLAGS = \
+       -I$(srcdir)/../gl                       \
+       -I$(builddir)/../gl                     \
+       -I$(builddir)/../lib/includes   \
+       -I$(srcdir)/../lib/includes     \
+       -I$(srcdir)/includes            \
+       -I$(builddir)/includes          \
+       -I$(srcdir)/../lib              \
+       -I$(builddir)/../lib
+
+if ENABLE_MINITASN1
+AM_CPPFLAGS += -I$(srcdir)/../lib/minitasn1
+endif
+
+SUBDIRS = includes
+
+defexecdir = $(bindir)
+defexec_DATA = 
+
+
+# OpenSSL
+
+libgnutls_openssl_la_LDFLAGS = -no-undefined
+
+if ENABLE_OPENSSL
+lib_LTLIBRARIES = libgnutls-openssl.la
+
+libgnutls_openssl_la_SOURCES = gnutls_openssl.c openssl_compat.h       \
+       openssl_compat.c
+
+libgnutls_openssl_la_LIBADD = ../gl/libgnu.la $(LIBSOCKET) \
+       ../lib/libgnutls.la
+
+libgnutls_openssl_la_LDFLAGS += -version-info 
$(LT_SSL_CURRENT):$(LT_SSL_REVISION):$(LT_SSL_AGE)
+
+if ENABLE_MINITASN1
+libgnutls_openssl_la_LIBADD += ../lib/minitasn1/libminitasn1.la
+else
+libgnutls_openssl_la_LDFLAGS += $(LTLIBTASN1)
+endif
+
+if HAVE_LD_OUTPUT_DEF
+libgnutls_openssl_la_LDFLAGS += \
+       -Wl,--output-def,libgnutls-openssl-$(DLL_VERSION).def
+defexec_DATA += libgnutls-openssl-$(DLL_VERSION).def
+endif
+endif
+
+DISTCLEANFILES = $(defexec_DATA)
diff --git a/libextra/gnutls_openssl.c b/extra/gnutls_openssl.c
similarity index 100%
rename from libextra/gnutls_openssl.c
rename to extra/gnutls_openssl.c
diff --git a/extra/includes/Makefile.am b/extra/includes/Makefile.am
new file mode 100644
index 0000000..5db221f
--- /dev/null
+++ b/extra/includes/Makefile.am
@@ -0,0 +1,28 @@
+## Process this file with automake to produce Makefile.in
+# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010 Free
+# Software Foundation, Inc.
+#
+# Author: Nikos Mavrogiannopoulos
+#
+# This file is part of GnuTLS-EXTRA.
+#
+# GnuTLS-extra is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3 of the
+# License, or (at your option) any later version.
+#
+# GnuTLS-extra is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GnuTLS-EXTRA; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+nobase_include_HEADERS = 
+
+if ENABLE_OPENSSL
+nobase_include_HEADERS += gnutls/openssl.h
+endif
diff --git a/libextra/includes/gnutls/openssl.h 
b/extra/includes/gnutls/openssl.h
similarity index 100%
rename from libextra/includes/gnutls/openssl.h
rename to extra/includes/gnutls/openssl.h
diff --git a/libextra/openssl_compat.c b/extra/openssl_compat.c
similarity index 100%
rename from libextra/openssl_compat.c
rename to extra/openssl_compat.c
diff --git a/libextra/openssl_compat.h b/extra/openssl_compat.h
similarity index 100%
rename from libextra/openssl_compat.h
rename to extra/openssl_compat.h
diff --git a/gl/Makefile.am b/gl/Makefile.am
index 93e68b2..e5e0b6a 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -2,14 +2,26 @@
 ## Process this file with automake to produce Makefile.in.
 # Copyright (C) 2002-2011 Free Software Foundation, Inc.
 #
-# This file is free software, distributed under the terms of the GNU
-# General Public License.  As a special exception to the GNU General
-# Public License, this file may be distributed as part of a program
-# that contains a configuration script generated by Autoconf, under
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this file.  If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License,
+# this file may be distributed as part of a program that
+# contains a configuration script generated by Autoconf, under
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override 
--lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc 
--tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests 
--avoid=lseek-tests --no-conditional-dependencies --libtool --macro-prefix=gl 
--no-vc-files alloca alphasort argp byteswap c-ctype crypto/hmac-md5 crypto/md5 
error extensions func getpass getsubopt gettext gettime havelib lib-msvc-compat 
lib-symbol-versions maintainer-makefile manywarnings memmem-simple minmax netdb 
netinet_in progname read-file scandir snprintf sockets socklen stdint strcase 
strverscmp sys_socket sys_stat time_r timespec u64 unistd valgrind-tests 
vasprintf version-etc version-etc-fsf vfprintf-posix vprintf-posix vsnprintf 
warnings
+# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override 
--lib=libgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc 
--tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests 
--avoid=lseek-tests --no-conditional-dependencies --libtool --macro-prefix=gl 
--no-vc-files accept alloca alphasort argp bind byteswap c-ctype close connect 
error extensions func getpass getsubopt gettext gettime havelib inet_ntop 
inet_pton lib-msvc-compat lib-symbol-versions listen maintainer-makefile 
manywarnings memmem-simple minmax netdb netinet_in pmccabe2html progname 
read-file recv recvfrom scandir select send sendto setsockopt shutdown snprintf 
socket sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r 
timespec u64 unistd valgrind-tests vasprintf version-etc version-etc-fsf 
vfprintf-posix vprintf-posix vsnprintf warnings
 
 AUTOMAKE_OPTIONS = 1.5 gnits
 
@@ -39,16 +51,21 @@ libgnu_la_DEPENDENCIES = $(gl_LTLIBOBJS)
 EXTRA_libgnu_la_SOURCES =
 libgnu_la_LDFLAGS = $(AM_LDFLAGS)
 libgnu_la_LDFLAGS += -no-undefined
+libgnu_la_LDFLAGS += $(INET_NTOP_LIB)
+libgnu_la_LDFLAGS += $(INET_PTON_LIB)
 libgnu_la_LDFLAGS += $(LIBSOCKET)
 libgnu_la_LDFLAGS += $(LIB_CLOCK_GETTIME)
+libgnu_la_LDFLAGS += $(LIB_SELECT)
 libgnu_la_LDFLAGS += $(LTLIBINTL)
 
-## begin gnulib module alignof
+## begin gnulib module accept
 
 
-EXTRA_DIST += alignof.h
+EXTRA_DIST += accept.c w32sock.h
 
-## end   gnulib module alignof
+EXTRA_libgnu_la_SOURCES += accept.c
+
+## end   gnulib module accept
 
 ## begin gnulib module alloca
 
@@ -102,6 +119,51 @@ libgnu_la_SOURCES += argp.h argp-ba.c argp-eexst.c \
 
 ## end   gnulib module argp
 
+## begin gnulib module arpa_inet
+
+BUILT_SOURCES += arpa/inet.h
+
+# We need the following in order to create <arpa/inet.h> when the system
+# doesn't have one.
+arpa/inet.h: arpa_inet.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(WARN_ON_USE_H) $(ARG_NONNULL_H)
+       $(AM_V_at)$(MKDIR_P) arpa
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''HAVE_FEATURES_H''@|$(HAVE_FEATURES_H)|g' \
+             -e 's|@''NEXT_ARPA_INET_H''@|$(NEXT_ARPA_INET_H)|g' \
+             -e 's|@''HAVE_ARPA_INET_H''@|$(HAVE_ARPA_INET_H)|g' \
+             -e 's/@''GNULIB_INET_NTOP''@/$(GNULIB_INET_NTOP)/g' \
+             -e 's/@''GNULIB_INET_PTON''@/$(GNULIB_INET_PTON)/g' \
+             -e 's|@''HAVE_DECL_INET_NTOP''@|$(HAVE_DECL_INET_NTOP)|g' \
+             -e 's|@''HAVE_DECL_INET_PTON''@|$(HAVE_DECL_INET_PTON)|g' \
+             -e 's|@''REPLACE_INET_NTOP''@|$(REPLACE_INET_NTOP)|g' \
+             -e 's|@''REPLACE_INET_PTON''@|$(REPLACE_INET_PTON)|g' \
+             -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+             -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+             -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+             < $(srcdir)/arpa_inet.in.h; \
+       } > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += arpa/inet.h arpa/inet.h-t
+MOSTLYCLEANDIRS += arpa
+
+EXTRA_DIST += arpa_inet.in.h
+
+## end   gnulib module arpa_inet
+
+## begin gnulib module bind
+
+
+EXTRA_DIST += bind.c w32sock.h
+
+EXTRA_libgnu_la_SOURCES += bind.c
+
+## end   gnulib module bind
+
 ## begin gnulib module byteswap
 
 BUILT_SOURCES += $(BYTESWAP_H)
@@ -131,6 +193,15 @@ libgnu_la_SOURCES += c-ctype.h c-ctype.c
 
 ## end   gnulib module c-ctype
 
+## begin gnulib module close
+
+
+EXTRA_DIST += close.c
+
+EXTRA_libgnu_la_SOURCES += close.c
+
+## end   gnulib module close
+
 ## begin gnulib module closedir
 
 
@@ -140,21 +211,14 @@ EXTRA_libgnu_la_SOURCES += closedir.c
 
 ## end   gnulib module closedir
 
-## begin gnulib module crypto/hmac-md5
-
-libgnu_la_SOURCES += hmac-md5.c
-
-EXTRA_DIST += hmac.h
+## begin gnulib module connect
 
-## end   gnulib module crypto/hmac-md5
 
-## begin gnulib module crypto/md5
+EXTRA_DIST += connect.c w32sock.h
 
-libgnu_la_SOURCES += md5.c
+EXTRA_libgnu_la_SOURCES += connect.c
 
-EXTRA_DIST += md5.h
-
-## end   gnulib module crypto/md5
+## end   gnulib module connect
 
 ## begin gnulib module dirent
 
@@ -292,6 +356,7 @@ float.h: float.in.h $(top_builddir)/config.status
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_FLOAT_H''@|$(NEXT_FLOAT_H)|g' \
+             -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \
              < $(srcdir)/float.in.h; \
        } > address@hidden && \
        mv address@hidden $@
@@ -301,9 +366,9 @@ float.h: $(top_builddir)/config.status
 endif
 MOSTLYCLEANFILES += float.h float.h-t
 
-EXTRA_DIST += float.c float.in.h
+EXTRA_DIST += float.c float.in.h itold.c
 
-EXTRA_libgnu_la_SOURCES += float.c
+EXTRA_libgnu_la_SOURCES += float.c itold.c
 
 ## end   gnulib module float
 
@@ -358,6 +423,15 @@ EXTRA_DIST += fseterr.h stdio-impl.h
 
 ## end   gnulib module fseterr
 
+## begin gnulib module fstat
+
+
+EXTRA_DIST += fstat.c
+
+EXTRA_libgnu_la_SOURCES += fstat.c
+
+## end   gnulib module fstat
+
 ## begin gnulib module ftell
 
 
@@ -430,6 +504,15 @@ EXTRA_libgnu_la_SOURCES += getpass.c
 
 ## end   gnulib module getpass
 
+## begin gnulib module getpeername
+
+
+EXTRA_DIST += getpeername.c w32sock.h
+
+EXTRA_libgnu_la_SOURCES += getpeername.c
+
+## end   gnulib module getpeername
+
 ## begin gnulib module getsubopt
 
 
@@ -493,6 +576,24 @@ EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath
 
 ## end   gnulib module havelib
 
+## begin gnulib module inet_ntop
+
+
+EXTRA_DIST += inet_ntop.c
+
+EXTRA_libgnu_la_SOURCES += inet_ntop.c
+
+## end   gnulib module inet_ntop
+
+## begin gnulib module inet_pton
+
+
+EXTRA_DIST += inet_pton.c
+
+EXTRA_libgnu_la_SOURCES += inet_pton.c
+
+## end   gnulib module inet_pton
+
 ## begin gnulib module intprops
 
 
@@ -527,6 +628,15 @@ EXTRA_libgnu_la_SOURCES += isnan.c isnanl.c
 
 ## end   gnulib module isnanl-nolibm
 
+## begin gnulib module listen
+
+
+EXTRA_DIST += listen.c w32sock.h
+
+EXTRA_libgnu_la_SOURCES += listen.c
+
+## end   gnulib module listen
+
 ## begin gnulib module lseek
 
 
@@ -574,17 +684,33 @@ math.h: math.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 
's|@''NEXT_AS_FIRST_DIRECTIVE_MATH_H''@|$(NEXT_AS_FIRST_DIRECTIVE_MATH_H)|g' \
+             -e 's/@''GNULIB_ACOSF''@/$(GNULIB_ACOSF)/g' \
              -e 's/@''GNULIB_ACOSL''@/$(GNULIB_ACOSL)/g' \
+             -e 's/@''GNULIB_ASINF''@/$(GNULIB_ASINF)/g' \
              -e 's/@''GNULIB_ASINL''@/$(GNULIB_ASINL)/g' \
+             -e 's/@''GNULIB_ATANF''@/$(GNULIB_ATANF)/g' \
              -e 's/@''GNULIB_ATANL''@/$(GNULIB_ATANL)/g' \
+             -e 's/@''GNULIB_ATAN2F''@/$(GNULIB_ATAN2F)/g' \
              -e 's/@''GNULIB_CEIL''@/$(GNULIB_CEIL)/g' \
              -e 's/@''GNULIB_CEILF''@/$(GNULIB_CEILF)/g' \
              -e 's/@''GNULIB_CEILL''@/$(GNULIB_CEILL)/g' \
+             -e 's/@''GNULIB_COPYSIGN''@/$(GNULIB_COPYSIGN)/g' \
+             -e 's/@''GNULIB_COPYSIGNF''@/$(GNULIB_COPYSIGNF)/g' \
+             -e 's/@''GNULIB_COPYSIGNL''@/$(GNULIB_COPYSIGNL)/g' \
+             -e 's/@''GNULIB_COSF''@/$(GNULIB_COSF)/g' \
              -e 's/@''GNULIB_COSL''@/$(GNULIB_COSL)/g' \
+             -e 's/@''GNULIB_COSHF''@/$(GNULIB_COSHF)/g' \
+             -e 's/@''GNULIB_EXPF''@/$(GNULIB_EXPF)/g' \
              -e 's/@''GNULIB_EXPL''@/$(GNULIB_EXPL)/g' \
+             -e 's/@''GNULIB_FABSF''@/$(GNULIB_FABSF)/g' \
              -e 's/@''GNULIB_FLOOR''@/$(GNULIB_FLOOR)/g' \
              -e 's/@''GNULIB_FLOORF''@/$(GNULIB_FLOORF)/g' \
              -e 's/@''GNULIB_FLOORL''@/$(GNULIB_FLOORL)/g' \
+             -e 's/@''GNULIB_FMA''@/$(GNULIB_FMA)/g' \
+             -e 's/@''GNULIB_FMAF''@/$(GNULIB_FMAF)/g' \
+             -e 's/@''GNULIB_FMAL''@/$(GNULIB_FMAL)/g' \
+             -e 's/@''GNULIB_FMODF''@/$(GNULIB_FMODF)/g' \
+             -e 's/@''GNULIB_FREXPF''@/$(GNULIB_FREXPF)/g' \
              -e 's/@''GNULIB_FREXP''@/$(GNULIB_FREXP)/g' \
              -e 's/@''GNULIB_FREXPL''@/$(GNULIB_FREXPL)/g' \
              -e 's/@''GNULIB_ISFINITE''@/$(GNULIB_ISFINITE)/g' \
@@ -593,32 +719,74 @@ math.h: math.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's/@''GNULIB_ISNANF''@/$(GNULIB_ISNANF)/g' \
              -e 's/@''GNULIB_ISNAND''@/$(GNULIB_ISNAND)/g' \
              -e 's/@''GNULIB_ISNANL''@/$(GNULIB_ISNANL)/g' \
+             -e 's/@''GNULIB_LDEXPF''@/$(GNULIB_LDEXPF)/g' \
              -e 's/@''GNULIB_LDEXPL''@/$(GNULIB_LDEXPL)/g' \
              -e 's/@''GNULIB_LOGB''@/$(GNULIB_LOGB)/g' \
+             -e 's/@''GNULIB_LOGF''@/$(GNULIB_LOGF)/g' \
              -e 's/@''GNULIB_LOGL''@/$(GNULIB_LOGL)/g' \
+             -e 's/@''GNULIB_LOG10F''@/$(GNULIB_LOG10F)/g' \
+             -e 's/@''GNULIB_MODFF''@/$(GNULIB_MODFF)/g' \
+             -e 's/@''GNULIB_POWF''@/$(GNULIB_POWF)/g' \
+             -e 's/@''GNULIB_RINT''@/$(GNULIB_RINT)/g' \
+             -e 's/@''GNULIB_RINTF''@/$(GNULIB_RINTF)/g' \
+             -e 's/@''GNULIB_RINTL''@/$(GNULIB_RINTL)/g' \
              -e 's/@''GNULIB_ROUND''@/$(GNULIB_ROUND)/g' \
              -e 's/@''GNULIB_ROUNDF''@/$(GNULIB_ROUNDF)/g' \
              -e 's/@''GNULIB_ROUNDL''@/$(GNULIB_ROUNDL)/g' \
              -e 's/@''GNULIB_SIGNBIT''@/$(GNULIB_SIGNBIT)/g' \
+             -e 's/@''GNULIB_SINF''@/$(GNULIB_SINF)/g' \
              -e 's/@''GNULIB_SINL''@/$(GNULIB_SINL)/g' \
+             -e 's/@''GNULIB_SINHF''@/$(GNULIB_SINHF)/g' \
+             -e 's/@''GNULIB_SQRTF''@/$(GNULIB_SQRTF)/g' \
              -e 's/@''GNULIB_SQRTL''@/$(GNULIB_SQRTL)/g' \
+             -e 's/@''GNULIB_TANF''@/$(GNULIB_TANF)/g' \
              -e 's/@''GNULIB_TANL''@/$(GNULIB_TANL)/g' \
+             -e 's/@''GNULIB_TANHF''@/$(GNULIB_TANHF)/g' \
              -e 's/@''GNULIB_TRUNC''@/$(GNULIB_TRUNC)/g' \
              -e 's/@''GNULIB_TRUNCF''@/$(GNULIB_TRUNCF)/g' \
              -e 's/@''GNULIB_TRUNCL''@/$(GNULIB_TRUNCL)/g' \
              < $(srcdir)/math.in.h | \
-         sed -e 's|@''HAVE_ACOSL''@|$(HAVE_ACOSL)|g' \
+         sed -e 's|@''HAVE_ACOSF''@|$(HAVE_ACOSF)|g' \
+             -e 's|@''HAVE_ACOSL''@|$(HAVE_ACOSL)|g' \
+             -e 's|@''HAVE_ASINF''@|$(HAVE_ASINF)|g' \
              -e 's|@''HAVE_ASINL''@|$(HAVE_ASINL)|g' \
+             -e 's|@''HAVE_ATANF''@|$(HAVE_ATANF)|g' \
              -e 's|@''HAVE_ATANL''@|$(HAVE_ATANL)|g' \
+             -e 's|@''HAVE_ATAN2F''@|$(HAVE_ATAN2F)|g' \
+             -e 's|@''HAVE_COPYSIGN''@|$(HAVE_COPYSIGN)|g' \
+             -e 's|@''HAVE_COPYSIGNF''@|$(HAVE_COPYSIGNF)|g' \
+             -e 's|@''HAVE_COPYSIGNL''@|$(HAVE_COPYSIGNL)|g' \
+             -e 's|@''HAVE_COSF''@|$(HAVE_COSF)|g' \
              -e 's|@''HAVE_COSL''@|$(HAVE_COSL)|g' \
+             -e 's|@''HAVE_COSHF''@|$(HAVE_COSHF)|g' \
+             -e 's|@''HAVE_EXPF''@|$(HAVE_EXPF)|g' \
              -e 's|@''HAVE_EXPL''@|$(HAVE_EXPL)|g' \
+             -e 's|@''HAVE_FABSF''@|$(HAVE_FABSF)|g' \
+             -e 's|@''HAVE_FMA''@|$(HAVE_FMA)|g' \
+             -e 's|@''HAVE_FMAF''@|$(HAVE_FMAF)|g' \
+             -e 's|@''HAVE_FMAL''@|$(HAVE_FMAL)|g' \
+             -e 's|@''HAVE_FMODF''@|$(HAVE_FMODF)|g' \
+             -e 's|@''HAVE_FREXPF''@|$(HAVE_FREXPF)|g' \
              -e 's|@''HAVE_ISNANF''@|$(HAVE_ISNANF)|g' \
              -e 's|@''HAVE_ISNAND''@|$(HAVE_ISNAND)|g' \
              -e 's|@''HAVE_ISNANL''@|$(HAVE_ISNANL)|g' \
+             -e 's|@''HAVE_LDEXPF''@|$(HAVE_LDEXPF)|g' \
+             -e 's|@''HAVE_LOGF''@|$(HAVE_LOGF)|g' \
              -e 's|@''HAVE_LOGL''@|$(HAVE_LOGL)|g' \
+             -e 's|@''HAVE_LOG10F''@|$(HAVE_LOG10F)|g' \
+             -e 's|@''HAVE_MODFF''@|$(HAVE_MODFF)|g' \
+             -e 's|@''HAVE_POWF''@|$(HAVE_POWF)|g' \
+             -e 's|@''HAVE_RINT''@|$(HAVE_RINT)|g' \
+             -e 's|@''HAVE_RINTF''@|$(HAVE_RINTF)|g' \
+             -e 's|@''HAVE_RINTL''@|$(HAVE_RINTL)|g' \
+             -e 's|@''HAVE_SINF''@|$(HAVE_SINF)|g' \
              -e 's|@''HAVE_SINL''@|$(HAVE_SINL)|g' \
+             -e 's|@''HAVE_SINHF''@|$(HAVE_SINHF)|g' \
+             -e 's|@''HAVE_SQRTF''@|$(HAVE_SQRTF)|g' \
              -e 's|@''HAVE_SQRTL''@|$(HAVE_SQRTL)|g' \
+             -e 's|@''HAVE_TANF''@|$(HAVE_TANF)|g' \
              -e 's|@''HAVE_TANL''@|$(HAVE_TANL)|g' \
+             -e 's|@''HAVE_TANHF''@|$(HAVE_TANHF)|g' \
              -e 's|@''HAVE_DECL_ACOSL''@|$(HAVE_DECL_ACOSL)|g' \
              -e 's|@''HAVE_DECL_ASINL''@|$(HAVE_DECL_ASINL)|g' \
              -e 's|@''HAVE_DECL_ATANL''@|$(HAVE_DECL_ATANL)|g' \
@@ -648,12 +816,17 @@ math.h: math.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H) $(
              -e 's|@''REPLACE_FLOOR''@|$(REPLACE_FLOOR)|g' \
              -e 's|@''REPLACE_FLOORF''@|$(REPLACE_FLOORF)|g' \
              -e 's|@''REPLACE_FLOORL''@|$(REPLACE_FLOORL)|g' \
+             -e 's|@''REPLACE_FMA''@|$(REPLACE_FMA)|g' \
+             -e 's|@''REPLACE_FMAF''@|$(REPLACE_FMAF)|g' \
+             -e 's|@''REPLACE_FMAL''@|$(REPLACE_FMAL)|g' \
+             -e 's|@''REPLACE_FREXPF''@|$(REPLACE_FREXPF)|g' \
              -e 's|@''REPLACE_FREXP''@|$(REPLACE_FREXP)|g' \
              -e 's|@''REPLACE_FREXPL''@|$(REPLACE_FREXPL)|g' \
              -e 's|@''REPLACE_HUGE_VAL''@|$(REPLACE_HUGE_VAL)|g' \
              -e 's|@''REPLACE_ISFINITE''@|$(REPLACE_ISFINITE)|g' \
              -e 's|@''REPLACE_ISINF''@|$(REPLACE_ISINF)|g' \
              -e 's|@''REPLACE_ISNAN''@|$(REPLACE_ISNAN)|g' \
+             -e 's|@''REPLACE_ITOLD''@|$(REPLACE_ITOLD)|g' \
              -e 's|@''REPLACE_LDEXPL''@|$(REPLACE_LDEXPL)|g' \
              -e 's|@''REPLACE_NAN''@|$(REPLACE_NAN)|g' \
              -e 's|@''REPLACE_ROUND''@|$(REPLACE_ROUND)|g' \
@@ -702,19 +875,29 @@ EXTRA_libgnu_la_SOURCES += mempcpy.c
 
 ## end   gnulib module mempcpy
 
-## begin gnulib module memxor
+## begin gnulib module minmax
 
-libgnu_la_SOURCES += memxor.c
+libgnu_la_SOURCES += minmax.h
 
-EXTRA_DIST += memxor.h
+## end   gnulib module minmax
 
-## end   gnulib module memxor
+## begin gnulib module msvc-inval
 
-## begin gnulib module minmax
 
-libgnu_la_SOURCES += minmax.h
+EXTRA_DIST += msvc-inval.c msvc-inval.h
 
-## end   gnulib module minmax
+EXTRA_libgnu_la_SOURCES += msvc-inval.c
+
+## end   gnulib module msvc-inval
+
+## begin gnulib module msvc-nothrow
+
+
+EXTRA_DIST += msvc-nothrow.c msvc-nothrow.h
+
+EXTRA_libgnu_la_SOURCES += msvc-nothrow.c
+
+## end   gnulib module msvc-nothrow
 
 ## begin gnulib module netdb
 
@@ -790,6 +973,13 @@ EXTRA_libgnu_la_SOURCES += opendir.c
 
 ## end   gnulib module opendir
 
+## begin gnulib module pmccabe2html
+
+
+EXTRA_DIST += $(top_srcdir)/build-aux/pmccabe2html 
$(top_srcdir)/build-aux/pmccabe.css
+
+## end   gnulib module pmccabe2html
+
 ## begin gnulib module printf-frexp
 
 libgnu_la_SOURCES += printf-frexp.c
@@ -849,6 +1039,24 @@ EXTRA_libgnu_la_SOURCES += realloc.c
 
 ## end   gnulib module realloc-posix
 
+## begin gnulib module recv
+
+
+EXTRA_DIST += recv.c w32sock.h
+
+EXTRA_libgnu_la_SOURCES += recv.c
+
+## end   gnulib module recv
+
+## begin gnulib module recvfrom
+
+
+EXTRA_DIST += recvfrom.c w32sock.h
+
+EXTRA_libgnu_la_SOURCES += recvfrom.c
+
+## end   gnulib module recvfrom
+
 ## begin gnulib module scandir
 
 
@@ -858,6 +1066,93 @@ EXTRA_libgnu_la_SOURCES += scandir.c
 
 ## end   gnulib module scandir
 
+## begin gnulib module select
+
+
+EXTRA_DIST += select.c
+
+EXTRA_libgnu_la_SOURCES += select.c
+
+## end   gnulib module select
+
+## begin gnulib module send
+
+
+EXTRA_DIST += send.c w32sock.h
+
+EXTRA_libgnu_la_SOURCES += send.c
+
+## end   gnulib module send
+
+## begin gnulib module sendto
+
+
+EXTRA_DIST += sendto.c w32sock.h
+
+EXTRA_libgnu_la_SOURCES += sendto.c
+
+## end   gnulib module sendto
+
+## begin gnulib module setsockopt
+
+
+EXTRA_DIST += setsockopt.c w32sock.h
+
+EXTRA_libgnu_la_SOURCES += setsockopt.c
+
+## end   gnulib module setsockopt
+
+## begin gnulib module shutdown
+
+
+EXTRA_DIST += shutdown.c w32sock.h
+
+EXTRA_libgnu_la_SOURCES += shutdown.c
+
+## end   gnulib module shutdown
+
+## begin gnulib module signal-h
+
+BUILT_SOURCES += signal.h
+
+# We need the following in order to create <signal.h> when the system
+# doesn't have a complete one.
+signal.h: signal.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(ARG_NONNULL_H) $(WARN_ON_USE_H)
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */' && \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''NEXT_SIGNAL_H''@|$(NEXT_SIGNAL_H)|g' \
+             -e 's|@''GNULIB_PTHREAD_SIGMASK''@|$(GNULIB_PTHREAD_SIGMASK)|g' \
+             -e 's|@''GNULIB_RAISE''@|$(GNULIB_RAISE)|g' \
+             -e 's/@''GNULIB_SIGNAL_H_SIGPIPE''@/$(GNULIB_SIGNAL_H_SIGPIPE)/g' 
\
+             -e 's/@''GNULIB_SIGPROCMASK''@/$(GNULIB_SIGPROCMASK)/g' \
+             -e 's/@''GNULIB_SIGACTION''@/$(GNULIB_SIGACTION)/g' \
+             -e 
's|@''HAVE_POSIX_SIGNALBLOCKING''@|$(HAVE_POSIX_SIGNALBLOCKING)|g' \
+             -e 's|@''HAVE_PTHREAD_SIGMASK''@|$(HAVE_PTHREAD_SIGMASK)|g' \
+             -e 's|@''HAVE_RAISE''@|$(HAVE_RAISE)|g' \
+             -e 's|@''HAVE_SIGSET_T''@|$(HAVE_SIGSET_T)|g' \
+             -e 's|@''HAVE_SIGINFO_T''@|$(HAVE_SIGINFO_T)|g' \
+             -e 's|@''HAVE_SIGACTION''@|$(HAVE_SIGACTION)|g' \
+             -e 
's|@''HAVE_STRUCT_SIGACTION_SA_SIGACTION''@|$(HAVE_STRUCT_SIGACTION_SA_SIGACTION)|g'
 \
+             -e 
's|@''HAVE_TYPE_VOLATILE_SIG_ATOMIC_T''@|$(HAVE_TYPE_VOLATILE_SIG_ATOMIC_T)|g' \
+             -e 's|@''HAVE_SIGHANDLER_T''@|$(HAVE_SIGHANDLER_T)|g' \
+             -e 's|@''REPLACE_PTHREAD_SIGMASK''@|$(REPLACE_PTHREAD_SIGMASK)|g' 
\
+             -e 's|@''REPLACE_RAISE''@|$(REPLACE_RAISE)|g' \
+             -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+             -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+             -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+             < $(srcdir)/signal.in.h; \
+       } > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += signal.h signal.h-t
+
+EXTRA_DIST += signal.in.h
+
+## end   gnulib module signal-h
+
 ## begin gnulib module signbit
 
 
@@ -972,6 +1267,15 @@ EXTRA_libgnu_la_SOURCES += snprintf.c
 
 ## end   gnulib module snprintf
 
+## begin gnulib module socket
+
+
+EXTRA_DIST += socket.c w32sock.h
+
+EXTRA_libgnu_la_SOURCES += socket.c
+
+## end   gnulib module socket
+
 ## begin gnulib module sockets
 
 libgnu_la_SOURCES += sockets.h sockets.c
@@ -980,6 +1284,29 @@ EXTRA_DIST += w32sock.h
 
 ## end   gnulib module sockets
 
+## begin gnulib module stdalign
+
+BUILT_SOURCES += $(STDALIGN_H)
+
+# We need the following in order to create <stdalign.h> when the system
+# doesn't have one that works.
+if GL_GENERATE_STDALIGN_H
+stdalign.h: stdalign.in.h $(top_builddir)/config.status
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         cat $(srcdir)/stdalign.in.h; \
+       } > address@hidden && \
+       mv address@hidden $@
+else
+stdalign.h: $(top_builddir)/config.status
+       rm -f $@
+endif
+MOSTLYCLEANFILES += stdalign.h stdalign.h-t
+
+EXTRA_DIST += stdalign.in.h
+
+## end   gnulib module stdalign
+
 ## begin gnulib module stdarg
 
 BUILT_SOURCES += $(STDARG_H)
@@ -1127,6 +1454,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's|@''NEXT_STDIO_H''@|$(NEXT_STDIO_H)|g' \
              -e 's/@''GNULIB_DPRINTF''@/$(GNULIB_DPRINTF)/g' \
              -e 's/@''GNULIB_FCLOSE''@/$(GNULIB_FCLOSE)/g' \
+             -e 's/@''GNULIB_FDOPEN''@/$(GNULIB_FDOPEN)/g' \
              -e 's/@''GNULIB_FFLUSH''@/$(GNULIB_FFLUSH)/g' \
              -e 's/@''GNULIB_FGETC''@/$(GNULIB_FGETC)/g' \
              -e 's/@''GNULIB_FGETS''@/$(GNULIB_FGETS)/g' \
@@ -1197,6 +1525,7 @@ stdio.h: stdio.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H)
              -e 's|@''HAVE_VDPRINTF''@|$(HAVE_VDPRINTF)|g' \
              -e 's|@''REPLACE_DPRINTF''@|$(REPLACE_DPRINTF)|g' \
              -e 's|@''REPLACE_FCLOSE''@|$(REPLACE_FCLOSE)|g' \
+             -e 's|@''REPLACE_FDOPEN''@|$(REPLACE_FDOPEN)|g' \
              -e 's|@''REPLACE_FFLUSH''@|$(REPLACE_FFLUSH)|g' \
              -e 's|@''REPLACE_FOPEN''@|$(REPLACE_FOPEN)|g' \
              -e 's|@''REPLACE_FPRINTF''@|$(REPLACE_FPRINTF)|g' \
@@ -1267,6 +1596,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) \
              -e 's/@''GNULIB_MKOSTEMPS''@/$(GNULIB_MKOSTEMPS)/g' \
              -e 's/@''GNULIB_MKSTEMP''@/$(GNULIB_MKSTEMP)/g' \
              -e 's/@''GNULIB_MKSTEMPS''@/$(GNULIB_MKSTEMPS)/g' \
+             -e 's/@''GNULIB_POSIX_OPENPT''@/$(GNULIB_POSIX_OPENPT)/g' \
              -e 's/@''GNULIB_PTSNAME''@/$(GNULIB_PTSNAME)/g' \
              -e 's/@''GNULIB_PUTENV''@/$(GNULIB_PUTENV)/g' \
              -e 's/@''GNULIB_RANDOM_R''@/$(GNULIB_RANDOM_R)/g' \
@@ -1293,6 +1623,7 @@ stdlib.h: stdlib.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) \
              -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \
              -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \
              -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \
+             -e 's|@''HAVE_POSIX_OPENPT''@|$(HAVE_POSIX_OPENPT)|g' \
              -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \
              -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \
              -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
@@ -1533,6 +1864,40 @@ EXTRA_libgnu_la_SOURCES += strverscmp.c
 
 ## end   gnulib module strverscmp
 
+## begin gnulib module sys_select
+
+BUILT_SOURCES += sys/select.h
+
+# We need the following in order to create <sys/select.h> when the system
+# doesn't have one that works with the given compiler.
+sys/select.h: sys_select.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(WARN_ON_USE_H)
+       $(AM_V_at)$(MKDIR_P) sys
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''NEXT_SYS_SELECT_H''@|$(NEXT_SYS_SELECT_H)|g' \
+             -e 's|@''HAVE_SYS_SELECT_H''@|$(HAVE_SYS_SELECT_H)|g' \
+             -e 's/@''GNULIB_PSELECT''@/$(GNULIB_PSELECT)/g' \
+             -e 's/@''GNULIB_SELECT''@/$(GNULIB_SELECT)/g' \
+             -e 's|@''HAVE_WINSOCK2_H''@|$(HAVE_WINSOCK2_H)|g' \
+             -e 's|@''HAVE_PSELECT''@|$(HAVE_PSELECT)|g' \
+             -e 's|@''REPLACE_PSELECT''@|$(REPLACE_PSELECT)|g' \
+             -e 's|@''REPLACE_SELECT''@|$(REPLACE_SELECT)|g' \
+             -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+             -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+             < $(srcdir)/sys_select.in.h; \
+       } > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += sys/select.h sys/select.h-t
+MOSTLYCLEANDIRS += sys
+
+EXTRA_DIST += sys_select.in.h
+
+## end   gnulib module sys_select
+
 ## begin gnulib module sys_socket
 
 BUILT_SOURCES += sys/socket.h
@@ -1600,6 +1965,7 @@ sys/stat.h: sys_stat.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNU
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_SYS_STAT_H''@|$(NEXT_SYS_STAT_H)|g' \
              -e 's/@''GNULIB_FCHMODAT''@/$(GNULIB_FCHMODAT)/g' \
+             -e 's/@''GNULIB_FSTAT''@/$(GNULIB_FSTAT)/g' \
              -e 's/@''GNULIB_FSTATAT''@/$(GNULIB_FSTATAT)/g' \
              -e 's/@''GNULIB_FUTIMENS''@/$(GNULIB_FUTIMENS)/g' \
              -e 's/@''GNULIB_LCHMOD''@/$(GNULIB_LCHMOD)/g' \
@@ -1836,8 +2202,10 @@ unistd.h: unistd.in.h $(top_builddir)/config.status 
$(CXXDEFS_H) $(ARG_NONNULL_H
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
              -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \
+             -e 's/@''GNULIB_CHDIR''@/$(GNULIB_CHDIR)/g' \
              -e 's/@''GNULIB_CHOWN''@/$(GNULIB_CHOWN)/g' \
              -e 's/@''GNULIB_CLOSE''@/$(GNULIB_CLOSE)/g' \
+             -e 's/@''GNULIB_DUP''@/$(GNULIB_DUP)/g' \
              -e 's/@''GNULIB_DUP2''@/$(GNULIB_DUP2)/g' \
              -e 's/@''GNULIB_DUP3''@/$(GNULIB_DUP3)/g' \
              -e 's/@''GNULIB_ENVIRON''@/$(GNULIB_ENVIRON)/g' \
diff --git a/gl/accept.c b/gl/accept.c
new file mode 100644
index 0000000..01faf54
--- /dev/null
+++ b/gl/accept.c
@@ -0,0 +1,52 @@
+/* accept.c --- wrappers for Windows accept function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef accept
+
+int
+rpl_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      SOCKET fh = accept (sock, addr, addrlen);
+      if (fh == INVALID_SOCKET)
+        {
+          set_winsock_errno ();
+          return -1;
+        }
+      else
+        return SOCKET_TO_FD (fh);
+    }
+}
diff --git a/gl/alignof.h b/gl/alignof.h
deleted file mode 100644
index 1c1f75c..0000000
--- a/gl/alignof.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* Determine alignment of types.
-   Copyright (C) 2003-2004, 2006, 2009-2011 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef _ALIGNOF_H
-#define _ALIGNOF_H
-
-#include <stddef.h>
-
-/* Determine the alignment of a structure slot (field) of a given type,
-   at compile time.  Note that the result depends on the ABI.
-   Note: The result cannot be used as a value for an 'enum' constant,
-   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
-#if defined __cplusplus
-  template <class type> struct alignof_helper { char __slot1; type __slot2; };
-# define alignof_slot(type) offsetof (alignof_helper<type>, __slot2)
-#else
-# define alignof_slot(type) offsetof (struct { char __slot1; type __slot2; }, 
__slot2)
-#endif
-
-/* Determine the good alignment of an object of the given type at compile time.
-   Note that this is not necessarily the same as alignof_slot(type).
-   For example, with GNU C on x86 platforms: alignof_type(double) = 8, but
-   - when -malign-double is not specified:  alignof_slot(double) = 4,
-   - when -malign-double is specified:      alignof_slot(double) = 8.
-   Note: The result cannot be used as a value for an 'enum' constant,
-   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
-#if defined __GNUC__
-# define alignof_type __alignof__
-#else
-# define alignof_type alignof_slot
-#endif
-
-/* alignof is an alias for alignof_slot semantics, since that's what most
-   callers need.
-   Note: The result cannot be used as a value for an 'enum' constant,
-   due to bugs in HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
-#define alignof alignof_slot
-
-#endif /* _ALIGNOF_H */
diff --git a/gl/argp-parse.c b/gl/argp-parse.c
index 5cab8ce..64360be 100644
--- a/gl/argp-parse.c
+++ b/gl/argp-parse.c
@@ -21,6 +21,7 @@
 #endif
 
 #include <alloca.h>
+#include <stdalign.h>
 #include <stddef.h>
 #include <stdlib.h>
 #include <string.h>
@@ -42,7 +43,6 @@
 #include "argp.h"
 #include "argp-namefrob.h"
 
-#define alignof(type) offsetof (struct { char c; type x; }, x)
 #define alignto(n, d) ((((n) + (d) - 1) / (d)) * (d))
 
 /* Getopt return values.  */
diff --git a/gl/arpa_inet.in.h b/gl/arpa_inet.in.h
new file mode 100644
index 0000000..5264853
--- /dev/null
+++ b/gl/arpa_inet.in.h
@@ -0,0 +1,141 @@
+/* A GNU-like <arpa/inet.h>.
+
+   Copyright (C) 2005-2006, 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifndef address@hidden@_ARPA_INET_H
+
+#if __GNUC__ >= 3
address@hidden@
+#endif
address@hidden@
+
+#if @HAVE_FEATURES_H@
+# include <features.h> /* for __GLIBC__ */
+#endif
+
+/* Gnulib's sys/socket.h is responsible for defining socklen_t (used below) and
+   for pulling in winsock2.h etc. under MinGW.
+   But avoid namespace pollution on glibc systems.  */
+#ifndef __GLIBC__
+# include <sys/socket.h>
+#endif
+
+/* On NonStop Kernel, inet_ntop and inet_pton are declared in <netdb.h>.
+   But avoid namespace pollution on glibc systems.  */
+#if defined __TANDEM && !defined __GLIBC__
+# include <netdb.h>
+#endif
+
+#if @HAVE_ARPA_INET_H@
+
+/* The include_next requires a split double-inclusion guard.  */
+# @INCLUDE_NEXT@ @NEXT_ARPA_INET_H@
+
+#endif
+
+#ifndef address@hidden@_ARPA_INET_H
+#define address@hidden@_ARPA_INET_H
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_ARG_NONNULL is copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+
+#if @GNULIB_INET_NTOP@
+/* Converts an internet address from internal format to a printable,
+   presentable format.
+   AF is an internet address family, such as AF_INET or AF_INET6.
+   SRC points to a 'struct in_addr' (for AF_INET) or 'struct in6_addr'
+   (for AF_INET6).
+   DST points to a buffer having room for CNT bytes.
+   The printable representation of the address (in numeric form, not
+   surrounded by [...], no reverse DNS is done) is placed in DST, and
+   DST is returned.  If an error occurs, the return value is NULL and
+   errno is set.  If CNT bytes are not sufficient to hold the result,
+   the return value is NULL and errno is set to ENOSPC.  A good value
+   for CNT is 46.
+
+   For more details, see the POSIX:2001 specification
+   <http://www.opengroup.org/susv3xsh/inet_ntop.html>.  */
+# if @REPLACE_INET_NTOP@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef inet_ntop
+#   define inet_ntop rpl_inet_ntop
+#  endif
+_GL_FUNCDECL_RPL (inet_ntop, const char *,
+                  (int af, const void *restrict src,
+                   char *restrict dst, socklen_t cnt)
+                  _GL_ARG_NONNULL ((2, 3)));
+_GL_CXXALIAS_RPL (inet_ntop, const char *,
+                  (int af, const void *restrict src,
+                   char *restrict dst, socklen_t cnt));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (inet_ntop, const char *,
+                  (int af, const void *restrict src,
+                   char *restrict dst, socklen_t cnt)
+                  _GL_ARG_NONNULL ((2, 3)));
+#  endif
+/* Need to cast, because on NonStop Kernel, the fourth parameter is
+                                            size_t cnt.  */
+_GL_CXXALIAS_SYS_CAST (inet_ntop, const char *,
+                       (int af, const void *restrict src,
+                        char *restrict dst, socklen_t cnt));
+# endif
+_GL_CXXALIASWARN (inet_ntop);
+#elif defined GNULIB_POSIXCHECK
+# undef inet_ntop
+# if HAVE_RAW_DECL_INET_NTOP
+_GL_WARN_ON_USE (inet_ntop, "inet_ntop is unportable - "
+                 "use gnulib module inet_ntop for portability");
+# endif
+#endif
+
+#if @GNULIB_INET_PTON@
+# if @REPLACE_INET_PTON@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef inet_pton
+#   define inet_pton rpl_inet_pton
+#  endif
+_GL_FUNCDECL_RPL (inet_pton, int,
+                  (int af, const char *restrict src, void *restrict dst)
+                  _GL_ARG_NONNULL ((2, 3)));
+_GL_CXXALIAS_RPL (inet_pton, int,
+                  (int af, const char *restrict src, void *restrict dst));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (inet_pton, int,
+                  (int af, const char *restrict src, void *restrict dst)
+                  _GL_ARG_NONNULL ((2, 3)));
+#  endif
+_GL_CXXALIAS_SYS (inet_pton, int,
+                  (int af, const char *restrict src, void *restrict dst));
+# endif
+_GL_CXXALIASWARN (inet_pton);
+#elif defined GNULIB_POSIXCHECK
+# undef inet_pton
+# if HAVE_RAW_DECL_INET_PTON
+_GL_WARN_ON_USE (inet_pton, "inet_pton is unportable - "
+                 "use gnulib module inet_pton for portability");
+# endif
+#endif
+
+
+#endif /* address@hidden@_ARPA_INET_H */
+#endif /* address@hidden@_ARPA_INET_H */
diff --git a/gl/bind.c b/gl/bind.c
new file mode 100644
index 0000000..baaea59
--- /dev/null
+++ b/gl/bind.c
@@ -0,0 +1,49 @@
+/* bind.c --- wrappers for Windows bind function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef bind
+
+int
+rpl_bind (int fd, const struct sockaddr *sockaddr, socklen_t len)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = bind (sock, sockaddr, len);
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
+}
diff --git a/gl/close.c b/gl/close.c
new file mode 100644
index 0000000..c2197fe
--- /dev/null
+++ b/gl/close.c
@@ -0,0 +1,69 @@
+/* close replacement.
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <unistd.h>
+
+#include <errno.h>
+
+#include "fd-hook.h"
+#include "msvc-inval.h"
+
+#undef close
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static int
+close_nothrow (int fd)
+{
+  int result;
+
+  TRY_MSVC_INVAL
+    {
+      result = close (fd);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = -1;
+      errno = EBADF;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#else
+# define close_nothrow close
+#endif
+
+/* Override close() to call into other gnulib modules.  */
+
+int
+rpl_close (int fd)
+{
+#if WINDOWS_SOCKETS
+  int retval = execute_all_close_hooks (close_nothrow, fd);
+#else
+  int retval = close_nothrow (fd);
+#endif
+
+#if REPLACE_FCHDIR
+  if (retval >= 0)
+    _gl_unregister_fd (fd);
+#endif
+
+  return retval;
+}
diff --git a/gl/closedir.c b/gl/closedir.c
index 700d60e..0fdce18 100644
--- a/gl/closedir.c
+++ b/gl/closedir.c
@@ -19,6 +19,10 @@
 /* Specification.  */
 #include <dirent.h>
 
+#if REPLACE_FCHDIR
+# include <unistd.h>
+#endif
+
 #if HAVE_CLOSEDIR
 
 /* Override closedir(), to keep track of the open file descriptors.
diff --git a/gl/connect.c b/gl/connect.c
new file mode 100644
index 0000000..afd13b9
--- /dev/null
+++ b/gl/connect.c
@@ -0,0 +1,56 @@
+/* connect.c --- wrappers for Windows connect function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef connect
+
+int
+rpl_connect (int fd, const struct sockaddr *sockaddr, socklen_t len)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = connect (sock, sockaddr, len);
+      if (r < 0)
+        {
+          /* EINPROGRESS is not returned by WinSock 2.0; for backwards
+             compatibility, connect(2) uses EWOULDBLOCK.  */
+          if (WSAGetLastError () == WSAEWOULDBLOCK)
+            WSASetLastError (WSAEINPROGRESS);
+
+          set_winsock_errno ();
+        }
+
+      return r;
+    }
+}
diff --git a/gl/errno.in.h b/gl/errno.in.h
index 5a7533a..b6014b4 100644
--- a/gl/errno.in.h
+++ b/gl/errno.in.h
@@ -33,50 +33,106 @@
 /* On native Windows platforms, many macros are not defined.  */
 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 
-/* POSIX says that EAGAIN and EWOULDBLOCK may have the same value.  */
-#  define EWOULDBLOCK     EAGAIN
-
-/* Values >= 100 seem safe to use.  */
-#  define ETXTBSY   100
-#  define GNULIB_defined_ETXTBSY 1
+/* These are the same values as defined by MSVC 10, for interoperability.  */
+
+#  ifndef ENOMSG
+#   define ENOMSG    122
+#   define GNULIB_defined_ENOMSG 1
+#  endif
+
+#  ifndef EIDRM
+#   define EIDRM     111
+#   define GNULIB_defined_EIDRM 1
+#  endif
+
+#  ifndef ENOLINK
+#   define ENOLINK   121
+#   define GNULIB_defined_ENOLINK 1
+#  endif
+
+#  ifndef EPROTO
+#   define EPROTO    134
+#   define GNULIB_defined_EPROTO 1
+#  endif
+
+#  ifndef EBADMSG
+#   define EBADMSG   104
+#   define GNULIB_defined_EBADMSG 1
+#  endif
+
+#  ifndef EOVERFLOW
+#   define EOVERFLOW 132
+#   define GNULIB_defined_EOVERFLOW 1
+#  endif
+
+#  ifndef ENOTSUP
+#   define ENOTSUP   129
+#   define GNULIB_defined_ENOTSUP 1
+#  endif
+
+#  ifndef ENETRESET
+#   define ENETRESET 117
+#   define GNULIB_defined_ENETRESET 1
+#  endif
+
+#  ifndef ECONNABORTED
+#   define ECONNABORTED 106
+#   define GNULIB_defined_ECONNABORTED 1
+#  endif
+
+#  ifndef ECANCELED
+#   define ECANCELED 105
+#   define GNULIB_defined_ECANCELED 1
+#  endif
+
+#  ifndef EINPROGRESS
+#   define EINPROGRESS     112
+#   define EALREADY        103
+#   define ENOTSOCK        128
+#   define EDESTADDRREQ    109
+#   define EMSGSIZE        115
+#   define EPROTOTYPE      136
+#   define ENOPROTOOPT     123
+#   define EPROTONOSUPPORT 135
+#   define EOPNOTSUPP      130
+#   define EAFNOSUPPORT    102
+#   define EADDRINUSE      100
+#   define EADDRNOTAVAIL   101
+#   define ENETDOWN        116
+#   define ENETUNREACH     118
+#   define ECONNRESET      108
+#   define ENOBUFS         119
+#   define EISCONN         113
+#   define ENOTCONN        126
+#   define ETIMEDOUT       138
+#   define ECONNREFUSED    107
+#   define ELOOP           114
+#   define EHOSTUNREACH    110
+#   define EWOULDBLOCK     140
+#   define ETXTBSY         139
+#   define ENODATA         120  /* not required by POSIX */
+#   define ENOSR           124  /* not required by POSIX */
+#   define ENOSTR          125  /* not required by POSIX */
+#   define ENOTRECOVERABLE 127  /* not required by POSIX */
+#   define EOWNERDEAD      133  /* not required by POSIX */
+#   define ETIME           137  /* not required by POSIX */
+#   define EOTHER          131  /* not required by POSIX */
+#   define GNULIB_defined_ESOCK 1
+#  endif
 
 /* These are intentionally the same values as the WSA* error numbers, defined
    in <winsock2.h>.  */
-#  define EINPROGRESS     10036
-#  define EALREADY        10037
-#  define ENOTSOCK        10038
-#  define EDESTADDRREQ    10039
-#  define EMSGSIZE        10040
-#  define EPROTOTYPE      10041
-#  define ENOPROTOOPT     10042
-#  define EPROTONOSUPPORT 10043
 #  define ESOCKTNOSUPPORT 10044  /* not required by POSIX */
-#  define EOPNOTSUPP      10045
 #  define EPFNOSUPPORT    10046  /* not required by POSIX */
-#  define EAFNOSUPPORT    10047
-#  define EADDRINUSE      10048
-#  define EADDRNOTAVAIL   10049
-#  define ENETDOWN        10050
-#  define ENETUNREACH     10051
-#  define ENETRESET       10052
-#  define ECONNABORTED    10053
-#  define ECONNRESET      10054
-#  define ENOBUFS         10055
-#  define EISCONN         10056
-#  define ENOTCONN        10057
 #  define ESHUTDOWN       10058  /* not required by POSIX */
 #  define ETOOMANYREFS    10059  /* not required by POSIX */
-#  define ETIMEDOUT       10060
-#  define ECONNREFUSED    10061
-#  define ELOOP           10062
 #  define EHOSTDOWN       10064  /* not required by POSIX */
-#  define EHOSTUNREACH    10065
 #  define EPROCLIM        10067  /* not required by POSIX */
 #  define EUSERS          10068  /* not required by POSIX */
 #  define EDQUOT          10069
 #  define ESTALE          10070
 #  define EREMOTE         10071  /* not required by POSIX */
-#  define GNULIB_defined_ESOCK 1
+#  define GNULIB_defined_EWINSOCK 1
 
 # endif
 
diff --git a/gl/error.c b/gl/error.c
index 7482baa..5ebe8bf 100644
--- a/gl/error.c
+++ b/gl/error.c
@@ -92,6 +92,8 @@ extern void __error_at_line (int status, int errnum, const 
char *file_name,
 /* Get declarations of the Win32 API functions.  */
 #  define WIN32_LEAN_AND_MEAN
 #  include <windows.h>
+/* Get _get_osfhandle.  */
+#  include "msvc-nothrow.h"
 # endif
 
 /* The gnulib override of fcntl is not needed in this file.  */
diff --git a/gl/float.c b/gl/float.c
index c453d6d..b05b40c 100644
--- a/gl/float.c
+++ b/gl/float.c
@@ -20,7 +20,7 @@
 /* Specification.  */
 #include <float.h>
 
-#if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 
106) && defined __GNUC__
+#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined 
__linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__
 const union gl_long_double_union gl_LDBL_MAX =
   { { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL } };
 #elif defined __i386__
diff --git a/gl/float.in.h b/gl/float.in.h
index 57b7bc9..d5b2258 100644
--- a/gl/float.in.h
+++ b/gl/float.in.h
@@ -109,7 +109,8 @@ extern const union gl_long_double_union gl_LDBL_MAX;
 #endif
 
 /* On AIX 7.1 with gcc 4.2, the values of LDBL_MIN_EXP, LDBL_MIN, LDBL_MAX are
-   wrong.  */
+   wrong.
+   On Linux/PowerPC with gcc 4.4, the value of LDBL_MAX is wrong.  */
 #if (defined _ARCH_PPC || defined _POWER) && defined _AIX && (LDBL_MANT_DIG == 
106) && defined __GNUC__
 # undef LDBL_MIN_EXP
 # define LDBL_MIN_EXP DBL_MIN_EXP
@@ -117,6 +118,8 @@ extern const union gl_long_double_union gl_LDBL_MAX;
 # define LDBL_MIN_10_EXP DBL_MIN_10_EXP
 # undef LDBL_MIN
 # define LDBL_MIN 2.22507385850720138309023271733240406422e-308L /* DBL_MIN = 
2^-1022 */
+#endif
+#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined 
__linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__
 # undef LDBL_MAX
 /* LDBL_MAX is represented as { 0x7FEFFFFF, 0xFFFFFFFF, 0x7C8FFFFF, 0xFFFFFFFF 
}.
    It is not easy to define:
@@ -170,5 +173,16 @@ extern const union gl_long_double_union gl_LDBL_MAX;
 # endif
 #endif
 
+#if @REPLACE_ITOLD@
+/* Pull in a function that fixes the 'int' to 'long double' conversion
+   of glibc 2.7.  */
+extern
+# ifdef __cplusplus
+"C"
+# endif
+void _Qp_itoq (long double *, int);
+static void (*_gl_float_fix_itold) (long double *, int) = _Qp_itoq;
+#endif
+
 #endif /* address@hidden@_FLOAT_H */
 #endif /* address@hidden@_FLOAT_H */
diff --git a/gl/frexp.c b/gl/frexp.c
index 0f0d41a..26bdec9 100644
--- a/gl/frexp.c
+++ b/gl/frexp.c
@@ -17,7 +17,9 @@
 /* Written by Paolo Bonzini <address@hidden>, 2003, and
    Bruno Haible <address@hidden>, 2007.  */
 
-#include <config.h>
+#if ! defined USE_LONG_DOUBLE
+# include <config.h>
+#endif
 
 /* Specification.  */
 #include <math.h>
diff --git a/gl/frexpl.c b/gl/frexpl.c
index ea635a4..c468937 100644
--- a/gl/frexpl.c
+++ b/gl/frexpl.c
@@ -14,5 +14,22 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#define USE_LONG_DOUBLE
-#include "frexp.c"
+#include <config.h>
+
+#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+
+/* Specification.  */
+# include <math.h>
+
+long double
+frexpl (long double x, int *expptr)
+{
+  return frexp (x, expptr);
+}
+
+#else
+
+# define USE_LONG_DOUBLE
+# include "frexp.c"
+
+#endif
diff --git a/gl/fstat.c b/gl/fstat.c
new file mode 100644
index 0000000..db5b17c
--- /dev/null
+++ b/gl/fstat.c
@@ -0,0 +1,82 @@
+/* fstat() replacement.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* If the user's config.h happens to include <sys/stat.h>, let it include only
+   the system's <sys/stat.h> here, so that orig_fstat doesn't recurse to
+   rpl_fstat.  */
+#define __need_system_sys_stat_h
+#include <config.h>
+
+/* Get the original definition of fstat.  It might be defined as a macro.  */
+#include <sys/types.h>
+#include <sys/stat.h>
+#undef __need_system_sys_stat_h
+
+static inline int
+orig_fstat (int fd, struct stat *buf)
+{
+  return fstat (fd, buf);
+}
+
+/* Specification.  */
+/* Write "sys/stat.h" here, not <sys/stat.h>, otherwise OSF/1 5.1 DTK cc
+   eliminates this include because of the preliminary #include <sys/stat.h>
+   above.  */
+#include "sys/stat.h"
+
+#include <errno.h>
+#include <unistd.h>
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# include "msvc-inval.h"
+#endif
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static inline int
+fstat_nothrow (int fd, struct stat *buf)
+{
+  int result;
+
+  TRY_MSVC_INVAL
+    {
+      result = orig_fstat (fd, buf);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = -1;
+      errno = EBADF;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#else
+# define fstat_nothrow orig_fstat
+#endif
+
+int
+rpl_fstat (int fd, struct stat *buf)
+{
+#if REPLACE_FCHDIR && REPLACE_OPEN_DIRECTORY
+  /* Handle the case when rpl_open() used a dummy file descriptor to work
+     around an open() that can't normally visit directories.  */
+  const char *name = _gl_directory_name (fd);
+  if (name != NULL)
+    return stat (name, buf);
+#endif
+
+  return fstat_nothrow (fd, buf);
+}
diff --git a/gl/getpeername.c b/gl/getpeername.c
new file mode 100644
index 0000000..abe5a40
--- /dev/null
+++ b/gl/getpeername.c
@@ -0,0 +1,49 @@
+/* getpeername.c --- wrappers for Windows getpeername function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef getpeername
+
+int
+rpl_getpeername (int fd, struct sockaddr *addr, socklen_t *addrlen)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = getpeername (sock, addr, addrlen);
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
+}
diff --git a/gl/gettext.h b/gl/gettext.h
index 88d9867..792e506 100644
--- a/gl/gettext.h
+++ b/gl/gettext.h
@@ -178,4 +178,109 @@ npgettext_aux (const char *domain,
     return translation;
 }
 
+/* The same thing extended for non-constant arguments.  Here MSGCTXT and MSGID
+   can be arbitrary expressions.  But for string literals these macros are
+   less efficient than those above.  */
+
+#include <string.h>
+
+#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
+  (((__GNUC__ >= 3 || __GNUG__ >= 2) && !defined __STRICT_ANSI__) \
+   /* || __STDC_VERSION__ >= 199901L */ )
+
+#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+#include <stdlib.h>
+#endif
+
+#define pgettext_expr(Msgctxt, Msgid) \
+  dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
+#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
+  dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static const char *
+dcpgettext_expr (const char *domain,
+                 const char *msgctxt, const char *msgid,
+                 int category)
+{
+  size_t msgctxt_len = strlen (msgctxt) + 1;
+  size_t msgid_len = strlen (msgid) + 1;
+  const char *translation;
+#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+  char msg_ctxt_id[msgctxt_len + msgid_len];
+#else
+  char buf[1024];
+  char *msg_ctxt_id =
+    (msgctxt_len + msgid_len <= sizeof (buf)
+     ? buf
+     : (char *) malloc (msgctxt_len + msgid_len));
+  if (msg_ctxt_id != NULL)
+#endif
+    {
+      memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
+      msg_ctxt_id[msgctxt_len - 1] = '\004';
+      memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
+      translation = dcgettext (domain, msg_ctxt_id, category);
+#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+      if (msg_ctxt_id != buf)
+        free (msg_ctxt_id);
+#endif
+      if (translation != msg_ctxt_id)
+        return translation;
+    }
+  return msgid;
+}
+
+#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
+  dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
+#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
+  dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
+
+#ifdef __GNUC__
+__inline
+#else
+#ifdef __cplusplus
+inline
+#endif
+#endif
+static const char *
+dcnpgettext_expr (const char *domain,
+                  const char *msgctxt, const char *msgid,
+                  const char *msgid_plural, unsigned long int n,
+                  int category)
+{
+  size_t msgctxt_len = strlen (msgctxt) + 1;
+  size_t msgid_len = strlen (msgid) + 1;
+  const char *translation;
+#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+  char msg_ctxt_id[msgctxt_len + msgid_len];
+#else
+  char buf[1024];
+  char *msg_ctxt_id =
+    (msgctxt_len + msgid_len <= sizeof (buf)
+     ? buf
+     : (char *) malloc (msgctxt_len + msgid_len));
+  if (msg_ctxt_id != NULL)
+#endif
+    {
+      memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
+      msg_ctxt_id[msgctxt_len - 1] = '\004';
+      memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
+      translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, 
category);
+#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
+      if (msg_ctxt_id != buf)
+        free (msg_ctxt_id);
+#endif
+      if (!(translation == msg_ctxt_id || translation == msgid_plural))
+        return translation;
+    }
+  return (n == 1 ? msgid : msgid_plural);
+}
+
 #endif /* _LIBGETTEXT_H */
diff --git a/gl/hmac-md5.c b/gl/hmac-md5.c
deleted file mode 100644
index 2c0edf5..0000000
--- a/gl/hmac-md5.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/* hmac-md5.c -- hashed message authentication codes
-   Copyright (C) 2005-2006, 2009-2011 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Simon Josefsson.  */
-
-#include <config.h>
-
-#include "hmac.h"
-
-#include "memxor.h"
-#include "md5.h"
-
-#include <string.h>
-
-#define IPAD 0x36
-#define OPAD 0x5c
-
-int
-hmac_md5 (const void *key, size_t keylen,
-          const void *in, size_t inlen, void *resbuf)
-{
-  struct md5_ctx inner;
-  struct md5_ctx outer;
-  char optkeybuf[16];
-  char block[64];
-  char innerhash[16];
-
-  /* Reduce the key's size, so that it becomes <= 64 bytes large.  */
-
-  if (keylen > 64)
-    {
-      struct md5_ctx keyhash;
-
-      md5_init_ctx (&keyhash);
-      md5_process_bytes (key, keylen, &keyhash);
-      md5_finish_ctx (&keyhash, optkeybuf);
-
-      key = optkeybuf;
-      keylen = 16;
-    }
-
-  /* Compute INNERHASH from KEY and IN.  */
-
-  md5_init_ctx (&inner);
-
-  memset (block, IPAD, sizeof (block));
-  gl_memxor (block, key, keylen);
-
-  md5_process_block (block, 64, &inner);
-  md5_process_bytes (in, inlen, &inner);
-
-  md5_finish_ctx (&inner, innerhash);
-
-  /* Compute result from KEY and INNERHASH.  */
-
-  md5_init_ctx (&outer);
-
-  memset (block, OPAD, sizeof (block));
-  gl_memxor (block, key, keylen);
-
-  md5_process_block (block, 64, &outer);
-  md5_process_bytes (innerhash, 16, &outer);
-
-  md5_finish_ctx (&outer, resbuf);
-
-  return 0;
-}
diff --git a/gl/hmac.h b/gl/hmac.h
deleted file mode 100644
index 67cb72e..0000000
--- a/gl/hmac.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* hmac.h -- hashed message authentication codes
-   Copyright (C) 2005, 2009-2011 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Simon Josefsson.  */
-
-#ifndef HMAC_H
-# define HMAC_H 1
-
-#include <stddef.h>
-
-/* Compute Hashed Message Authentication Code with MD5, as described
-   in RFC 2104, over BUFFER data of BUFLEN bytes using the KEY of
-   KEYLEN bytes, writing the output to pre-allocated 16 byte minimum
-   RESBUF buffer.  Return 0 on success.  */
-int
-hmac_md5 (const void *key, size_t keylen,
-          const void *buffer, size_t buflen, void *resbuf);
-
-/* Compute Hashed Message Authentication Code with SHA-1, over BUFFER
-   data of BUFLEN bytes using the KEY of KEYLEN bytes, writing the
-   output to pre-allocated 20 byte minimum RESBUF buffer.  Return 0 on
-   success.  */
-int
-hmac_sha1 (const void *key, size_t keylen,
-           const void *in, size_t inlen, void *resbuf);
-
-#endif /* HMAC_H */
diff --git a/gl/inet_ntop.c b/gl/inet_ntop.c
new file mode 100644
index 0000000..c11b1e0
--- /dev/null
+++ b/gl/inet_ntop.c
@@ -0,0 +1,249 @@
+/* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form
+
+   Copyright (C) 2005-2006, 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/*
+ * Copyright (c) 1996-1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#include <config.h>
+
+/* Specification.  */
+#include <arpa/inet.h>
+
+#if HAVE_DECL_INET_NTOP
+
+# undef inet_ntop
+
+const char *
+rpl_inet_ntop (int af, const void *restrict src,
+               char *restrict dst, socklen_t cnt)
+{
+  return inet_ntop (af, src, dst, cnt);
+}
+
+#else
+
+# include <stdio.h>
+# include <string.h>
+# include <errno.h>
+
+# define NS_IN6ADDRSZ 16
+# define NS_INT16SZ 2
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+typedef int verify_int_size[4 <= sizeof (int) ? 1 : -1];
+
+static const char *inet_ntop4 (const unsigned char *src, char *dst, socklen_t 
size);
+# if HAVE_IPV6
+static const char *inet_ntop6 (const unsigned char *src, char *dst, socklen_t 
size);
+# endif
+
+
+/* char *
+ * inet_ntop(af, src, dst, size)
+ *      convert a network format address to presentation format.
+ * return:
+ *      pointer to presentation format address (`dst'), or NULL (see errno).
+ * author:
+ *      Paul Vixie, 1996.
+ */
+const char *
+inet_ntop (int af, const void *restrict src,
+           char *restrict dst, socklen_t cnt)
+{
+  switch (af)
+    {
+# if HAVE_IPV4
+    case AF_INET:
+      return (inet_ntop4 (src, dst, cnt));
+# endif
+
+# if HAVE_IPV6
+    case AF_INET6:
+      return (inet_ntop6 (src, dst, cnt));
+# endif
+
+    default:
+      errno = EAFNOSUPPORT;
+      return (NULL);
+    }
+  /* NOTREACHED */
+}
+
+/* const char *
+ * inet_ntop4(src, dst, size)
+ *      format an IPv4 address
+ * return:
+ *      `dst' (as a const)
+ * notes:
+ *      (1) uses no statics
+ *      (2) takes a u_char* not an in_addr as input
+ * author:
+ *      Paul Vixie, 1996.
+ */
+static const char *
+inet_ntop4 (const unsigned char *src, char *dst, socklen_t size)
+{
+  char tmp[sizeof "255.255.255.255"];
+  int len;
+
+  len = sprintf (tmp, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]);
+  if (len < 0)
+    return NULL;
+
+  if (len > size)
+    {
+      errno = ENOSPC;
+      return NULL;
+    }
+
+  return strcpy (dst, tmp);
+}
+
+# if HAVE_IPV6
+
+/* const char *
+ * inet_ntop6(src, dst, size)
+ *      convert IPv6 binary address into presentation (printable) format
+ * author:
+ *      Paul Vixie, 1996.
+ */
+static const char *
+inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
+{
+  /*
+   * Note that int32_t and int16_t need only be "at least" large enough
+   * to contain a value of the specified size.  On some systems, like
+   * Crays, there is no such thing as an integer variable with 16 bits.
+   * Keep this in mind if you think this function should have been coded
+   * to use pointer overlays.  All the world's not a VAX.
+   */
+  char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
+  struct
+  {
+    int base, len;
+  } best, cur;
+  unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
+  int i;
+
+  /*
+   * Preprocess:
+   *      Copy the input (bytewise) array into a wordwise array.
+   *      Find the longest run of 0x00's in src[] for :: shorthanding.
+   */
+  memset (words, '\0', sizeof words);
+  for (i = 0; i < NS_IN6ADDRSZ; i += 2)
+    words[i / 2] = (src[i] << 8) | src[i + 1];
+  best.base = -1;
+  cur.base = -1;
+  for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
+    {
+      if (words[i] == 0)
+        {
+          if (cur.base == -1)
+            cur.base = i, cur.len = 1;
+          else
+            cur.len++;
+        }
+      else
+        {
+          if (cur.base != -1)
+            {
+              if (best.base == -1 || cur.len > best.len)
+                best = cur;
+              cur.base = -1;
+            }
+        }
+    }
+  if (cur.base != -1)
+    {
+      if (best.base == -1 || cur.len > best.len)
+        best = cur;
+    }
+  if (best.base != -1 && best.len < 2)
+    best.base = -1;
+
+  /*
+   * Format the result.
+   */
+  tp = tmp;
+  for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
+    {
+      /* Are we inside the best run of 0x00's? */
+      if (best.base != -1 && i >= best.base && i < (best.base + best.len))
+        {
+          if (i == best.base)
+            *tp++ = ':';
+          continue;
+        }
+      /* Are we following an initial run of 0x00s or any real hex? */
+      if (i != 0)
+        *tp++ = ':';
+      /* Is this address an encapsulated IPv4? */
+      if (i == 6 && best.base == 0 &&
+          (best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
+        {
+          if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp)))
+            return (NULL);
+          tp += strlen (tp);
+          break;
+        }
+      {
+        int len = sprintf (tp, "%x", words[i]);
+        if (len < 0)
+          return NULL;
+        tp += len;
+      }
+    }
+  /* Was it a trailing run of 0x00's? */
+  if (best.base != -1 && (best.base + best.len) ==
+      (NS_IN6ADDRSZ / NS_INT16SZ))
+    *tp++ = ':';
+  *tp++ = '\0';
+
+  /*
+   * Check for overflow, copy, and we're done.
+   */
+  if ((socklen_t) (tp - tmp) > size)
+    {
+      errno = ENOSPC;
+      return NULL;
+    }
+
+  return strcpy (dst, tmp);
+}
+
+# endif
+
+#endif
diff --git a/gl/inet_pton.c b/gl/inet_pton.c
new file mode 100644
index 0000000..cb1a872
--- /dev/null
+++ b/gl/inet_pton.c
@@ -0,0 +1,268 @@
+/* inet_pton.c -- convert IPv4 and IPv6 addresses from text to binary form
+
+   Copyright (C) 2006, 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/*
+ * Copyright (c) 1996,1999 by Internet Software Consortium.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+ * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+ * SOFTWARE.
+ */
+
+#include <config.h>
+
+/* Specification.  */
+#include <arpa/inet.h>
+
+#if HAVE_DECL_INET_PTON
+
+# undef inet_pton
+
+int
+rpl_inet_pton (int af, const char *restrict src, void *restrict dst)
+{
+  return inet_pton (af, src, dst);
+}
+
+#else
+
+# include <c-ctype.h>
+# include <string.h>
+# include <errno.h>
+
+# define NS_INADDRSZ 4
+# define NS_IN6ADDRSZ 16
+# define NS_INT16SZ 2
+
+/*
+ * WARNING: Don't even consider trying to compile this on a system where
+ * sizeof(int) < 4.  sizeof(int) > 4 is fine; all the world's not a VAX.
+ */
+
+static int inet_pton4 (const char *src, unsigned char *dst);
+# if HAVE_IPV6
+static int inet_pton6 (const char *src, unsigned char *dst);
+# endif
+
+/* int
+ * inet_pton(af, src, dst)
+ *      convert from presentation format (which usually means ASCII printable)
+ *      to network format (which is usually some kind of binary format).
+ * return:
+ *      1 if the address was valid for the specified address family
+ *      0 if the address wasn't valid (`dst' is untouched in this case)
+ *      -1 if some other error occurred (`dst' is untouched in this case, too)
+ * author:
+ *      Paul Vixie, 1996.
+ */
+int
+inet_pton (int af, const char *restrict src, void *restrict dst)
+{
+  switch (af)
+    {
+    case AF_INET:
+      return (inet_pton4 (src, dst));
+
+# if HAVE_IPV6
+    case AF_INET6:
+      return (inet_pton6 (src, dst));
+# endif
+
+    default:
+      errno = EAFNOSUPPORT;
+      return (-1);
+    }
+  /* NOTREACHED */
+}
+
+/* int
+ * inet_pton4(src, dst)
+ *      like inet_aton() but without all the hexadecimal, octal (with the
+ *      exception of 0) and shorthand.
+ * return:
+ *      1 if `src' is a valid dotted quad, else 0.
+ * notice:
+ *      does not touch `dst' unless it's returning 1.
+ * author:
+ *      Paul Vixie, 1996.
+ */
+static int
+inet_pton4 (const char *restrict src, unsigned char *restrict dst)
+{
+  int saw_digit, octets, ch;
+  unsigned char tmp[NS_INADDRSZ], *tp;
+
+  saw_digit = 0;
+  octets = 0;
+  *(tp = tmp) = 0;
+  while ((ch = *src++) != '\0')
+    {
+
+      if (ch >= '0' && ch <= '9')
+        {
+          unsigned new = *tp * 10 + (ch - '0');
+
+          if (saw_digit && *tp == 0)
+            return (0);
+          if (new > 255)
+            return (0);
+          *tp = new;
+          if (!saw_digit)
+            {
+              if (++octets > 4)
+                return (0);
+              saw_digit = 1;
+            }
+        }
+      else if (ch == '.' && saw_digit)
+        {
+          if (octets == 4)
+            return (0);
+          *++tp = 0;
+          saw_digit = 0;
+        }
+      else
+        return (0);
+    }
+  if (octets < 4)
+    return (0);
+  memcpy (dst, tmp, NS_INADDRSZ);
+  return (1);
+}
+
+# if HAVE_IPV6
+
+/* int
+ * inet_pton6(src, dst)
+ *      convert presentation level address to network order binary form.
+ * return:
+ *      1 if `src' is a valid [RFC1884 2.2] address, else 0.
+ * notice:
+ *      (1) does not touch `dst' unless it's returning 1.
+ *      (2) :: in a full address is silently ignored.
+ * credit:
+ *      inspired by Mark Andrews.
+ * author:
+ *      Paul Vixie, 1996.
+ */
+static int
+inet_pton6 (const char *restrict src, unsigned char *restrict dst)
+{
+  static const char xdigits[] = "0123456789abcdef";
+  unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
+  const char *curtok;
+  int ch, saw_xdigit;
+  unsigned val;
+
+  tp = memset (tmp, '\0', NS_IN6ADDRSZ);
+  endp = tp + NS_IN6ADDRSZ;
+  colonp = NULL;
+  /* Leading :: requires some special handling. */
+  if (*src == ':')
+    if (*++src != ':')
+      return (0);
+  curtok = src;
+  saw_xdigit = 0;
+  val = 0;
+  while ((ch = c_tolower (*src++)) != '\0')
+    {
+      const char *pch;
+
+      pch = strchr (xdigits, ch);
+      if (pch != NULL)
+        {
+          val <<= 4;
+          val |= (pch - xdigits);
+          if (val > 0xffff)
+            return (0);
+          saw_xdigit = 1;
+          continue;
+        }
+      if (ch == ':')
+        {
+          curtok = src;
+          if (!saw_xdigit)
+            {
+              if (colonp)
+                return (0);
+              colonp = tp;
+              continue;
+            }
+          else if (*src == '\0')
+            {
+              return (0);
+            }
+          if (tp + NS_INT16SZ > endp)
+            return (0);
+          *tp++ = (u_char) (val >> 8) & 0xff;
+          *tp++ = (u_char) val & 0xff;
+          saw_xdigit = 0;
+          val = 0;
+          continue;
+        }
+      if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
+          inet_pton4 (curtok, tp) > 0)
+        {
+          tp += NS_INADDRSZ;
+          saw_xdigit = 0;
+          break;                /* '\0' was seen by inet_pton4(). */
+        }
+      return (0);
+    }
+  if (saw_xdigit)
+    {
+      if (tp + NS_INT16SZ > endp)
+        return (0);
+      *tp++ = (u_char) (val >> 8) & 0xff;
+      *tp++ = (u_char) val & 0xff;
+    }
+  if (colonp != NULL)
+    {
+      /*
+       * Since some memmove()'s erroneously fail to handle
+       * overlapping regions, we'll do the shift by hand.
+       */
+      const int n = tp - colonp;
+      int i;
+
+      if (tp == endp)
+        return (0);
+      for (i = 1; i <= n; i++)
+        {
+          endp[-i] = colonp[n - i];
+          colonp[n - i] = 0;
+        }
+      tp = endp;
+    }
+  if (tp != endp)
+    return (0);
+  memcpy (dst, tmp, NS_IN6ADDRSZ);
+  return (1);
+}
+
+# endif
+
+#endif
diff --git a/gl/isnan.c b/gl/isnan.c
index f26dc1e..1d0754c 100644
--- a/gl/isnan.c
+++ b/gl/isnan.c
@@ -83,7 +83,7 @@ int
 FUNC (DOUBLE x)
 {
 #ifdef KNOWN_EXPBIT0_LOCATION
-# if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || 
(defined __x86_64__ || defined __amd64__) || (defined __i386 || defined 
__i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+# if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || 
(defined __x86_64__ || defined __amd64__) || (defined __i386 || defined 
__i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && 
!HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
   /* Special CPU dependent code is needed to treat bit patterns outside the
      IEEE 754 specification (such as Pseudo-NaNs, Pseudo-Infinities,
      Pseudo-Zeroes, Unnormalized Numbers, and Pseudo-Denormals) as NaNs.
@@ -157,7 +157,7 @@ FUNC (DOUBLE x)
      the signaling NaNs, handle only the quiet NaNs.  */
   if (x == x)
     {
-# if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || 
(defined __x86_64__ || defined __amd64__) || (defined __i386 || defined 
__i386__ || defined _I386 || defined _M_IX86 || defined _X86_))
+# if defined USE_LONG_DOUBLE && ((defined __ia64 && LDBL_MANT_DIG == 64) || 
(defined __x86_64__ || defined __amd64__) || (defined __i386 || defined 
__i386__ || defined _I386 || defined _M_IX86 || defined _X86_)) && 
!HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
       /* Detect any special bit patterns that pass ==; see comment above.  */
       memory_double m1;
       memory_double m2;
diff --git a/gl/itold.c b/gl/itold.c
new file mode 100644
index 0000000..0236f33
--- /dev/null
+++ b/gl/itold.c
@@ -0,0 +1,28 @@
+/* Replacement for 'int' to 'long double' conversion routine.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+   Written by Bruno Haible <address@hidden>, 2011.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <float.h>
+
+void
+_Qp_itoq (long double *result, int a)
+{
+  /* Convert from 'int' to 'double', then from 'double' to 'long double'.  */
+  *result = (double) a;
+}
diff --git a/gl/listen.c b/gl/listen.c
new file mode 100644
index 0000000..b7d070e
--- /dev/null
+++ b/gl/listen.c
@@ -0,0 +1,49 @@
+/* listen.c --- wrappers for Windows listen function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef listen
+
+int
+rpl_listen (int fd, int backlog)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = listen (sock, backlog);
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
+}
diff --git a/gl/lseek.c b/gl/lseek.c
index 8339044..8c9834f 100644
--- a/gl/lseek.c
+++ b/gl/lseek.c
@@ -24,6 +24,8 @@
 /* Windows platforms.  */
 /* Get GetFileType.  */
 # include <windows.h>
+/* Get _get_osfhandle.  */
+# include "msvc-nothrow.h"
 #else
 # include <sys/stat.h>
 #endif
diff --git a/gl/m4/arpa_inet_h.m4 b/gl/m4/arpa_inet_h.m4
new file mode 100644
index 0000000..1df7401
--- /dev/null
+++ b/gl/m4/arpa_inet_h.m4
@@ -0,0 +1,57 @@
+# arpa_inet_h.m4 serial 13
+dnl Copyright (C) 2006, 2008-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Simon Josefsson and Bruno Haible
+
+AC_DEFUN([gl_HEADER_ARPA_INET],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
+
+  AC_CHECK_HEADERS_ONCE([arpa/inet.h])
+  if test $ac_cv_header_arpa_inet_h = yes; then
+    HAVE_ARPA_INET_H=1
+  else
+    HAVE_ARPA_INET_H=0
+  fi
+  AC_SUBST([HAVE_ARPA_INET_H])
+  dnl <arpa/inet.h> is always overridden, because of GNULIB_POSIXCHECK.
+  gl_CHECK_NEXT_HEADERS([arpa/inet.h])
+
+  AC_REQUIRE([gl_FEATURES_H])
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[
+/* On some systems, this header is not self-consistent.  */
+#if !(defined __GLIBC__ || defined __UCLIBC__)
+# include <sys/socket.h>
+#endif
+#ifdef __TANDEM
+# include <netdb.h>
+#endif
+#include <arpa/inet.h>
+    ]], [inet_ntop inet_pton])
+])
+
+AC_DEFUN([gl_ARPA_INET_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+])
+
+AC_DEFUN([gl_ARPA_INET_H_DEFAULTS],
+[
+  GNULIB_INET_NTOP=0;     AC_SUBST([GNULIB_INET_NTOP])
+  GNULIB_INET_PTON=0;     AC_SUBST([GNULIB_INET_PTON])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_DECL_INET_NTOP=1;  AC_SUBST([HAVE_DECL_INET_NTOP])
+  HAVE_DECL_INET_PTON=1;  AC_SUBST([HAVE_DECL_INET_PTON])
+  REPLACE_INET_NTOP=0;    AC_SUBST([REPLACE_INET_NTOP])
+  REPLACE_INET_PTON=0;    AC_SUBST([REPLACE_INET_PTON])
+])
diff --git a/gl/m4/close.m4 b/gl/m4/close.m4
new file mode 100644
index 0000000..f860a32
--- /dev/null
+++ b/gl/m4/close.m4
@@ -0,0 +1,33 @@
+# close.m4 serial 8
+dnl Copyright (C) 2008-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_CLOSE],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_REQUIRE([gl_MSVC_INVAL])
+  if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
+    REPLACE_CLOSE=1
+  fi
+  m4_ifdef([gl_PREREQ_SYS_H_WINSOCK2], [
+    gl_PREREQ_SYS_H_WINSOCK2
+    if test $UNISTD_H_HAVE_WINSOCK2_H = 1; then
+      dnl Even if the 'socket' module is not used here, another part of the
+      dnl application may use it and pass file descriptors that refer to
+      dnl sockets to the close() function. So enable the support for sockets.
+      REPLACE_CLOSE=1
+    fi
+  ])
+  dnl Replace close() for supporting the gnulib-defined fchdir() function,
+  dnl to keep fchdir's bookkeeping up-to-date.
+  m4_ifdef([gl_FUNC_FCHDIR], [
+    if test $REPLACE_CLOSE = 0; then
+      gl_TEST_FCHDIR
+      if test $HAVE_FCHDIR = 0; then
+        REPLACE_CLOSE=1
+      fi
+    fi
+  ])
+])
diff --git a/gl/m4/dup2.m4 b/gl/m4/dup2.m4
index 5c2cc96..cd9d254 100644
--- a/gl/m4/dup2.m4
+++ b/gl/m4/dup2.m4
@@ -1,4 +1,4 @@
-#serial 14
+#serial 16
 dnl Copyright (C) 2002, 2005, 2007, 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -71,3 +71,6 @@ AC_DEFUN([gl_FUNC_DUP2],
     fi
   ])
 ])
+
+# Prerequisites of lib/dup2.c.
+AC_DEFUN([gl_PREREQ_DUP2], [])
diff --git a/gl/m4/fdopen.m4 b/gl/m4/fdopen.m4
new file mode 100644
index 0000000..8cae2fc
--- /dev/null
+++ b/gl/m4/fdopen.m4
@@ -0,0 +1,49 @@
+# fdopen.m4 serial 2
+dnl Copyright (C) 2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FDOPEN],
+[
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_MSVC_INVAL])
+  if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
+    REPLACE_FDOPEN=1
+  else
+    dnl Test whether fdopen() sets errno when it fails due to a bad fd 
argument.
+    AC_CACHE_CHECK([whether fdopen sets errno], [gl_cv_func_fdopen_works],
+      [
+        AC_RUN_IFELSE(
+          [AC_LANG_SOURCE([[
+#include <stdio.h>
+#include <errno.h>
+int
+main (void)
+{
+  FILE *fp;
+  errno = 0;
+  fp = fdopen (-1, "r");
+  if (fp != NULL)
+    return 1;
+  if (errno == 0)
+    return 2;
+  return 0;
+}]])],
+          [gl_cv_func_fdopen_works=yes],
+          [gl_cv_func_fdopen_works=no],
+          [case "$host_os" in
+             mingw*) gl_cv_func_fdopen_works="guessing no" ;;
+             *)      gl_cv_func_fdopen_works="guessing yes" ;;
+           esac
+          ])
+      ])
+    case "$gl_cv_func_fdopen_works" in
+      *no) REPLACE_FDOPEN=1 ;;
+    esac
+  fi
+])
+
+dnl Prerequisites of lib/fdopen.c.
+AC_DEFUN([gl_PREREQ_FDOPEN], [])
diff --git a/gl/m4/float_h.m4 b/gl/m4/float_h.m4
index 261f1ac..0420e06 100644
--- a/gl/m4/float_h.m4
+++ b/gl/m4/float_h.m4
@@ -1,4 +1,4 @@
-# float_h.m4 serial 7
+# float_h.m4 serial 9
 dnl Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -33,17 +33,66 @@ changequote([,])dnl
           ;;
       esac
       ;;
+    linux*)
+      case "$host_cpu" in
+        powerpc*)
+          FLOAT_H=float.h
+          ;;
+      esac
+      ;;
   esac
   case "$host_os" in
-    aix* | freebsd*)
+    aix* | freebsd* | linux*)
       if test -n "$FLOAT_H"; then
         REPLACE_FLOAT_LDBL=1
       fi
       ;;
   esac
+
+  dnl Test against glibc-2.7 Linux/SPARC64 bug.
+  REPLACE_ITOLD=0
+  AC_CACHE_CHECK([whether conversion from 'int' to 'long double' works],
+    [gl_cv_func_itold_works],
+    [
+      AC_RUN_IFELSE(
+        [AC_LANG_SOURCE([[
+int i = -1;
+volatile long double ld;
+int main ()
+{
+  ld += i * 1.0L;
+  if (ld > 0)
+    return 1;
+  return 0;
+}]])],
+        [gl_cv_func_itold_works=yes],
+        [gl_cv_func_itold_works=no],
+        [case "$host" in
+           sparc*-*-linux*)
+             AC_EGREP_CPP([yes],
+               [#if defined __LP64__ || defined __arch64__
+                yes
+                #endif],
+               [gl_cv_func_itold_works="guessing no"],
+               [gl_cv_func_itold_works="guessing yes"])
+             ;;
+           *) gl_cv_func_itold_works="guessing yes" ;;
+         esac
+        ])
+    ])
+  case "$gl_cv_func_itold_works" in
+    *no)
+      REPLACE_ITOLD=1
+      dnl We add the workaround to <float.h> but also to <math.h>,
+      dnl to increase the chances that the fix function gets pulled in.
+      FLOAT_H=float.h
+      ;;
+  esac
+
   if test -n "$FLOAT_H"; then
     gl_NEXT_HEADERS([float.h])
   fi
   AC_SUBST([FLOAT_H])
   AM_CONDITIONAL([GL_GENERATE_FLOAT_H], [test -n "$FLOAT_H"])
+  AC_SUBST([REPLACE_ITOLD])
 ])
diff --git a/gl/m4/frexp.m4 b/gl/m4/frexp.m4
index f2048f3..b0bdd10 100644
--- a/gl/m4/frexp.m4
+++ b/gl/m4/frexp.m4
@@ -1,4 +1,4 @@
-# frexp.m4 serial 12
+# frexp.m4 serial 13
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -93,6 +93,7 @@ AC_DEFUN([gl_FUNC_FREXP_WORKS],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CHECK_FUNCS_ONCE([alarm])
   AC_CACHE_CHECK([whether frexp works], [gl_cv_func_frexp_works],
     [
       AC_RUN_IFELSE(
@@ -100,6 +101,9 @@ AC_DEFUN([gl_FUNC_FREXP_WORKS],
 #include <float.h>
 #include <math.h>
 #include <string.h>
+#if HAVE_ALARM
+# include <unistd.h>
+#endif
 /* HP cc on HP-UX 10.20 has a bug with the constant expression -0.0.
    ICC 10.0 has a bug when optimizing the expression -zero.
    The expression -DBL_MIN * DBL_MIN does not work when cross-compiling
@@ -120,6 +124,11 @@ int main()
   int i;
   volatile double x;
   double zero = 0.0;
+#if HAVE_ALARM
+  /* NeXTstep 3.3 frexp() runs into an endless loop when called on an infinite
+     number.  Let the test fail in this case.  */
+  alarm (5);
+#endif
   /* Test on denormalized numbers.  */
   for (i = 1, x = 1.0; i >= DBL_MIN_EXP; i--, x *= 0.5)
     ;
diff --git a/gl/m4/frexpl.m4 b/gl/m4/frexpl.m4
index e9f9964..91f2a35 100644
--- a/gl/m4/frexpl.m4
+++ b/gl/m4/frexpl.m4
@@ -1,4 +1,4 @@
-# frexpl.m4 serial 17
+# frexpl.m4 serial 18
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -7,6 +7,7 @@ dnl with or without modifications, as long as this notice is 
preserved.
 AC_DEFUN([gl_FUNC_FREXPL],
 [
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
   dnl Check whether it's declared.
   dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
   AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
@@ -40,7 +41,7 @@ AC_DEFUN([gl_FUNC_FREXPL],
       LIBS="$save_LIBS"
       case "$gl_cv_func_frexpl_works" in
         *yes) gl_func_frexpl=yes ;;
-        *)    gl_func_frexpl=no; REPLACE_FREXPL=1; FREXPL_LIBM= ;;
+        *)    gl_func_frexpl=no; REPLACE_FREXPL=1 ;;
       esac
     else
       gl_func_frexpl=no
@@ -50,12 +51,22 @@ AC_DEFUN([gl_FUNC_FREXPL],
         [Define if the frexpl() function is available.])
     fi
   fi
+  if test $HAVE_DECL_FREXPL = 0 || test $gl_func_frexpl = no; then
+    dnl Find libraries needed to link lib/frexpl.c.
+    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
+      AC_REQUIRE([gl_FUNC_FREXP])
+      FREXPL_LIBM="$FREXP_LIBM"
+    else
+      FREXPL_LIBM=
+    fi
+  fi
   AC_SUBST([FREXPL_LIBM])
 ])
 
 AC_DEFUN([gl_FUNC_FREXPL_NO_LIBM],
 [
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
   dnl Check whether it's declared.
   dnl MacOS X 10.3 has frexpl() in libc but doesn't declare it in <math.h>.
   AC_CHECK_DECL([frexpl], , [HAVE_DECL_FREXPL=0], [[#include <math.h>]])
diff --git a/gl/m4/fstat.m4 b/gl/m4/fstat.m4
new file mode 100644
index 0000000..0daea88
--- /dev/null
+++ b/gl/m4/fstat.m4
@@ -0,0 +1,28 @@
+# fstat.m4 serial 1
+dnl Copyright (C) 2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FSTAT],
+[
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
+  AC_REQUIRE([gl_MSVC_INVAL])
+  if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
+    REPLACE_FSTAT=1
+  fi
+  dnl Replace fstat() for supporting the gnulib-defined open() on directories.
+  m4_ifdef([gl_FUNC_FCHDIR], [
+    gl_TEST_FCHDIR
+    if test $HAVE_FCHDIR = 0 \
+       && test "$gl_cv_func_open_directory_works" != yes; then
+      REPLACE_FSTAT=1
+    fi
+  ])
+])
+
+# Prerequisites of lib/fstat.c.
+AC_DEFUN([gl_PREREQ_FSTAT],
+[
+  AC_REQUIRE([AC_C_INLINE])
+])
diff --git a/gl/m4/ftruncate.m4 b/gl/m4/ftruncate.m4
new file mode 100644
index 0000000..4a47ba4
--- /dev/null
+++ b/gl/m4/ftruncate.m4
@@ -0,0 +1,24 @@
+# serial 18
+
+# See if we need to emulate a missing ftruncate function using chsize.
+
+# Copyright (C) 2000-2001, 2003-2007, 2009-2011 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FTRUNCATE],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+  AC_CHECK_FUNCS_ONCE([ftruncate])
+  if test $ac_cv_func_ftruncate = no; then
+    HAVE_FTRUNCATE=0
+  fi
+])
+
+# Prerequisites of lib/ftruncate.c.
+AC_DEFUN([gl_PREREQ_FTRUNCATE],
+[
+  AC_REQUIRE([AC_C_INLINE])
+  AC_CHECK_FUNCS([chsize])
+])
diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4
index 950e51b..409b70b 100644
--- a/gl/m4/gnulib-cache.m4
+++ b/gl/m4/gnulib-cache.m4
@@ -1,9 +1,21 @@
 # Copyright (C) 2002-2011 Free Software Foundation, Inc.
 #
-# This file is free software, distributed under the terms of the GNU
-# General Public License.  As a special exception to the GNU General
-# Public License, this file may be distributed as part of a program
-# that contains a configuration script generated by Autoconf, under
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this file.  If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License,
+# this file may be distributed as part of a program that
+# contains a configuration script generated by Autoconf, under
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
@@ -15,18 +27,20 @@
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu 
--source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests 
--aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lseek-tests 
--no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files alloca 
alphasort argp byteswap c-ctype crypto/hmac-md5 crypto/md5 error extensions 
func getpass getsubopt gettext gettime havelib lib-msvc-compat 
lib-symbol-versions maintainer-makefile manywarnings memmem-simple minmax netdb 
netinet_in progname read-file scandir snprintf sockets socklen stdint strcase 
strverscmp sys_socket sys_stat time_r timespec u64 unistd valgrind-tests 
vasprintf version-etc version-etc-fsf vfprintf-posix vprintf-posix vsnprintf 
warnings
+#   gnulib-tool --import --dir=. --local-dir=gl/override --lib=libgnu 
--source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests 
--aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lseek-tests 
--no-conditional-dependencies --libtool --macro-prefix=gl --no-vc-files accept 
alloca alphasort argp bind byteswap c-ctype close connect error extensions func 
getpass getsubopt gettext gettime havelib inet_ntop inet_pton lib-msvc-compat 
lib-symbol-versions listen maintainer-makefile manywarnings memmem-simple 
minmax netdb netinet_in pmccabe2html progname read-file recv recvfrom scandir 
select send sendto setsockopt shutdown snprintf socket sockets socklen stdint 
strcase strverscmp sys_socket sys_stat time_r timespec u64 unistd 
valgrind-tests vasprintf version-etc version-etc-fsf vfprintf-posix 
vprintf-posix vsnprintf warnings
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([gl/override])
 gl_MODULES([
+  accept
   alloca
   alphasort
   argp
+  bind
   byteswap
   c-ctype
-  crypto/hmac-md5
-  crypto/md5
+  close
+  connect
   error
   extensions
   func
@@ -35,18 +49,30 @@ gl_MODULES([
   gettext
   gettime
   havelib
+  inet_ntop
+  inet_pton
   lib-msvc-compat
   lib-symbol-versions
+  listen
   maintainer-makefile
   manywarnings
   memmem-simple
   minmax
   netdb
   netinet_in
+  pmccabe2html
   progname
   read-file
+  recv
+  recvfrom
   scandir
+  select
+  send
+  sendto
+  setsockopt
+  shutdown
   snprintf
+  socket
   sockets
   socklen
   stdint
diff --git a/gl/m4/gnulib-common.m4 b/gl/m4/gnulib-common.m4
index 8fc448f..7d83299 100644
--- a/gl/m4/gnulib-common.m4
+++ b/gl/m4/gnulib-common.m4
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 30
+# gnulib-common.m4 serial 31
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -211,6 +211,29 @@ m4_ifndef([AS_VAR_IF],
 [m4_define([AS_VAR_IF],
 [AS_IF([test x"AS_VAR_GET([$1])" = x""$2], [$3], [$4])])])
 
+# gl_PROG_CC_C99
+# Modifies the value of the shell variable CC in an attempt to make $CC
+# understand ISO C99 source code.
+# This is like AC_PROG_CC_C99, except that
+# - AC_PROG_CC_C99 did not exist in Autoconf versions < 2.60,
+# - AC_PROG_CC_C99 does not mix well with AC_PROG_CC_STDC
+#   <http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00367.html>,
+#   but many more packages use AC_PROG_CC_STDC than AC_PROG_CC_C99
+#   <http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00441.html>.
+# Remaining problems:
+# - When AC_PROG_CC_STDC is invoked twice, it adds the C99 enabling options
+#   to CC twice
+#   <http://lists.gnu.org/archive/html/bug-gnulib/2011-09/msg00431.html>.
+# - AC_PROG_CC_STDC is likely to change when C1X is an ISO standard.
+AC_DEFUN([gl_PROG_CC_C99],
+[
+  dnl Change that version number to the minimum Autoconf version that supports
+  dnl mixing AC_PROG_CC_C99 calls with AC_PROG_CC_STDC calls.
+  m4_version_prereq([9.0],
+    [AC_REQUIRE([AC_PROG_CC_C99])],
+    [AC_REQUIRE([AC_PROG_CC_STDC])])
+])
+
 # gl_PROG_AR_RANLIB
 # Determines the values for AR, ARFLAGS, RANLIB that fit with the compiler.
 # The user can set the variables AR, ARFLAGS, RANLIB if he wants to override
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index 0660eb7..fe23cdf 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -1,10 +1,22 @@
 # DO NOT EDIT! GENERATED AUTOMATICALLY!
 # Copyright (C) 2002-2011 Free Software Foundation, Inc.
 #
-# This file is free software, distributed under the terms of the GNU
-# General Public License.  As a special exception to the GNU General
-# Public License, this file may be distributed as part of a program
-# that contains a configuration script generated by Autoconf, under
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this file.  If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License,
+# this file may be distributed as part of a program that
+# contains a configuration script generated by Autoconf, under
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
@@ -26,25 +38,30 @@ AC_DEFUN([gl_EARLY],
   m4_pattern_allow([^gl_LIBOBJS$])dnl a variable
   m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable
   AC_REQUIRE([gl_PROG_AR_RANLIB])
-  # Code from module alignof:
+  # Code from module accept:
+  # Code from module accept-tests:
   # Code from module alloca:
   # Code from module alloca-opt:
   # Code from module alloca-opt-tests:
   # Code from module alphasort:
   # Code from module argp:
   # Code from module argp-tests:
+  # Code from module arpa_inet:
+  # Code from module arpa_inet-tests:
   # Code from module binary-io:
   # Code from module binary-io-tests:
+  # Code from module bind:
+  # Code from module bind-tests:
   # Code from module byteswap:
   # Code from module byteswap-tests:
   # Code from module c-ctype:
   # Code from module c-ctype-tests:
   # Code from module clock-time:
+  # Code from module close:
+  # Code from module close-tests:
   # Code from module closedir:
-  # Code from module crypto/hmac-md5:
-  # Code from module crypto/hmac-md5-tests:
-  # Code from module crypto/md5:
-  # Code from module crypto/md5-tests:
+  # Code from module connect:
+  # Code from module connect-tests:
   # Code from module dirent:
   # Code from module dirent-tests:
   # Code from module dirname-lgpl:
@@ -62,6 +79,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module fcntl-h:
   # Code from module fcntl-h-tests:
   # Code from module fd-hook:
+  # Code from module fdopen:
   # Code from module fdopen-tests:
   # Code from module fgetc-tests:
   # Code from module filename:
@@ -70,6 +88,8 @@ AC_DEFUN([gl_EARLY],
   # Code from module fpieee:
   AC_REQUIRE([gl_FP_IEEE])
   # Code from module fpucw:
+  # Code from module fputc-tests:
+  # Code from module fread-tests:
   # Code from module frexp-nolibm:
   # Code from module frexp-nolibm-tests:
   # Code from module frexpl-nolibm:
@@ -81,14 +101,18 @@ AC_DEFUN([gl_EARLY],
   # Code from module fseeko-tests:
   # Code from module fseterr:
   # Code from module fseterr-tests:
+  # Code from module fstat:
   # Code from module fstat-tests:
   # Code from module ftell:
   # Code from module ftell-tests:
   # Code from module ftello:
   AC_REQUIRE([AC_FUNC_FSEEKO])
   # Code from module ftello-tests:
+  # Code from module ftruncate:
+  # Code from module ftruncate-tests:
   # Code from module func:
   # Code from module func-tests:
+  # Code from module fwrite-tests:
   # Code from module getcwd-lgpl:
   # Code from module getcwd-lgpl-tests:
   # Code from module getdelim:
@@ -100,6 +124,8 @@ AC_DEFUN([gl_EARLY],
   # Code from module getopt-posix-tests:
   # Code from module getpagesize:
   # Code from module getpass:
+  # Code from module getpeername:
+  # Code from module getpeername-tests:
   # Code from module getsubopt:
   # Code from module gettext:
   # Code from module gettext-h:
@@ -111,11 +137,17 @@ AC_DEFUN([gl_EARLY],
   # Code from module ignore-value:
   # Code from module ignore-value-tests:
   # Code from module include_next:
+  # Code from module inet_ntop:
+  # Code from module inet_ntop-tests:
+  # Code from module inet_pton:
+  # Code from module inet_pton-tests:
   # Code from module intprops:
   # Code from module intprops-tests:
   # Code from module inttypes:
   # Code from module inttypes-incomplete:
   # Code from module inttypes-tests:
+  # Code from module ioctl:
+  # Code from module ioctl-tests:
   # Code from module isnand-nolibm:
   # Code from module isnand-nolibm-tests:
   # Code from module isnanf-nolibm:
@@ -126,6 +158,10 @@ AC_DEFUN([gl_EARLY],
   AC_REQUIRE([AC_SYS_LARGEFILE])
   # Code from module lib-msvc-compat:
   # Code from module lib-symbol-versions:
+  # Code from module listen:
+  # Code from module listen-tests:
+  # Code from module lock:
+  # Code from module lock-tests:
   # Code from module lseek:
   # Code from module lstat:
   # Code from module lstat-tests:
@@ -142,9 +178,9 @@ AC_DEFUN([gl_EARLY],
   # Code from module memchr-tests:
   # Code from module memmem-simple:
   # Code from module mempcpy:
-  # Code from module memxor:
   # Code from module minmax:
   # Code from module msvc-inval:
+  # Code from module msvc-nothrow:
   # Code from module multiarch:
   # Code from module netdb:
   # Code from module netdb-tests:
@@ -156,6 +192,11 @@ AC_DEFUN([gl_EARLY],
   # Code from module opendir:
   # Code from module pathmax:
   # Code from module pathmax-tests:
+  # Code from module perror:
+  # Code from module perror-tests:
+  # Code from module pipe-posix:
+  # Code from module pipe-posix-tests:
+  # Code from module pmccabe2html:
   # Code from module printf-frexp:
   # Code from module printf-frexp-tests:
   # Code from module printf-frexpl:
@@ -169,10 +210,26 @@ AC_DEFUN([gl_EARLY],
   # Code from module read-file-tests:
   # Code from module readdir:
   # Code from module realloc-posix:
+  # Code from module recv:
+  # Code from module recv-tests:
+  # Code from module recvfrom:
+  # Code from module recvfrom-tests:
   # Code from module same-inode:
   # Code from module scandir:
+  # Code from module select:
+  # Code from module select-tests:
+  # Code from module send:
+  # Code from module send-tests:
+  # Code from module sendto:
+  # Code from module sendto-tests:
   # Code from module setenv:
   # Code from module setenv-tests:
+  # Code from module setsockopt:
+  # Code from module setsockopt-tests:
+  # Code from module shutdown:
+  # Code from module shutdown-tests:
+  # Code from module signal-h:
+  # Code from module signal-h-tests:
   # Code from module signbit:
   # Code from module signbit-tests:
   # Code from module size_max:
@@ -184,6 +241,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module snippet/warn-on-use:
   # Code from module snprintf:
   # Code from module snprintf-tests:
+  # Code from module socket:
   # Code from module socketlib:
   # Code from module sockets:
   # Code from module sockets-tests:
@@ -191,12 +249,14 @@ AC_DEFUN([gl_EARLY],
   # Code from module ssize_t:
   # Code from module stat:
   # Code from module stat-tests:
+  # Code from module stdalign:
+  # Code from module stdalign-tests:
   # Code from module stdarg:
   dnl Some compilers (e.g., AIX 5.3 cc) need to be in c99 mode
   dnl for the builtin va_copy to work.  With Autoconf 2.60 or later,
-  dnl AC_PROG_CC_STDC arranges for this.  With older Autoconf AC_PROG_CC_STDC
+  dnl gl_PROG_CC_C99 arranges for this.  With older Autoconf gl_PROG_CC_C99
   dnl shouldn't hurt, though installers are on their own to set c99 mode.
-  AC_REQUIRE([AC_PROG_CC_STDC])
+  gl_PROG_CC_C99
   # Code from module stdbool:
   # Code from module stdbool-tests:
   # Code from module stddef:
@@ -214,6 +274,8 @@ AC_DEFUN([gl_EARLY],
   # Code from module strerror:
   # Code from module strerror-override:
   # Code from module strerror-tests:
+  # Code from module strerror_r-posix:
+  # Code from module strerror_r-posix-tests:
   # Code from module string:
   # Code from module string-tests:
   # Code from module strings:
@@ -225,6 +287,10 @@ AC_DEFUN([gl_EARLY],
   # Code from module strverscmp-tests:
   # Code from module symlink:
   # Code from module symlink-tests:
+  # Code from module sys_ioctl:
+  # Code from module sys_ioctl-tests:
+  # Code from module sys_select:
+  # Code from module sys_select-tests:
   # Code from module sys_socket:
   # Code from module sys_socket-tests:
   # Code from module sys_stat:
@@ -237,6 +303,10 @@ AC_DEFUN([gl_EARLY],
   # Code from module sys_uio-tests:
   # Code from module sysexits:
   # Code from module sysexits-tests:
+  # Code from module thread:
+  # Code from module thread-tests:
+  # Code from module threadlib:
+  gl_THREADLIB_EARLY
   # Code from module time:
   # Code from module time-tests:
   # Code from module time_r:
@@ -270,6 +340,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module wchar:
   # Code from module wchar-tests:
   # Code from module xsize:
+  # Code from module yield:
 ])
 
 # This macro should be invoked from ./configure.ac, in the section
@@ -286,6 +357,11 @@ AC_DEFUN([gl_INIT],
   m4_pushdef([gl_LIBSOURCES_DIR], [])
   gl_COMMON
   gl_source_base='gl'
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([accept])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([accept])
 changequote(,)dnl
 LTALLOCA=`echo "$ALLOCA" | sed -e 's/\.[^.]* /.lo /g;s/\.[^.]*$/.lo/'`
 changequote([, ])dnl
@@ -301,14 +377,30 @@ gl_ARGP
 m4_ifdef([AM_XGETTEXT_OPTION],
   [AM_][XGETTEXT_OPTION([--flag=argp_error:2:c-format])
    AM_][XGETTEXT_OPTION([--flag=argp_failure:4:c-format])])
+gl_HEADER_ARPA_INET
+AC_PROG_MKDIR_P
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([bind])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([bind])
 gl_BYTESWAP
 gl_CLOCK_TIME
+gl_FUNC_CLOSE
+if test $REPLACE_CLOSE = 1; then
+  AC_LIBOBJ([close])
+fi
+gl_UNISTD_MODULE_INDICATOR([close])
 gl_FUNC_CLOSEDIR
 if test $HAVE_CLOSEDIR = 0 || test $REPLACE_CLOSEDIR = 1; then
   AC_LIBOBJ([closedir])
 fi
 gl_DIRENT_MODULE_INDICATOR([closedir])
-gl_MD5
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([connect])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([connect])
 gl_DIRENT_H
 gl_DIRNAME_LGPL
 gl_DOUBLE_SLASH_ROOT
@@ -325,6 +417,9 @@ gl_FLOAT_H
 if test $REPLACE_FLOAT_LDBL = 1; then
   AC_LIBOBJ([float])
 fi
+if test $REPLACE_ITOLD = 1; then
+  AC_LIBOBJ([itold])
+fi
 gl_FUNC_FREXP_NO_LIBM
 if test $gl_func_frexp_no_libm != yes; then
   AC_LIBOBJ([frexp])
@@ -345,6 +440,12 @@ if test $HAVE_FSEEKO = 0 || test $REPLACE_FSEEKO = 1; then
   AC_LIBOBJ([fseeko])
 fi
 gl_STDIO_MODULE_INDICATOR([fseeko])
+gl_FUNC_FSTAT
+if test $REPLACE_FSTAT = 1; then
+  AC_LIBOBJ([fstat])
+  gl_PREREQ_FSTAT
+fi
+gl_SYS_STAT_MODULE_INDICATOR([fstat])
 gl_FUNC_FTELL
 if test $REPLACE_FTELL = 1; then
   AC_LIBOBJ([ftell])
@@ -386,6 +487,11 @@ if test $HAVE_GETPASS = 0; then
   AC_LIBOBJ([getpass])
   gl_PREREQ_GETPASS
 fi
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([getpeername])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([getpeername])
 gl_FUNC_GETSUBOPT
 if test $HAVE_GETSUBOPT = 0; then
   AC_LIBOBJ([getsubopt])
@@ -413,6 +519,18 @@ m4_if(m4_version_compare([2.61a.100],
         m4_defn([m4_PACKAGE_VERSION])), [1], [],
       [AC_CONFIG_LINKS([$GNUmakefile:$GNUmakefile], [],
         [GNUmakefile=$GNUmakefile])])
+gl_FUNC_INET_NTOP
+if test $HAVE_INET_NTOP = 0 || test $REPLACE_INET_NTOP = 1; then
+  AC_LIBOBJ([inet_ntop])
+  gl_PREREQ_INET_NTOP
+fi
+gl_ARPA_INET_MODULE_INDICATOR([inet_ntop])
+gl_FUNC_INET_PTON
+if test $HAVE_INET_PTON = 0 || test $REPLACE_INET_NTOP = 1; then
+  AC_LIBOBJ([inet_pton])
+  gl_PREREQ_INET_PTON
+fi
+gl_ARPA_INET_MODULE_INDICATOR([inet_pton])
 gl_FUNC_ISNAND_NO_LIBM
 if test $gl_func_isnand_no_libm != yes; then
   AC_LIBOBJ([isnand])
@@ -430,6 +548,11 @@ if test $gl_func_isnanl_no_libm != yes; then
 fi
 gl_LD_OUTPUT_DEF
 gl_LD_VERSION_SCRIPT
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([listen])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([listen])
 gl_FUNC_LSEEK
 if test $REPLACE_LSEEK = 1; then
   AC_LIBOBJ([lseek])
@@ -465,8 +588,15 @@ if test $HAVE_MEMPCPY = 0; then
   gl_PREREQ_MEMPCPY
 fi
 gl_STRING_MODULE_INDICATOR([mempcpy])
-gl_MEMXOR
 gl_MINMAX
+gl_MSVC_INVAL
+if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
+  AC_LIBOBJ([msvc-inval])
+fi
+gl_MSVC_NOTHROW
+if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
+  AC_LIBOBJ([msvc-nothrow])
+fi
 gl_MULTIARCH
 gl_HEADER_NETDB
 gl_HEADER_NETINET_IN
@@ -476,6 +606,7 @@ if test $HAVE_OPENDIR = 0 || test $REPLACE_OPENDIR = 1; then
   AC_LIBOBJ([opendir])
 fi
 gl_DIRENT_MODULE_INDICATOR([opendir])
+AC_PATH_PROG([PMCCABE], [pmccabe], [false])
 gl_FUNC_PRINTF_FREXP
 gl_FUNC_PRINTF_FREXPL
 m4_divert_text([INIT_PREPARE], [gl_printf_safe=yes])
@@ -498,12 +629,48 @@ if test $REPLACE_REALLOC = 1; then
   AC_LIBOBJ([realloc])
 fi
 gl_STDLIB_MODULE_INDICATOR([realloc-posix])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([recv])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([recv])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([recvfrom])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([recvfrom])
 gl_FUNC_SCANDIR
 if test $HAVE_SCANDIR = 0; then
   AC_LIBOBJ([scandir])
   gl_PREREQ_SCANDIR
 fi
 gl_DIRENT_MODULE_INDICATOR([scandir])
+gl_FUNC_SELECT
+if test $REPLACE_SELECT = 1; then
+  AC_LIBOBJ([select])
+fi
+gl_SYS_SELECT_MODULE_INDICATOR([select])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([send])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([send])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([sendto])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([sendto])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([setsockopt])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([setsockopt])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([shutdown])
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([shutdown])
+gl_SIGNAL_H
 gl_SIGNBIT
 if test $REPLACE_SIGNBIT = 1; then
   AC_LIBOBJ([signbitf])
@@ -520,10 +687,25 @@ gl_UNISTD_MODULE_INDICATOR([sleep])
 gl_FUNC_SNPRINTF
 gl_STDIO_MODULE_INDICATOR([snprintf])
 gl_MODULE_INDICATOR([snprintf])
+AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  AC_LIBOBJ([socket])
+fi
+# When this module is used, sockets may actually occur as file descriptors,
+# hence it is worth warning if the modules 'close' and 'ioctl' are not used.
+m4_ifdef([gl_UNISTD_H_DEFAULTS], [AC_REQUIRE([gl_UNISTD_H_DEFAULTS])])
+m4_ifdef([gl_SYS_IOCTL_H_DEFAULTS], [AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])])
+AC_REQUIRE([gl_PREREQ_SYS_H_WINSOCK2])
+if test "$ac_cv_header_winsock2_h" = yes; then
+  UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=1
+  SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=1
+fi
+gl_SYS_SOCKET_MODULE_INDICATOR([socket])
 gl_SOCKETLIB
 gl_SOCKETS
 gl_TYPE_SOCKLEN_T
 gt_TYPE_SSIZE_T
+gl_STDALIGN_H
 gl_STDARG_H
 AM_STDBOOL_H
 gl_STDDEF_H
@@ -582,6 +764,8 @@ if test $HAVE_STRVERSCMP = 0; then
   gl_PREREQ_STRVERSCMP
 fi
 gl_STRING_MODULE_INDICATOR([strverscmp])
+gl_HEADER_SYS_SELECT
+AC_PROG_MKDIR_P
 gl_HEADER_SYS_SOCKET
 AC_PROG_MKDIR_P
 gl_HEADER_SYS_STAT_H
@@ -669,15 +853,28 @@ changequote([, ])dnl
 gl_FUNC_DUP2
 if test $HAVE_DUP2 = 0 || test $REPLACE_DUP2 = 1; then
   AC_LIBOBJ([dup2])
+  gl_PREREQ_DUP2
 fi
 gl_UNISTD_MODULE_INDICATOR([dup2])
 gl_ENVIRON
 gl_UNISTD_MODULE_INDICATOR([environ])
 gl_FCNTL_H
+gl_FUNC_FDOPEN
+if test $REPLACE_FDOPEN = 1; then
+  AC_LIBOBJ([fdopen])
+  gl_PREREQ_FDOPEN
+fi
+gl_STDIO_MODULE_INDICATOR([fdopen])
 gl_FUNC_UNGETC_WORKS
 gl_FUNC_UNGETC_WORKS
 gl_FUNC_UNGETC_WORKS
 gl_FUNC_UNGETC_WORKS
+gl_FUNC_FTRUNCATE
+if test $HAVE_FTRUNCATE = 0; then
+  AC_LIBOBJ([ftruncate])
+  gl_PREREQ_FTRUNCATE
+fi
+gl_UNISTD_MODULE_INDICATOR([ftruncate])
 gl_FUNC_GETCWD_LGPL
 if test $REPLACE_GETCWD = 1; then
   AC_LIBOBJ([getcwd-lgpl])
@@ -689,11 +886,20 @@ if test $REPLACE_GETPAGESIZE = 1; then
 fi
 gl_UNISTD_MODULE_INDICATOR([getpagesize])
 AC_REQUIRE([AC_C_INLINE])
+AC_C_BIGENDIAN
+AC_C_BIGENDIAN
 gl_INTTYPES_H
 gl_INTTYPES_INCOMPLETE
+gl_FUNC_IOCTL
+if test $HAVE_IOCTL = 0 || test $REPLACE_IOCTL = 1; then
+  AC_LIBOBJ([ioctl])
+fi
+gl_SYS_IOCTL_MODULE_INDICATOR([ioctl])
 gl_DOUBLE_EXPONENT_LOCATION
 gl_FLOAT_EXPONENT_LOCATION
 gl_LONG_DOUBLE_EXPONENT_LOCATION
+AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
+gl_LOCK
 gl_FUNC_LSTAT
 if test $REPLACE_LSTAT = 1; then
   AC_LIBOBJ([lstat])
@@ -705,10 +911,6 @@ dnl Check for prerequisites for memory fence checks.
 gl_FUNC_MMAP_ANON
 AC_CHECK_HEADERS_ONCE([sys/mman.h])
 AC_CHECK_FUNCS_ONCE([mprotect])
-gl_MSVC_INVAL
-if test $HAVE_MSVC_INVALID_PARAMETER_HANDLER = 1; then
-  AC_LIBOBJ([msvc-inval])
-fi
 gl_FUNC_OPEN
 if test $REPLACE_OPEN = 1; then
   AC_LIBOBJ([open])
@@ -716,6 +918,16 @@ if test $REPLACE_OPEN = 1; then
 fi
 gl_FCNTL_MODULE_INDICATOR([open])
 gl_PATHMAX
+gl_FUNC_PERROR
+if test $REPLACE_PERROR = 1; then
+  AC_LIBOBJ([perror])
+fi
+gl_STRING_MODULE_INDICATOR([perror])
+gl_FUNC_PIPE
+if test $HAVE_PIPE = 0; then
+  AC_LIBOBJ([pipe])
+fi
+gl_UNISTD_MODULE_INDICATOR([pipe])
 gl_FUNC_PUTENV
 if test $REPLACE_PUTENV = 1; then
   AC_LIBOBJ([putenv])
@@ -725,6 +937,7 @@ dnl Check for prerequisites for memory fence checks.
 gl_FUNC_MMAP_ANON
 AC_CHECK_HEADERS_ONCE([sys/mman.h])
 AC_CHECK_FUNCS_ONCE([mprotect])
+AC_CHECK_HEADERS_ONCE([sys/wait.h])
 gl_FUNC_SETENV
 if test $HAVE_SETENV = 0 || test $REPLACE_SETENV = 1; then
   AC_LIBOBJ([setenv])
@@ -742,6 +955,12 @@ fi
 gl_SYS_STAT_MODULE_INDICATOR([stat])
 gt_TYPE_WCHAR_T
 gt_TYPE_WINT_T
+gl_FUNC_STRERROR_R
+if test $HAVE_DECL_STRERROR_R = 0 || test $REPLACE_STRERROR_R = 1; then
+  AC_LIBOBJ([strerror_r])
+  gl_PREREQ_STRERROR_R
+fi
+gl_STRING_MODULE_INDICATOR([strerror_r])
 dnl Check for prerequisites for memory fence checks.
 gl_FUNC_MMAP_ANON
 AC_CHECK_HEADERS_ONCE([sys/mman.h])
@@ -751,7 +970,11 @@ if test $HAVE_SYMLINK = 0 || test $REPLACE_SYMLINK = 1; 
then
   AC_LIBOBJ([symlink])
 fi
 gl_UNISTD_MODULE_INDICATOR([symlink])
+gl_SYS_IOCTL_H
+AC_PROG_MKDIR_P
 AC_CHECK_FUNCS_ONCE([shutdown])
+gl_THREAD
+gl_THREADLIB
 gl_FUNC_UNSETENV
 if test $HAVE_UNSETENV = 0 || test $REPLACE_UNSETENV = 1; then
   AC_LIBOBJ([unsetenv])
@@ -761,6 +984,7 @@ gl_STDLIB_MODULE_INDICATOR([unsetenv])
 gl_VALGRIND_TESTS
 abs_aux_dir=`cd "$ac_aux_dir"; pwd`
 AC_SUBST([abs_aux_dir])
+gl_YIELD
   m4_popdef([gl_MODULE_INDICATOR_CONDITION])
   m4_ifval(gltests_LIBSOURCES_LIST, [
     m4_syscmd([test ! -d ]m4_defn([gltests_LIBSOURCES_DIR])[ ||
@@ -854,13 +1078,15 @@ AC_DEFUN([gltests_LIBSOURCES], [
 # gnulib-tool and may be removed by future gnulib-tool invocations.
 AC_DEFUN([gl_FILE_LIST], [
   build-aux/config.rpath
+  build-aux/pmccabe.css
+  build-aux/pmccabe2html
   build-aux/snippet/_Noreturn.h
   build-aux/snippet/arg-nonnull.h
   build-aux/snippet/c++defs.h
   build-aux/snippet/warn-on-use.h
   build-aux/useless-if-before-free
   build-aux/vc-list-files
-  lib/alignof.h
+  lib/accept.c
   lib/alloca.c
   lib/alloca.in.h
   lib/alphasort.c
@@ -877,13 +1103,17 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/argp-pvh.c
   lib/argp-xinl.c
   lib/argp.h
+  lib/arpa_inet.in.h
   lib/asnprintf.c
   lib/asprintf.c
   lib/basename-lgpl.c
+  lib/bind.c
   lib/byteswap.in.h
   lib/c-ctype.c
   lib/c-ctype.h
+  lib/close.c
   lib/closedir.c
+  lib/connect.c
   lib/dirent-private.h
   lib/dirent.in.h
   lib/dirname-lgpl.c
@@ -905,6 +1135,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/fseeko.c
   lib/fseterr.c
   lib/fseterr.h
+  lib/fstat.c
   lib/ftell.c
   lib/ftello.c
   lib/getdelim.c
@@ -915,12 +1146,13 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/getopt_int.h
   lib/getpass.c
   lib/getpass.h
+  lib/getpeername.c
   lib/getsubopt.c
   lib/gettext.h
   lib/gettime.c
   lib/gettimeofday.c
-  lib/hmac-md5.c
-  lib/hmac.h
+  lib/inet_ntop.c
+  lib/inet_pton.c
   lib/intprops.h
   lib/isnan.c
   lib/isnand-nolibm.h
@@ -929,18 +1161,20 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/isnanf.c
   lib/isnanl-nolibm.h
   lib/isnanl.c
+  lib/itold.c
+  lib/listen.c
   lib/lseek.c
   lib/malloc.c
   lib/math.in.h
-  lib/md5.c
-  lib/md5.h
   lib/memchr.c
   lib/memchr.valgrind
   lib/memmem.c
   lib/mempcpy.c
-  lib/memxor.c
-  lib/memxor.h
   lib/minmax.h
+  lib/msvc-inval.c
+  lib/msvc-inval.h
+  lib/msvc-nothrow.c
+  lib/msvc-nothrow.h
   lib/netdb.in.h
   lib/netinet_in.in.h
   lib/opendir.c
@@ -960,15 +1194,25 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/read-file.h
   lib/readdir.c
   lib/realloc.c
+  lib/recv.c
+  lib/recvfrom.c
   lib/scandir.c
+  lib/select.c
+  lib/send.c
+  lib/sendto.c
+  lib/setsockopt.c
+  lib/shutdown.c
+  lib/signal.in.h
   lib/signbitd.c
   lib/signbitf.c
   lib/signbitl.c
   lib/size_max.h
   lib/sleep.c
   lib/snprintf.c
+  lib/socket.c
   lib/sockets.c
   lib/sockets.h
+  lib/stdalign.in.h
   lib/stdarg.in.h
   lib/stdbool.in.h
   lib/stddef.in.h
@@ -991,6 +1235,7 @@ AC_DEFUN([gl_FILE_LIST], [
   lib/strndup.c
   lib/strnlen.c
   lib/strverscmp.c
+  lib/sys_select.in.h
   lib/sys_socket.in.h
   lib/sys_stat.in.h
   lib/sys_time.in.h
@@ -1019,8 +1264,10 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/alloca.m4
   m4/alphasort.m4
   m4/argp.m4
+  m4/arpa_inet_h.m4
   m4/byteswap.m4
   m4/clock_time.m4
+  m4/close.m4
   m4/closedir.m4
   m4/codeset.m4
   m4/dirent_h.m4
@@ -1037,14 +1284,17 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/extensions.m4
   m4/fcntl-o.m4
   m4/fcntl_h.m4
+  m4/fdopen.m4
   m4/float_h.m4
   m4/fpieee.m4
   m4/frexp.m4
   m4/frexpl.m4
   m4/fseek.m4
   m4/fseeko.m4
+  m4/fstat.m4
   m4/ftell.m4
   m4/ftello.m4
+  m4/ftruncate.m4
   m4/func.m4
   m4/getcwd.m4
   m4/getdelim.m4
@@ -1061,6 +1311,8 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/gnulib-common.m4
   m4/iconv.m4
   m4/include_next.m4
+  m4/inet_ntop.m4
+  m4/inet_pton.m4
   m4/intdiv0.m4
   m4/intl.m4
   m4/intldir.m4
@@ -1070,6 +1322,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/inttypes-pri.m4
   m4/inttypes.m4
   m4/inttypes_h.m4
+  m4/ioctl.m4
   m4/isnand.m4
   m4/isnanf.m4
   m4/isnanl.m4
@@ -1089,15 +1342,14 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/malloca.m4
   m4/manywarnings.m4
   m4/math_h.m4
-  m4/md5.m4
   m4/memchr.m4
   m4/memmem.m4
   m4/mempcpy.m4
-  m4/memxor.m4
   m4/minmax.m4
   m4/mmap-anon.m4
   m4/mode_t.m4
   m4/msvc-inval.m4
+  m4/msvc-nothrow.m4
   m4/multiarch.m4
   m4/netdb_h.m4
   m4/netinet_in_h.m4
@@ -1106,6 +1358,8 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/open.m4
   m4/opendir.m4
   m4/pathmax.m4
+  m4/perror.m4
+  m4/pipe.m4
   m4/po.m4
   m4/printf-frexp.m4
   m4/printf-frexpl.m4
@@ -1118,7 +1372,9 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/readdir.m4
   m4/realloc.m4
   m4/scandir.m4
+  m4/select.m4
   m4/setenv.m4
+  m4/signal_h.m4
   m4/signbit.m4
   m4/size_max.m4
   m4/sleep.m4
@@ -1129,6 +1385,7 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/sockpfaf.m4
   m4/ssize_t.m4
   m4/stat.m4
+  m4/stdalign.m4
   m4/stdarg.m4
   m4/stdbool.m4
   m4/stddef_h.m4
@@ -1140,18 +1397,22 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/strchrnul.m4
   m4/strdup.m4
   m4/strerror.m4
+  m4/strerror_r.m4
   m4/string_h.m4
   m4/strings_h.m4
   m4/strndup.m4
   m4/strnlen.m4
   m4/strverscmp.m4
   m4/symlink.m4
+  m4/sys_ioctl_h.m4
+  m4/sys_select_h.m4
   m4/sys_socket_h.m4
   m4/sys_stat_h.m4
   m4/sys_time_h.m4
   m4/sys_types_h.m4
   m4/sys_uio_h.m4
   m4/sysexits.m4
+  m4/thread.m4
   m4/threadlib.m4
   m4/time_h.m4
   m4/time_r.m4
@@ -1173,19 +1434,25 @@ AC_DEFUN([gl_FILE_LIST], [
   m4/wchar_t.m4
   m4/wint_t.m4
   m4/xsize.m4
+  m4/yield.m4
   tests/infinity.h
   tests/init.sh
   tests/macros.h
   tests/minus-zero.h
   tests/nan.h
   tests/signature.h
+  tests/test-accept.c
   tests/test-alloca-opt.c
   tests/test-argp-2.sh
   tests/test-argp.c
+  tests/test-arpa_inet.c
   tests/test-binary-io.c
   tests/test-binary-io.sh
+  tests/test-bind.c
   tests/test-byteswap.c
   tests/test-c-ctype.c
+  tests/test-close.c
+  tests/test-connect.c
   tests/test-dirent.c
   tests/test-dup2.c
   tests/test-environ.c
@@ -1195,6 +1462,8 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-fgetc.c
   tests/test-float.c
   tests/test-fprintf-posix.h
+  tests/test-fputc.c
+  tests/test-fread.c
   tests/test-frexp.c
   tests/test-frexpl.c
   tests/test-fseek.c
@@ -1219,49 +1488,74 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-ftello3.c
   tests/test-ftello4.c
   tests/test-ftello4.sh
+  tests/test-ftruncate.c
+  tests/test-ftruncate.sh
   tests/test-func.c
+  tests/test-fwrite.c
   tests/test-getcwd-lgpl.c
   tests/test-getdelim.c
   tests/test-getline.c
   tests/test-getopt.c
   tests/test-getopt.h
   tests/test-getopt_long.h
+  tests/test-getpeername.c
   tests/test-gettimeofday.c
-  tests/test-hmac-md5.c
   tests/test-ignore-value.c
+  tests/test-inet_ntop.c
+  tests/test-inet_pton.c
   tests/test-intprops.c
   tests/test-inttypes.c
+  tests/test-ioctl.c
   tests/test-isnand-nolibm.c
   tests/test-isnand.h
   tests/test-isnanf-nolibm.c
   tests/test-isnanf.h
   tests/test-isnanl-nolibm.c
   tests/test-isnanl.h
+  tests/test-listen.c
+  tests/test-lock.c
   tests/test-lstat.c
   tests/test-lstat.h
   tests/test-malloc-gnu.c
   tests/test-malloca.c
   tests/test-math.c
-  tests/test-md5.c
   tests/test-memchr.c
   tests/test-netdb.c
   tests/test-netinet_in.c
   tests/test-open.c
   tests/test-open.h
   tests/test-pathmax.c
+  tests/test-perror.c
+  tests/test-perror.sh
+  tests/test-perror2.c
+  tests/test-pipe.c
   tests/test-printf-frexp.c
   tests/test-printf-frexpl.c
   tests/test-printf-posix.h
   tests/test-printf-posix.output
   tests/test-rawmemchr.c
   tests/test-read-file.c
+  tests/test-recv.c
+  tests/test-recvfrom.c
+  tests/test-select-fd.c
+  tests/test-select-in.sh
+  tests/test-select-out.sh
+  tests/test-select-stdin.c
+  tests/test-select.c
+  tests/test-select.h
+  tests/test-send.c
+  tests/test-sendto.c
   tests/test-setenv.c
+  tests/test-setsockopt.c
+  tests/test-shutdown.c
+  tests/test-signal-h.c
   tests/test-signbit.c
   tests/test-sleep.c
   tests/test-snprintf.c
   tests/test-sockets.c
   tests/test-stat.c
   tests/test-stat.h
+  tests/test-stdalign.c
   tests/test-stdbool.c
   tests/test-stddef.c
   tests/test-stdint.c
@@ -1269,12 +1563,15 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-stdlib.c
   tests/test-strchrnul.c
   tests/test-strerror.c
+  tests/test-strerror_r.c
   tests/test-string.c
   tests/test-strings.c
   tests/test-strnlen.c
   tests/test-strverscmp.c
   tests/test-symlink.c
   tests/test-symlink.h
+  tests/test-sys_ioctl.c
+  tests/test-sys_select.c
   tests/test-sys_socket.c
   tests/test-sys_stat.c
   tests/test-sys_time.c
@@ -1282,6 +1579,8 @@ AC_DEFUN([gl_FILE_LIST], [
   tests/test-sys_uio.c
   tests/test-sys_wait.h
   tests/test-sysexits.c
+  tests/test-thread_create.c
+  tests/test-thread_self.c
   tests/test-time.c
   tests/test-u64.c
   tests/test-unistd.c
@@ -1304,24 +1603,36 @@ AC_DEFUN([gl_FILE_LIST], [
   tests=lib/binary-io.h
   tests=lib/dup2.c
   tests=lib/fcntl.in.h
+  tests=lib/fdopen.c
+  tests=lib/ftruncate.c
   tests=lib/getcwd-lgpl.c
   tests=lib/getpagesize.c
+  tests=lib/glthread/lock.c
+  tests=lib/glthread/lock.h
+  tests=lib/glthread/thread.c
+  tests=lib/glthread/thread.h
+  tests=lib/glthread/threadlib.c
+  tests=lib/glthread/yield.h
   tests=lib/ignore-value.h
   tests=lib/inttypes.in.h
+  tests=lib/ioctl.c
   tests=lib/lstat.c
   tests=lib/malloca.c
   tests=lib/malloca.h
   tests=lib/malloca.valgrind
-  tests=lib/msvc-inval.c
-  tests=lib/msvc-inval.h
   tests=lib/open.c
   tests=lib/pathmax.h
+  tests=lib/perror.c
+  tests=lib/pipe.c
   tests=lib/putenv.c
   tests=lib/same-inode.h
   tests=lib/setenv.c
   tests=lib/stat.c
+  tests=lib/strerror_r.c
   tests=lib/symlink.c
+  tests=lib/sys_ioctl.in.h
   tests=lib/unsetenv.c
+  tests=lib/w32sock.h
   top/GNUmakefile
   top/maint.mk
 ])
diff --git a/gl/m4/include_next.m4 b/gl/m4/include_next.m4
index d5230ce..8a1fab6 100644
--- a/gl/m4/include_next.m4
+++ b/gl/m4/include_next.m4
@@ -1,4 +1,4 @@
-# include_next.m4 serial 22
+# include_next.m4 serial 23
 dnl Copyright (C) 2006-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -219,12 +219,17 @@ changequote(,)
                    gl_dirsep_regex='[/\\]'
                    ;;
                  *)
-                   gl_dirsep_regex='/'
+                   gl_dirsep_regex='\/'
                    ;;
                esac
+               dnl A sed expression that turns a string into a basic regular
+               dnl expression, for use within "/.../".
+               gl_make_literal_regex_sed='s,[]$^\\.*/[],\\&,g'
 changequote([,])
-               
gl_absolute_header_sed='\|'"${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[|{
-                   
s|.*"\(.*'"${gl_dirsep_regex}"']m4_defn([gl_HEADER_NAME])[\)".*|\1|
+               gl_header_literal_regex=`echo ']m4_defn([gl_HEADER_NAME])[' \
+                                        | sed -e "$gl_make_literal_regex_sed"`
+               
gl_absolute_header_sed="/${gl_dirsep_regex}${gl_header_literal_regex}/"'{
+                   
s/.*"\(.*'"${gl_dirsep_regex}${gl_header_literal_regex}"'\)".*/\1/
 changequote(,)dnl
                    s|^/[^/]|//&|
 changequote([,])dnl
diff --git a/gl/m4/inet_ntop.m4 b/gl/m4/inet_ntop.m4
new file mode 100644
index 0000000..4936fa3
--- /dev/null
+++ b/gl/m4/inet_ntop.m4
@@ -0,0 +1,68 @@
+# inet_ntop.m4 serial 19
+dnl Copyright (C) 2005-2006, 2008-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_INET_NTOP],
+[
+  AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
+
+  dnl Persuade Solaris <arpa/inet.h> to declare inet_ntop.
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+  AC_REQUIRE([AC_C_RESTRICT])
+
+  dnl Most platforms that provide inet_ntop define it in libc.
+  dnl Solaris 8..10 provide inet_ntop in libnsl instead.
+  dnl Solaris 2.6..7 provide inet_ntop in libresolv instead.
+  dnl Native Windows provides it in -lws2_32 instead, with a declaration in
+  dnl <ws2tcpip.h>, and it uses stdcall calling convention, not cdecl
+  dnl (hence we cannot use AC_CHECK_FUNCS, AC_SEARCH_LIBS to find it).
+  HAVE_INET_NTOP=1
+  INET_NTOP_LIB=
+  gl_PREREQ_SYS_H_WINSOCK2
+  if test $HAVE_WINSOCK2_H = 1; then
+    AC_CHECK_DECLS([inet_ntop],,, [[#include <ws2tcpip.h>]])
+    if test $ac_cv_have_decl_inet_ntop = yes; then
+      dnl It needs to be overridden, because the stdcall calling convention
+      dnl is not compliant with POSIX.
+      REPLACE_INET_NTOP=1
+      INET_NTOP_LIB="-lws2_32"
+    else
+      HAVE_DECL_INET_NTOP=0
+      HAVE_INET_NTOP=0
+    fi
+  else
+    gl_save_LIBS=$LIBS
+    AC_SEARCH_LIBS([inet_ntop], [nsl resolv], [],
+      [AC_CHECK_FUNCS([inet_ntop])
+       if test $ac_cv_func_inet_ntop = no; then
+         HAVE_INET_NTOP=0
+       fi
+      ])
+    LIBS=$gl_save_LIBS
+
+    if test "$ac_cv_search_inet_ntop" != "no" \
+       && test "$ac_cv_search_inet_ntop" != "none required"; then
+      INET_NTOP_LIB="$ac_cv_search_inet_ntop"
+    fi
+
+    AC_CHECK_HEADERS_ONCE([netdb.h])
+    AC_CHECK_DECLS([inet_ntop],,,
+      [[#include <arpa/inet.h>
+        #if HAVE_NETDB_H
+        # include <netdb.h>
+        #endif
+      ]])
+    if test $ac_cv_have_decl_inet_ntop = no; then
+      HAVE_DECL_INET_NTOP=0
+    fi
+  fi
+  AC_SUBST([INET_NTOP_LIB])
+])
+
+# Prerequisites of lib/inet_ntop.c.
+AC_DEFUN([gl_PREREQ_INET_NTOP], [
+  AC_REQUIRE([gl_SOCKET_FAMILIES])
+])
diff --git a/gl/m4/inet_pton.m4 b/gl/m4/inet_pton.m4
new file mode 100644
index 0000000..e64da7b
--- /dev/null
+++ b/gl/m4/inet_pton.m4
@@ -0,0 +1,68 @@
+# inet_pton.m4 serial 17
+dnl Copyright (C) 2006, 2008-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_INET_PTON],
+[
+  AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
+
+  dnl Persuade Solaris <arpa/inet.h> to declare inet_pton.
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+  AC_REQUIRE([AC_C_RESTRICT])
+
+  dnl Most platforms that provide inet_pton define it in libc.
+  dnl Solaris 8..10 provide inet_pton in libnsl instead.
+  dnl Solaris 2.6..7 provide inet_pton in libresolv instead.
+  dnl Native Windows provides it in -lws2_32 instead, with a declaration in
+  dnl <ws2tcpip.h>, and it uses stdcall calling convention, not cdecl
+  dnl (hence we cannot use AC_CHECK_FUNCS, AC_SEARCH_LIBS to find it).
+  HAVE_INET_PTON=1
+  INET_PTON_LIB=
+  gl_PREREQ_SYS_H_WINSOCK2
+  if test $HAVE_WINSOCK2_H = 1; then
+    AC_CHECK_DECLS([inet_pton],,, [[#include <ws2tcpip.h>]])
+    if test $ac_cv_have_decl_inet_pton = yes; then
+      dnl It needs to be overridden, because the stdcall calling convention
+      dnl is not compliant with POSIX.
+      REPLACE_INET_PTON=1
+      INET_PTON_LIB="-lws2_32"
+    else
+      HAVE_DECL_INET_PTON=0
+      HAVE_INET_PTON=0
+    fi
+  else
+    gl_save_LIBS=$LIBS
+    AC_SEARCH_LIBS([inet_pton], [nsl resolv], [],
+      [AC_CHECK_FUNCS([inet_pton])
+       if test $ac_cv_func_inet_pton = no; then
+         HAVE_INET_PTON=0
+       fi
+      ])
+    LIBS=$gl_save_LIBS
+
+    if test "$ac_cv_search_inet_pton" != "no" \
+       && test "$ac_cv_search_inet_pton" != "none required"; then
+      INET_PTON_LIB="$ac_cv_search_inet_pton"
+    fi
+
+    AC_CHECK_HEADERS_ONCE([netdb.h])
+    AC_CHECK_DECLS([inet_pton],,,
+      [[#include <arpa/inet.h>
+        #if HAVE_NETDB_H
+        # include <netdb.h>
+        #endif
+      ]])
+    if test $ac_cv_have_decl_inet_pton = no; then
+      HAVE_DECL_INET_PTON=0
+    fi
+  fi
+  AC_SUBST([INET_PTON_LIB])
+])
+
+# Prerequisites of lib/inet_pton.c.
+AC_DEFUN([gl_PREREQ_INET_PTON], [
+  AC_REQUIRE([gl_SOCKET_FAMILIES])
+])
diff --git a/gl/m4/ioctl.m4 b/gl/m4/ioctl.m4
new file mode 100644
index 0000000..a1db8fc
--- /dev/null
+++ b/gl/m4/ioctl.m4
@@ -0,0 +1,41 @@
+# ioctl.m4 serial 4
+dnl Copyright (C) 2008-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_IOCTL],
+[
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+  AC_REQUIRE([gl_HEADER_SYS_SOCKET])
+  HAVE_IOCTL=1
+  if test "$ac_cv_header_winsock2_h" = yes; then
+    dnl Even if the 'socket' module is not used here, another part of the
+    dnl application may use it and pass file descriptors that refer to
+    dnl sockets to the ioctl() function. So enable the support for sockets.
+    HAVE_IOCTL=0
+  else
+    AC_CHECK_FUNCS([ioctl])
+    dnl On glibc systems, the second parameter is 'unsigned long int request',
+    dnl not 'int request'. We cannot simply cast the function pointer, but
+    dnl instead need a wrapper.
+    AC_CACHE_CHECK([for ioctl with POSIX signature],
+      [gl_cv_func_ioctl_posix_signature],
+      [AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <sys/ioctl.h>]],
+            [[extern
+              #ifdef __cplusplus
+              "C"
+              #endif
+              int ioctl (int, int, ...);
+            ]])
+         ],
+         [gl_cv_func_ioctl_posix_signature=yes],
+         [gl_cv_func_ioctl_posix_signature=no])
+      ])
+    if test $gl_cv_func_ioctl_posix_signature != yes; then
+      REPLACE_IOCTL=1
+    fi
+  fi
+])
diff --git a/gl/m4/isnand.m4 b/gl/m4/isnand.m4
index 2b18b0a..48f1a48 100644
--- a/gl/m4/isnand.m4
+++ b/gl/m4/isnand.m4
@@ -1,4 +1,4 @@
-# isnand.m4 serial 10
+# isnand.m4 serial 11
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -43,7 +43,7 @@ AC_DEFUN([gl_FUNC_ISNAND_NO_LIBM],
 dnl Prerequisites of replacement isnand definition. It does not need -lm.
 AC_DEFUN([gl_PREREQ_ISNAND],
 [
-  gl_DOUBLE_EXPONENT_LOCATION
+  AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION])
 ])
 
 dnl Test whether isnand() can be used with libm.
diff --git a/gl/m4/isnanl.m4 b/gl/m4/isnanl.m4
index c79308b..daabe2a 100644
--- a/gl/m4/isnanl.m4
+++ b/gl/m4/isnanl.m4
@@ -1,4 +1,4 @@
-# isnanl.m4 serial 16
+# isnanl.m4 serial 17
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -56,6 +56,7 @@ dnl Prerequisites of replacement isnanl definition. It does 
not need -lm.
 AC_DEFUN([gl_PREREQ_ISNANL],
 [
   gl_LONG_DOUBLE_EXPONENT_LOCATION
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
 ])
 
 dnl Test whether isnanl() can be used without libm.
@@ -116,6 +117,7 @@ AC_DEFUN([gl_FUNC_ISNANL_WORKS],
 [
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([gl_BIGENDIAN])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   AC_CACHE_CHECK([whether isnanl works], [gl_cv_func_isnanl_works],
     [
@@ -169,7 +171,7 @@ int main ()
       result |= 1;
   }
 
-#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined 
__amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined 
_M_IX86 || defined _X86_))
+#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined 
__amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined 
_M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
 /* Representation of an 80-bit 'long double' as an initializer for a sequence
    of 'unsigned int' words.  */
 # ifdef WORDS_BIGENDIAN
diff --git a/gl/m4/ldexpl.m4 b/gl/m4/ldexpl.m4
index 4e419cf..f5d15fd 100644
--- a/gl/m4/ldexpl.m4
+++ b/gl/m4/ldexpl.m4
@@ -1,4 +1,4 @@
-# ldexpl.m4 serial 13
+# ldexpl.m4 serial 14
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -7,6 +7,7 @@ dnl with or without modifications, as long as this notice is 
preserved.
 AC_DEFUN([gl_FUNC_LDEXPL],
 [
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
   AC_REQUIRE([gl_FUNC_ISNANL]) dnl for ISNANL_LIBM
   dnl Check whether it's declared.
   dnl MacOS X 10.3 has ldexpl() in libc but doesn't declare it in <math.h>.
@@ -53,7 +54,12 @@ AC_DEFUN([gl_FUNC_LDEXPL],
   fi
   if test $HAVE_DECL_LDEXPL = 0 || test $gl_func_ldexpl = no; then
     dnl Find libraries needed to link lib/ldexpl.c.
-    LDEXPL_LIBM="$ISNANL_LIBM"
+    if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
+      AC_REQUIRE([gl_FUNC_LDEXP])
+      LDEXPL_LIBM="$LDEXP_LIBM"
+    else
+      LDEXPL_LIBM="$ISNANL_LIBM"
+    fi
   fi
   AC_SUBST([LDEXPL_LIBM])
 ])
diff --git a/gl/m4/math_h.m4 b/gl/m4/math_h.m4
index 7b46aee..e58a9e9 100644
--- a/gl/m4/math_h.m4
+++ b/gl/m4/math_h.m4
@@ -1,4 +1,4 @@
-# math_h.m4 serial 25
+# math_h.m4 serial 56
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -38,9 +38,13 @@ AC_DEFUN([gl_MATH_H],
 
   dnl Check for declarations of anything we want to poison if the
   dnl corresponding gnulib module is not in use.
-  gl_WARN_ON_USE_PREPARE([[#include <math.h>
-    ]], [acosl asinl atanl ceilf ceill cosl expl floorf floorl frexpl
-    ldexpl logb logl round roundf roundl sinl sqrtl tanl trunc truncf truncl])
+  gl_WARN_ON_USE_PREPARE([[#include <math.h>]],
+    [acosf acosl asinf asinl atanf atanl
+     ceilf ceill copysign copysignf copysignl cosf cosl coshf
+     expf expl fabsf floorf floorl fma fmaf fmal fmodf frexpf frexpl
+     ldexpf ldexpl logb logf logl log10f modff powf
+     rint rintf rintl round roundf roundl sinf sinl sinhf sqrtf sqrtl
+     tanf tanl tanhf trunc truncf truncl])
 ])
 
 AC_DEFUN([gl_MATH_MODULE_INDICATOR],
@@ -54,51 +58,109 @@ AC_DEFUN([gl_MATH_MODULE_INDICATOR],
 
 AC_DEFUN([gl_MATH_H_DEFAULTS],
 [
-  GNULIB_ACOSL=0;    AC_SUBST([GNULIB_ACOSL])
-  GNULIB_ASINL=0;    AC_SUBST([GNULIB_ASINL])
-  GNULIB_ATANL=0;    AC_SUBST([GNULIB_ATANL])
-  GNULIB_CEIL=0;     AC_SUBST([GNULIB_CEIL])
-  GNULIB_CEILF=0;    AC_SUBST([GNULIB_CEILF])
-  GNULIB_CEILL=0;    AC_SUBST([GNULIB_CEILL])
-  GNULIB_COSL=0;     AC_SUBST([GNULIB_COSL])
-  GNULIB_EXPL=0;     AC_SUBST([GNULIB_EXPL])
-  GNULIB_FLOOR=0;    AC_SUBST([GNULIB_FLOOR])
-  GNULIB_FLOORF=0;   AC_SUBST([GNULIB_FLOORF])
-  GNULIB_FLOORL=0;   AC_SUBST([GNULIB_FLOORL])
-  GNULIB_FREXP=0;    AC_SUBST([GNULIB_FREXP])
-  GNULIB_FREXPL=0;   AC_SUBST([GNULIB_FREXPL])
-  GNULIB_ISFINITE=0; AC_SUBST([GNULIB_ISFINITE])
-  GNULIB_ISINF=0;    AC_SUBST([GNULIB_ISINF])
-  GNULIB_ISNAN=0;    AC_SUBST([GNULIB_ISNAN])
-  GNULIB_ISNANF=0;   AC_SUBST([GNULIB_ISNANF])
-  GNULIB_ISNAND=0;   AC_SUBST([GNULIB_ISNAND])
-  GNULIB_ISNANL=0;   AC_SUBST([GNULIB_ISNANL])
-  GNULIB_LDEXPL=0;   AC_SUBST([GNULIB_LDEXPL])
-  GNULIB_LOGB=0;     AC_SUBST([GNULIB_LOGB])
-  GNULIB_LOGL=0;     AC_SUBST([GNULIB_LOGL])
-  GNULIB_ROUND=0;    AC_SUBST([GNULIB_ROUND])
-  GNULIB_ROUNDF=0;   AC_SUBST([GNULIB_ROUNDF])
-  GNULIB_ROUNDL=0;   AC_SUBST([GNULIB_ROUNDL])
-  GNULIB_SIGNBIT=0;  AC_SUBST([GNULIB_SIGNBIT])
-  GNULIB_SINL=0;     AC_SUBST([GNULIB_SINL])
-  GNULIB_SQRTL=0;    AC_SUBST([GNULIB_SQRTL])
-  GNULIB_TANL=0;     AC_SUBST([GNULIB_TANL])
-  GNULIB_TRUNC=0;    AC_SUBST([GNULIB_TRUNC])
-  GNULIB_TRUNCF=0;   AC_SUBST([GNULIB_TRUNCF])
-  GNULIB_TRUNCL=0;   AC_SUBST([GNULIB_TRUNCL])
+  GNULIB_ACOSF=0;     AC_SUBST([GNULIB_ACOSF])
+  GNULIB_ACOSL=0;     AC_SUBST([GNULIB_ACOSL])
+  GNULIB_ASINF=0;     AC_SUBST([GNULIB_ASINF])
+  GNULIB_ASINL=0;     AC_SUBST([GNULIB_ASINL])
+  GNULIB_ATANF=0;     AC_SUBST([GNULIB_ATANF])
+  GNULIB_ATANL=0;     AC_SUBST([GNULIB_ATANL])
+  GNULIB_ATAN2F=0;    AC_SUBST([GNULIB_ATAN2F])
+  GNULIB_CEIL=0;      AC_SUBST([GNULIB_CEIL])
+  GNULIB_CEILF=0;     AC_SUBST([GNULIB_CEILF])
+  GNULIB_CEILL=0;     AC_SUBST([GNULIB_CEILL])
+  GNULIB_COPYSIGN=0;  AC_SUBST([GNULIB_COPYSIGN])
+  GNULIB_COPYSIGNF=0; AC_SUBST([GNULIB_COPYSIGNF])
+  GNULIB_COPYSIGNL=0; AC_SUBST([GNULIB_COPYSIGNL])
+  GNULIB_COSF=0;      AC_SUBST([GNULIB_COSF])
+  GNULIB_COSL=0;      AC_SUBST([GNULIB_COSL])
+  GNULIB_COSHF=0;     AC_SUBST([GNULIB_COSHF])
+  GNULIB_EXPF=0;      AC_SUBST([GNULIB_EXPF])
+  GNULIB_EXPL=0;      AC_SUBST([GNULIB_EXPL])
+  GNULIB_FABSF=0;     AC_SUBST([GNULIB_FABSF])
+  GNULIB_FLOOR=0;     AC_SUBST([GNULIB_FLOOR])
+  GNULIB_FLOORF=0;    AC_SUBST([GNULIB_FLOORF])
+  GNULIB_FLOORL=0;    AC_SUBST([GNULIB_FLOORL])
+  GNULIB_FMA=0;       AC_SUBST([GNULIB_FMA])
+  GNULIB_FMAF=0;      AC_SUBST([GNULIB_FMAF])
+  GNULIB_FMAL=0;      AC_SUBST([GNULIB_FMAL])
+  GNULIB_FMODF=0;     AC_SUBST([GNULIB_FMODF])
+  GNULIB_FREXPF=0;    AC_SUBST([GNULIB_FREXPF])
+  GNULIB_FREXP=0;     AC_SUBST([GNULIB_FREXP])
+  GNULIB_FREXPL=0;    AC_SUBST([GNULIB_FREXPL])
+  GNULIB_ISFINITE=0;  AC_SUBST([GNULIB_ISFINITE])
+  GNULIB_ISINF=0;     AC_SUBST([GNULIB_ISINF])
+  GNULIB_ISNAN=0;     AC_SUBST([GNULIB_ISNAN])
+  GNULIB_ISNANF=0;    AC_SUBST([GNULIB_ISNANF])
+  GNULIB_ISNAND=0;    AC_SUBST([GNULIB_ISNAND])
+  GNULIB_ISNANL=0;    AC_SUBST([GNULIB_ISNANL])
+  GNULIB_LDEXPF=0;    AC_SUBST([GNULIB_LDEXPF])
+  GNULIB_LDEXPL=0;    AC_SUBST([GNULIB_LDEXPL])
+  GNULIB_LOGB=0;      AC_SUBST([GNULIB_LOGB])
+  GNULIB_LOGF=0;      AC_SUBST([GNULIB_LOGF])
+  GNULIB_LOGL=0;      AC_SUBST([GNULIB_LOGL])
+  GNULIB_LOG10F=0;    AC_SUBST([GNULIB_LOG10F])
+  GNULIB_MODFF=0;     AC_SUBST([GNULIB_MODFF])
+  GNULIB_POWF=0;      AC_SUBST([GNULIB_POWF])
+  GNULIB_RINT=0;      AC_SUBST([GNULIB_RINT])
+  GNULIB_RINTF=0;     AC_SUBST([GNULIB_RINTF])
+  GNULIB_RINTL=0;     AC_SUBST([GNULIB_RINTL])
+  GNULIB_ROUND=0;     AC_SUBST([GNULIB_ROUND])
+  GNULIB_ROUNDF=0;    AC_SUBST([GNULIB_ROUNDF])
+  GNULIB_ROUNDL=0;    AC_SUBST([GNULIB_ROUNDL])
+  GNULIB_SIGNBIT=0;   AC_SUBST([GNULIB_SIGNBIT])
+  GNULIB_SINF=0;      AC_SUBST([GNULIB_SINF])
+  GNULIB_SINL=0;      AC_SUBST([GNULIB_SINL])
+  GNULIB_SINHF=0;     AC_SUBST([GNULIB_SINHF])
+  GNULIB_SQRTF=0;     AC_SUBST([GNULIB_SQRTF])
+  GNULIB_SQRTL=0;     AC_SUBST([GNULIB_SQRTL])
+  GNULIB_TANF=0;      AC_SUBST([GNULIB_TANF])
+  GNULIB_TANL=0;      AC_SUBST([GNULIB_TANL])
+  GNULIB_TANHF=0;     AC_SUBST([GNULIB_TANHF])
+  GNULIB_TRUNC=0;     AC_SUBST([GNULIB_TRUNC])
+  GNULIB_TRUNCF=0;    AC_SUBST([GNULIB_TRUNCF])
+  GNULIB_TRUNCL=0;    AC_SUBST([GNULIB_TRUNCL])
   dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_ACOSF=1;                AC_SUBST([HAVE_ACOSF])
   HAVE_ACOSL=1;                AC_SUBST([HAVE_ACOSL])
+  HAVE_ASINF=1;                AC_SUBST([HAVE_ASINF])
   HAVE_ASINL=1;                AC_SUBST([HAVE_ASINL])
+  HAVE_ATANF=1;                AC_SUBST([HAVE_ATANF])
   HAVE_ATANL=1;                AC_SUBST([HAVE_ATANL])
+  HAVE_ATAN2F=1;               AC_SUBST([HAVE_ATAN2F])
+  HAVE_COPYSIGN=1;             AC_SUBST([HAVE_COPYSIGN])
+  HAVE_COPYSIGNF=1;            AC_SUBST([HAVE_COPYSIGNF])
+  HAVE_COPYSIGNL=1;            AC_SUBST([HAVE_COPYSIGNL])
+  HAVE_COSF=1;                 AC_SUBST([HAVE_COSF])
   HAVE_COSL=1;                 AC_SUBST([HAVE_COSL])
+  HAVE_COSHF=1;                AC_SUBST([HAVE_COSHF])
+  HAVE_EXPF=1;                 AC_SUBST([HAVE_EXPF])
   HAVE_EXPL=1;                 AC_SUBST([HAVE_EXPL])
+  HAVE_FABSF=1;                AC_SUBST([HAVE_FABSF])
+  HAVE_FMA=1;                  AC_SUBST([HAVE_FMA])
+  HAVE_FMAF=1;                 AC_SUBST([HAVE_FMAF])
+  HAVE_FMAL=1;                 AC_SUBST([HAVE_FMAL])
+  HAVE_FMODF=1;                AC_SUBST([HAVE_FMODF])
+  HAVE_FREXPF=1;               AC_SUBST([HAVE_FREXPF])
   HAVE_ISNANF=1;               AC_SUBST([HAVE_ISNANF])
   HAVE_ISNAND=1;               AC_SUBST([HAVE_ISNAND])
   HAVE_ISNANL=1;               AC_SUBST([HAVE_ISNANL])
+  HAVE_LDEXPF=1;               AC_SUBST([HAVE_LDEXPF])
+  HAVE_LOGF=1;                 AC_SUBST([HAVE_LOGF])
   HAVE_LOGL=1;                 AC_SUBST([HAVE_LOGL])
+  HAVE_LOG10F=1;               AC_SUBST([HAVE_LOG10F])
+  HAVE_MODFF=1;                AC_SUBST([HAVE_MODFF])
+  HAVE_POWF=1;                 AC_SUBST([HAVE_POWF])
+  HAVE_RINT=1;                 AC_SUBST([HAVE_RINT])
+  HAVE_RINTF=1;                AC_SUBST([HAVE_RINTF])
+  HAVE_RINTL=1;                AC_SUBST([HAVE_RINTL])
+  HAVE_SINF=1;                 AC_SUBST([HAVE_SINF])
   HAVE_SINL=1;                 AC_SUBST([HAVE_SINL])
+  HAVE_SINHF=1;                AC_SUBST([HAVE_SINHF])
+  HAVE_SQRTF=1;                AC_SUBST([HAVE_SQRTF])
   HAVE_SQRTL=1;                AC_SUBST([HAVE_SQRTL])
+  HAVE_TANF=1;                 AC_SUBST([HAVE_TANF])
   HAVE_TANL=1;                 AC_SUBST([HAVE_TANL])
+  HAVE_TANHF=1;                AC_SUBST([HAVE_TANHF])
   HAVE_DECL_ACOSL=1;           AC_SUBST([HAVE_DECL_ACOSL])
   HAVE_DECL_ASINL=1;           AC_SUBST([HAVE_DECL_ASINL])
   HAVE_DECL_ATANL=1;           AC_SUBST([HAVE_DECL_ATANL])
@@ -127,6 +189,10 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_FLOOR=0;             AC_SUBST([REPLACE_FLOOR])
   REPLACE_FLOORF=0;            AC_SUBST([REPLACE_FLOORF])
   REPLACE_FLOORL=0;            AC_SUBST([REPLACE_FLOORL])
+  REPLACE_FMA=0;               AC_SUBST([REPLACE_FMA])
+  REPLACE_FMAF=0;              AC_SUBST([REPLACE_FMAF])
+  REPLACE_FMAL=0;              AC_SUBST([REPLACE_FMAL])
+  REPLACE_FREXPF=0;            AC_SUBST([REPLACE_FREXPF])
   REPLACE_FREXP=0;             AC_SUBST([REPLACE_FREXP])
   REPLACE_FREXPL=0;            AC_SUBST([REPLACE_FREXPL])
   REPLACE_HUGE_VAL=0;          AC_SUBST([REPLACE_HUGE_VAL])
@@ -144,3 +210,34 @@ AC_DEFUN([gl_MATH_H_DEFAULTS],
   REPLACE_TRUNCF=0;            AC_SUBST([REPLACE_TRUNCF])
   REPLACE_TRUNCL=0;            AC_SUBST([REPLACE_TRUNCL])
 ])
+
+# gl_LONG_DOUBLE_VS_DOUBLE
+# determines whether 'long double' and 'double' have the same representation.
+# Sets variable HAVE_SAME_LONG_DOUBLE_AS_DOUBLE to 0 or 1, and defines
+# HAVE_SAME_LONG_DOUBLE_AS_DOUBLE accordingly.
+# The currently known platforms where this is the case are:
+# Linux/HPPA, Minix 3.1.8, AIX 5, AIX 6 and 7 with xlc, MSVC 9.
+AC_DEFUN([gl_LONG_DOUBLE_VS_DOUBLE],
+[
+  AC_CACHE_CHECK([whether long double and double are the same],
+    [gl_cv_long_double_equals_double],
+    [AC_COMPILE_IFELSE(
+       [AC_LANG_PROGRAM([[#include <float.h>]],
+          [[typedef int check[sizeof (long double) == sizeof (double)
+                              && LDBL_MANT_DIG == DBL_MANT_DIG
+                              && LDBL_MAX_EXP == DBL_MAX_EXP
+                              && LDBL_MIN_EXP == DBL_MIN_EXP
+                              ? 1 : -1];
+          ]])],
+       [gl_cv_long_double_equals_double=yes],
+       [gl_cv_long_double_equals_double=no])
+    ])
+  if test $gl_cv_long_double_equals_double = yes; then
+    AC_DEFINE([HAVE_SAME_LONG_DOUBLE_AS_DOUBLE], [1],
+      [Define to 1 if 'long double' and 'double' have the same 
representation.])
+    HAVE_SAME_LONG_DOUBLE_AS_DOUBLE=1
+  else
+    HAVE_SAME_LONG_DOUBLE_AS_DOUBLE=0
+  fi
+  AC_SUBST([HAVE_SAME_LONG_DOUBLE_AS_DOUBLE])
+])
diff --git a/gl/m4/md5.m4 b/gl/m4/md5.m4
deleted file mode 100644
index 4b41a85..0000000
--- a/gl/m4/md5.m4
+++ /dev/null
@@ -1,13 +0,0 @@
-# md5.m4 serial 12
-dnl Copyright (C) 2002-2006, 2008-2011 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-
-AC_DEFUN([gl_MD5],
-[
-  dnl Prerequisites of lib/md5.c.
-  AC_REQUIRE([gl_BIGENDIAN])
-  AC_REQUIRE([AC_C_INLINE])
-  :
-])
diff --git a/gl/m4/memxor.m4 b/gl/m4/memxor.m4
deleted file mode 100644
index 10c3313..0000000
--- a/gl/m4/memxor.m4
+++ /dev/null
@@ -1,10 +0,0 @@
-# memxor.m4 serial 4
-dnl Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
-dnl This file is free software; the Free Software Foundation
-dnl gives unlimited permission to copy and/or distribute it,
-dnl with or without modifications, as long as this notice is preserved.
-
-AC_DEFUN([gl_MEMXOR],
-[
-  AC_REQUIRE([AC_C_RESTRICT])
-])
diff --git a/gl/m4/msvc-nothrow.m4 b/gl/m4/msvc-nothrow.m4
new file mode 100644
index 0000000..b2f6bb4
--- /dev/null
+++ b/gl/m4/msvc-nothrow.m4
@@ -0,0 +1,10 @@
+# msvc-nothrow.m4 serial 1
+dnl Copyright (C) 2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_MSVC_NOTHROW],
+[
+  AC_REQUIRE([gl_MSVC_INVAL])
+])
diff --git a/gl/m4/pathmax.m4 b/gl/m4/pathmax.m4
index 0856722..4913fa0 100644
--- a/gl/m4/pathmax.m4
+++ b/gl/m4/pathmax.m4
@@ -1,4 +1,4 @@
-# pathmax.m4 serial 9
+# pathmax.m4 serial 10
 dnl Copyright (C) 2002-2003, 2005-2006, 2009-2011 Free Software Foundation,
 dnl Inc.
 dnl This file is free software; the Free Software Foundation
@@ -10,3 +10,33 @@ AC_DEFUN([gl_PATHMAX],
   dnl Prerequisites of lib/pathmax.h.
   AC_CHECK_HEADERS_ONCE([sys/param.h])
 ])
+
+# Expands to a piece of C program that defines PATH_MAX in the same way as
+# "pathmax.h" will do.
+AC_DEFUN([gl_PATHMAX_SNIPPET], [[
+/* Arrange to define PATH_MAX, like "pathmax.h" does. */
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#include <limits.h>
+#if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN
+# include <sys/param.h>
+#endif
+#if !defined PATH_MAX && defined MAXPATHLEN
+# define PATH_MAX MAXPATHLEN
+#endif
+#ifdef __hpux
+# undef PATH_MAX
+# define PATH_MAX 1024
+#endif
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# undef PATH_MAX
+# define PATH_MAX 260
+#endif
+]])
+
+# Prerequisites of gl_PATHMAX_SNIPPET.
+AC_DEFUN([gl_PATHMAX_SNIPPET_PREREQ],
+[
+  AC_CHECK_HEADERS_ONCE([unistd.h sys/param.h])
+])
diff --git a/gl/m4/perror.m4 b/gl/m4/perror.m4
new file mode 100644
index 0000000..cb17ba3
--- /dev/null
+++ b/gl/m4/perror.m4
@@ -0,0 +1,63 @@
+# perror.m4 serial 6
+dnl Copyright (C) 2008-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_PERROR],
+[
+  AC_REQUIRE([gl_STDIO_H_DEFAULTS])
+  AC_REQUIRE([gl_HEADER_ERRNO_H])
+  AC_REQUIRE([gl_FUNC_STRERROR_R])
+  AC_REQUIRE([gl_FUNC_STRERROR_0])
+  dnl We intentionally do not check for the broader REPLACE_STRERROR_R,
+  dnl since on glibc systems, strerror_r is replaced only for signature
+  dnl issues, and perror is just fine.  Rather, we only want to
+  dnl replace perror if strerror_r was replaced for a content fix.
+  if test "$ERRNO_H:$REPLACE_STRERROR_0" != :0; then
+    dnl The system's perror() cannot know about the new errno values we add
+    dnl to <errno.h>, or any fix for strerror(0). Replace it.
+    REPLACE_PERROR=1
+  fi
+  case ${gl_cv_func_strerror_r_works-unset} in
+    unset|*yes)
+      AC_CACHE_CHECK([whether perror matches strerror],
+        [gl_cv_func_perror_works],
+        [AC_RUN_IFELSE(
+           [AC_LANG_PROGRAM(
+              [[#include <errno.h>
+                #include <stdio.h>
+                #include <stdlib.h>
+                #include <string.h>
+              ]],
+              [[char *str = strerror (-1);
+                if (!getenv("CONFTEST_OUTPUT")) return 0;
+                if (!str) str = "";
+                puts (str);
+                errno = -1;
+                perror ("");
+                return 0;
+              ]])],
+           [if CONFTEST_OUTPUT=1 ./conftest$EXEEXT >conftest.txt1 
2>conftest.txt2 \
+               && cmp conftest.txt1 conftest.txt2 >/dev/null; then
+              gl_cv_func_perror_works=yes
+            else
+              gl_cv_func_perror_works=no
+            fi
+            rm -rf conftest.txt1 conftest.txt2],
+           [gl_cv_func_perror_works=no],
+           [dnl Guess no when cross-compiling.
+            gl_cv_func_perror_works="guessing no"
+           ])
+        ])
+      if test "$gl_cv_func_perror_works" != yes; then
+        REPLACE_PERROR=1
+      fi
+      ;;
+    *)
+      dnl The system's perror() probably inherits the bugs in the
+      dnl system's strerror_r(). Replace it.
+      REPLACE_PERROR=1
+      ;;
+  esac
+])
diff --git a/gl/m4/pipe.m4 b/gl/m4/pipe.m4
new file mode 100644
index 0000000..9013174
--- /dev/null
+++ b/gl/m4/pipe.m4
@@ -0,0 +1,15 @@
+# pipe.m4 serial 2
+dnl Copyright (C) 2010-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_PIPE],
+[
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+
+  AC_CHECK_FUNCS_ONCE([pipe])
+  if test $ac_cv_func_pipe != yes; then
+    HAVE_PIPE=0
+  fi
+])
diff --git a/gl/m4/printf-frexpl.m4 b/gl/m4/printf-frexpl.m4
index 9b698c9..e15628a 100644
--- a/gl/m4/printf-frexpl.m4
+++ b/gl/m4/printf-frexpl.m4
@@ -1,4 +1,4 @@
-# printf-frexpl.m4 serial 8
+# printf-frexpl.m4 serial 9
 dnl Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,6 +9,8 @@ dnl Check how to define printf_frexpl() without linking with 
libm.
 AC_DEFUN([gl_FUNC_PRINTF_FREXPL],
 [
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
+
   dnl Subset of gl_FUNC_FREXPL_NO_LIBM.
   gl_CHECK_FREXPL_NO_LIBM
   if test $gl_cv_func_frexpl_no_libm = yes; then
diff --git a/gl/m4/printf.m4 b/gl/m4/printf.m4
index d046c11..0814c91 100644
--- a/gl/m4/printf.m4
+++ b/gl/m4/printf.m4
@@ -1,4 +1,4 @@
-# printf.m4 serial 45
+# printf.m4 serial 46
 dnl Copyright (C) 2003, 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -251,6 +251,7 @@ AC_DEFUN([gl_PRINTF_INFINITE_LONG_DOUBLE],
   AC_REQUIRE([gl_PRINTF_LONG_DOUBLE])
   AC_REQUIRE([AC_PROG_CC])
   AC_REQUIRE([gl_BIGENDIAN])
+  AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
   dnl The user can set or unset the variable gl_printf_safe to indicate
   dnl that he wishes a safe handling of non-IEEE-754 'long double' values.
@@ -321,7 +322,7 @@ int main ()
   if (sprintf (buf, "%Lg", zeroL / zeroL) < 0
       || !strisnan (buf, 0, strlen (buf)))
     result |= 1;
-#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined 
__x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || 
defined _I386 || defined _M_IX86 || defined _X86_))
+#if CHECK_PRINTF_SAFE && ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined 
__x86_64__ || defined __amd64__) || (defined __i386 || defined __i386__ || 
defined _I386 || defined _M_IX86 || defined _X86_)) && 
!HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
 /* Representation of an 80-bit 'long double' as an initializer for a sequence
    of 'unsigned int' words.  */
 # ifdef WORDS_BIGENDIAN
diff --git a/gl/m4/select.m4 b/gl/m4/select.m4
new file mode 100644
index 0000000..a58f0ac
--- /dev/null
+++ b/gl/m4/select.m4
@@ -0,0 +1,75 @@
+# select.m4 serial 6
+dnl Copyright (C) 2009-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_SELECT],
+[
+  AC_REQUIRE([gl_HEADER_SYS_SELECT])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_SOCKETS])
+  if test "$ac_cv_header_winsock2_h" = yes; then
+    REPLACE_SELECT=1
+  else
+    dnl On Interix 3.5, select(0, NULL, NULL, NULL, timeout) fails with error
+    dnl EFAULT.
+    AC_CHECK_HEADERS_ONCE([sys/select.h])
+    AC_CACHE_CHECK([whether select supports a 0 argument],
+      [gl_cv_func_select_supports0],
+      [
+        AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#include <sys/types.h>
+#include <sys/time.h>
+#if HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+int main ()
+{
+  struct timeval timeout;
+  timeout.tv_sec = 0;
+  timeout.tv_usec = 5;
+  return select (0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &timeout) < 0;
+}]])], [gl_cv_func_select_supports0=yes], [gl_cv_func_select_supports0=no],
+          [
+changequote(,)dnl
+           case "$host_os" in
+                       # Guess no on Interix.
+             interix*) gl_cv_func_select_supports0="guessing no";;
+                       # Guess yes otherwise.
+             *)        gl_cv_func_select_supports0="guessing yes";;
+           esac
+changequote([,])dnl
+          ])
+      ])
+    case "$gl_cv_func_select_supports0" in
+      *yes) ;;
+      *) REPLACE_SELECT=1 ;;
+    esac
+  fi
+
+  dnl Determine the needed libraries.
+  LIB_SELECT="$LIBSOCKET"
+  if test $REPLACE_SELECT = 1; then
+    case "$host_os" in
+      mingw*)
+        dnl On the MSVC platform, the function MsgWaitForMultipleObjects
+        dnl (used in lib/select.c) requires linking with -luser32. On mingw,
+        dnl it is implicit.
+        AC_LINK_IFELSE(
+          [AC_LANG_SOURCE([[
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+int
+main ()
+{
+  MsgWaitForMultipleObjects (0, NULL, 0, 0, 0);
+  return 0;
+}]])],
+          [],
+          [LIB_SELECT="$LIB_SELECT -luser32"])
+        ;;
+    esac
+  fi
+  AC_SUBST([LIB_SELECT])
+])
diff --git a/gl/m4/signal_h.m4 b/gl/m4/signal_h.m4
new file mode 100644
index 0000000..5cf54a0
--- /dev/null
+++ b/gl/m4/signal_h.m4
@@ -0,0 +1,83 @@
+# signal_h.m4 serial 18
+dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_SIGNAL_H],
+[
+  AC_REQUIRE([gl_SIGNAL_H_DEFAULTS])
+  AC_REQUIRE([gl_CHECK_TYPE_SIGSET_T])
+  gl_NEXT_HEADERS([signal.h])
+
+# AIX declares sig_atomic_t to already include volatile, and C89 compilers
+# then choke on 'volatile sig_atomic_t'.  C99 requires that it compile.
+  AC_CHECK_TYPE([volatile sig_atomic_t], [],
+    [HAVE_TYPE_VOLATILE_SIG_ATOMIC_T=0], [[
+#include <signal.h>
+    ]])
+
+  dnl Ensure the type pid_t gets defined.
+  AC_REQUIRE([AC_TYPE_PID_T])
+
+  AC_REQUIRE([AC_TYPE_UID_T])
+
+  dnl Persuade glibc <signal.h> to define sighandler_t.
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+  AC_CHECK_TYPE([sighandler_t], [], [HAVE_SIGHANDLER_T=0], [[
+#include <signal.h>
+    ]])
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[#include <signal.h>
+    ]], [pthread_sigmask sigaction
+    sigaddset sigdelset sigemptyset sigfillset sigismember
+    sigpending sigprocmask])
+])
+
+AC_DEFUN([gl_CHECK_TYPE_SIGSET_T],
+[
+  AC_CHECK_TYPES([sigset_t],
+    [gl_cv_type_sigset_t=yes], [gl_cv_type_sigset_t=no],
+    [[
+      #include <signal.h>
+      /* Mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.  */
+      #include <sys/types.h>
+    ]])
+  if test $gl_cv_type_sigset_t != yes; then
+    HAVE_SIGSET_T=0
+  fi
+])
+
+AC_DEFUN([gl_SIGNAL_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_SIGNAL_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_SIGNAL_H_DEFAULTS],
+[
+  GNULIB_PTHREAD_SIGMASK=0;    AC_SUBST([GNULIB_PTHREAD_SIGMASK])
+  GNULIB_RAISE=0;              AC_SUBST([GNULIB_RAISE])
+  GNULIB_SIGNAL_H_SIGPIPE=0;   AC_SUBST([GNULIB_SIGNAL_H_SIGPIPE])
+  GNULIB_SIGPROCMASK=0;        AC_SUBST([GNULIB_SIGPROCMASK])
+  GNULIB_SIGACTION=0;          AC_SUBST([GNULIB_SIGACTION])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_POSIX_SIGNALBLOCKING=1; AC_SUBST([HAVE_POSIX_SIGNALBLOCKING])
+  HAVE_PTHREAD_SIGMASK=1;      AC_SUBST([HAVE_PTHREAD_SIGMASK])
+  HAVE_RAISE=1;                AC_SUBST([HAVE_RAISE])
+  HAVE_SIGSET_T=1;             AC_SUBST([HAVE_SIGSET_T])
+  HAVE_SIGINFO_T=1;            AC_SUBST([HAVE_SIGINFO_T])
+  HAVE_SIGACTION=1;            AC_SUBST([HAVE_SIGACTION])
+  HAVE_STRUCT_SIGACTION_SA_SIGACTION=1;
+                               AC_SUBST([HAVE_STRUCT_SIGACTION_SA_SIGACTION])
+  HAVE_TYPE_VOLATILE_SIG_ATOMIC_T=1;
+                               AC_SUBST([HAVE_TYPE_VOLATILE_SIG_ATOMIC_T])
+  HAVE_SIGHANDLER_T=1;         AC_SUBST([HAVE_SIGHANDLER_T])
+  REPLACE_PTHREAD_SIGMASK=0;   AC_SUBST([REPLACE_PTHREAD_SIGMASK])
+  REPLACE_RAISE=0;             AC_SUBST([REPLACE_RAISE])
+])
diff --git a/gl/m4/stdalign.m4 b/gl/m4/stdalign.m4
new file mode 100644
index 0000000..da64dc6
--- /dev/null
+++ b/gl/m4/stdalign.m4
@@ -0,0 +1,22 @@
+# Check for stdalign.h that conforms to C1x.
+
+dnl Copyright 2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# Prepare for substituting <stdalign.h> if it is not supported.
+
+AC_DEFUN([gl_STDALIGN_H],
+[
+  AC_CHECK_HEADERS_ONCE([stdalign.h])
+
+  if test $ac_cv_header_stdalign_h = yes; then
+    STDALIGN_H=''
+  else
+    STDALIGN_H='stdalign.h'
+  fi
+
+  AC_SUBST([STDALIGN_H])
+  AM_CONDITIONAL([GL_GENERATE_STDALIGN_H], [test -n "$STDALIGN_H"])
+])
diff --git a/gl/m4/stdio_h.m4 b/gl/m4/stdio_h.m4
index 988e025..39bf80e 100644
--- a/gl/m4/stdio_h.m4
+++ b/gl/m4/stdio_h.m4
@@ -1,4 +1,4 @@
-# stdio_h.m4 serial 39
+# stdio_h.m4 serial 40
 dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -91,6 +91,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
 [
   GNULIB_DPRINTF=0;              AC_SUBST([GNULIB_DPRINTF])
   GNULIB_FCLOSE=0;               AC_SUBST([GNULIB_FCLOSE])
+  GNULIB_FDOPEN=0;               AC_SUBST([GNULIB_FDOPEN])
   GNULIB_FFLUSH=0;               AC_SUBST([GNULIB_FFLUSH])
   GNULIB_FGETC=0;                AC_SUBST([GNULIB_FGETC])
   GNULIB_FGETS=0;                AC_SUBST([GNULIB_FGETS])
@@ -161,6 +162,7 @@ AC_DEFUN([gl_STDIO_H_DEFAULTS],
   HAVE_VDPRINTF=1;               AC_SUBST([HAVE_VDPRINTF])
   REPLACE_DPRINTF=0;             AC_SUBST([REPLACE_DPRINTF])
   REPLACE_FCLOSE=0;              AC_SUBST([REPLACE_FCLOSE])
+  REPLACE_FDOPEN=0;              AC_SUBST([REPLACE_FDOPEN])
   REPLACE_FFLUSH=0;              AC_SUBST([REPLACE_FFLUSH])
   REPLACE_FOPEN=0;               AC_SUBST([REPLACE_FOPEN])
   REPLACE_FPRINTF=0;             AC_SUBST([REPLACE_FPRINTF])
diff --git a/gl/m4/stdlib_h.m4 b/gl/m4/stdlib_h.m4
index 25fdada..fbdba98 100644
--- a/gl/m4/stdlib_h.m4
+++ b/gl/m4/stdlib_h.m4
@@ -19,10 +19,10 @@ AC_DEFUN([gl_STDLIB_H],
 #if HAVE_RANDOM_H
 # include <random.h>
 #endif
-    ]], [_Exit atoll canonicalize_file_name getloadavg getsubopt grantpt 
mkdtemp
-    mkostemp mkostemps mkstemp mkstemps ptsname random_r initstat_r srandom_r
-    setstate_r realpath rpmatch setenv strtod strtoll strtoull unlockpt
-    unsetenv])
+    ]], [_Exit atoll canonicalize_file_name getloadavg getsubopt grantpt
+    initstate_r mkdtemp mkostemp mkostemps mkstemp mkstemps posix_openpt
+    ptsname random_r realpath rpmatch setenv setstate_r srandom_r strtod
+    strtoll strtoull unlockpt unsetenv])
 ])
 
 AC_DEFUN([gl_STDLIB_MODULE_INDICATOR],
@@ -50,6 +50,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   GNULIB_MKOSTEMPS=0;     AC_SUBST([GNULIB_MKOSTEMPS])
   GNULIB_MKSTEMP=0;       AC_SUBST([GNULIB_MKSTEMP])
   GNULIB_MKSTEMPS=0;      AC_SUBST([GNULIB_MKSTEMPS])
+  GNULIB_POSIX_OPENPT=0;  AC_SUBST([GNULIB_POSIX_OPENPT])
   GNULIB_PTSNAME=0;       AC_SUBST([GNULIB_PTSNAME])
   GNULIB_PUTENV=0;        AC_SUBST([GNULIB_PUTENV])
   GNULIB_RANDOM_R=0;      AC_SUBST([GNULIB_RANDOM_R])
@@ -76,6 +77,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   HAVE_MKOSTEMPS=1;          AC_SUBST([HAVE_MKOSTEMPS])
   HAVE_MKSTEMP=1;            AC_SUBST([HAVE_MKSTEMP])
   HAVE_MKSTEMPS=1;           AC_SUBST([HAVE_MKSTEMPS])
+  HAVE_POSIX_OPENPT=1;       AC_SUBST([HAVE_POSIX_OPENPT])
   HAVE_PTSNAME=1;            AC_SUBST([HAVE_PTSNAME])
   HAVE_RANDOM_H=1;           AC_SUBST([HAVE_RANDOM_H])
   HAVE_RANDOM_R=1;           AC_SUBST([HAVE_RANDOM_R])
diff --git a/gl/m4/strerror_r.m4 b/gl/m4/strerror_r.m4
new file mode 100644
index 0000000..1d4a653
--- /dev/null
+++ b/gl/m4/strerror_r.m4
@@ -0,0 +1,173 @@
+# strerror_r.m4 serial 14
+dnl Copyright (C) 2002, 2007-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_STRERROR_R],
+[
+  AC_REQUIRE([gl_HEADER_STRING_H_DEFAULTS])
+  AC_REQUIRE([gl_FUNC_STRERROR_R_WORKS])
+
+  dnl Persuade Solaris <string.h> to declare strerror_r().
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+
+  dnl Some systems don't declare strerror_r() if _THREAD_SAFE and _REENTRANT
+  dnl are not defined.
+  AC_CHECK_DECLS_ONCE([strerror_r])
+  if test $ac_cv_have_decl_strerror_r = no; then
+    HAVE_DECL_STRERROR_R=0
+  fi
+
+  if test $ac_cv_func_strerror_r = yes; then
+    if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then
+      if test $gl_cv_func_strerror_r_posix_signature = yes; then
+        case "$gl_cv_func_strerror_r_works" in
+          dnl The system's strerror_r has bugs.  Replace it.
+          *no) REPLACE_STRERROR_R=1 ;;
+        esac
+      else
+        dnl The system's strerror_r() has a wrong signature. Replace it.
+        REPLACE_STRERROR_R=1
+      fi
+    else
+      dnl The system's strerror_r() cannot know about the new errno values we
+      dnl add to <errno.h>, or any fix for strerror(0). Replace it.
+      REPLACE_STRERROR_R=1
+    fi
+  fi
+])
+
+# Prerequisites of lib/strerror_r.c.
+AC_DEFUN([gl_PREREQ_STRERROR_R], [
+  dnl glibc >= 2.3.4 and cygwin 1.7.9 have a function __xpg_strerror_r.
+  AC_CHECK_FUNCS_ONCE([__xpg_strerror_r])
+  AC_CHECK_FUNCS_ONCE([catgets])
+  AC_CHECK_FUNCS_ONCE([snprintf])
+])
+
+# Detect if strerror_r works, but without affecting whether a replacement
+# strerror_r will be used.
+AC_DEFUN([gl_FUNC_STRERROR_R_WORKS],
+[
+  AC_REQUIRE([gl_HEADER_ERRNO_H])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_REQUIRE([gl_FUNC_STRERROR_0])
+
+  AC_CHECK_FUNCS_ONCE([strerror_r])
+  if test $ac_cv_func_strerror_r = yes; then
+    if test "$ERRNO_H:$REPLACE_STRERROR_0" = :0; then
+      dnl The POSIX prototype is:  int strerror_r (int, char *, size_t);
+      dnl glibc, Cygwin:           char *strerror_r (int, char *, size_t);
+      dnl AIX 5.1, OSF/1 5.1:      int strerror_r (int, char *, int);
+      AC_CACHE_CHECK([for strerror_r with POSIX signature],
+        [gl_cv_func_strerror_r_posix_signature],
+        [AC_COMPILE_IFELSE(
+           [AC_LANG_PROGRAM(
+              [[#include <string.h>
+                int strerror_r (int, char *, size_t);
+              ]],
+              [])],
+           [gl_cv_func_strerror_r_posix_signature=yes],
+           [gl_cv_func_strerror_r_posix_signature=no])
+        ])
+      if test $gl_cv_func_strerror_r_posix_signature = yes; then
+        dnl AIX 6.1 strerror_r fails by returning -1, not an error number.
+        dnl HP-UX 11.31 strerror_r always fails when the buffer length argument
+        dnl is less than 80.
+        dnl FreeBSD 8.s strerror_r claims failure on 0
+        dnl MacOS X 10.5 strerror_r treats 0 like -1
+        dnl Solaris 10 strerror_r corrupts errno on failure
+        AC_CACHE_CHECK([whether strerror_r works],
+          [gl_cv_func_strerror_r_works],
+          [AC_RUN_IFELSE(
+             [AC_LANG_PROGRAM(
+                [[#include <errno.h>
+                  #include <string.h>
+                ]],
+                [[int result = 0;
+                  char buf[79];
+                  if (strerror_r (EACCES, buf, 0) < 0)
+                    result |= 1;
+                  errno = 0;
+                  if (strerror_r (EACCES, buf, sizeof buf) != 0)
+                    result |= 2;
+                  strcpy (buf, "Unknown");
+                  if (strerror_r (0, buf, sizeof buf) != 0)
+                    result |= 4;
+                  if (errno)
+                    result |= 8;
+                  if (strstr (buf, "nknown") || strstr (buf, "ndefined"))
+                    result |= 0x10;
+                  errno = 0;
+                  *buf = 0;
+                  if (strerror_r (-3, buf, sizeof buf) < 0)
+                    result |= 0x20;
+                  if (errno)
+                    result |= 0x40;
+                  if (!*buf)
+                    result |= 0x80;
+                  return result;
+                ]])],
+             [gl_cv_func_strerror_r_works=yes],
+             [gl_cv_func_strerror_r_works=no],
+             [
+changequote(,)dnl
+              case "$host_os" in
+                       # Guess no on AIX.
+                aix*)  gl_cv_func_strerror_r_works="guessing no";;
+                       # Guess no on HP-UX.
+                hpux*) gl_cv_func_strerror_r_works="guessing no";;
+                       # Guess no on BSD variants.
+                *bsd*)  gl_cv_func_strerror_r_works="guessing no";;
+                       # Guess yes otherwise.
+                *)     gl_cv_func_strerror_r_works="guessing yes";;
+              esac
+changequote([,])dnl
+             ])
+          ])
+      else
+        dnl The system's strerror() has a wrong signature.
+        dnl glibc >= 2.3.4 and cygwin 1.7.9 have a function __xpg_strerror_r.
+        AC_CHECK_FUNCS_ONCE([__xpg_strerror_r])
+        dnl In glibc < 2.14, __xpg_strerror_r does not populate buf on failure.
+        dnl In cygwin < 1.7.10, __xpg_strerror_r clobbers strerror's buffer.
+        if test $ac_cv_func___xpg_strerror_r = yes; then
+          AC_CACHE_CHECK([whether __xpg_strerror_r works],
+            [gl_cv_func_strerror_r_works],
+            [AC_RUN_IFELSE(
+               [AC_LANG_PROGRAM(
+                  [[#include <errno.h>
+                    #include <string.h>
+                    extern
+                    #ifdef __cplusplus
+                    "C"
+                    #endif
+                    int __xpg_strerror_r(int, char *, size_t);
+                  ]],
+                  [[int result = 0;
+                    char buf[256] = "^";
+                    char copy[256];
+                    char *str = strerror (-1);
+                    strcpy (copy, str);
+                    if (__xpg_strerror_r (-2, buf, 1) == 0)
+                      result |= 1;
+                    if (*buf)
+                      result |= 2;
+                    __xpg_strerror_r (-2, buf, 256);
+                    if (strcmp (str, copy))
+                      result |= 4;
+                    return result;
+                  ]])],
+               [gl_cv_func_strerror_r_works=yes],
+               [gl_cv_func_strerror_r_works=no],
+               [dnl Guess no on all platforms that have __xpg_strerror_r,
+                dnl at least until fixed glibc and cygwin are more common.
+                gl_cv_func_strerror_r_works="guessing no"
+               ])
+            ])
+        fi
+      fi
+    fi
+  fi
+])
diff --git a/gl/m4/sys_ioctl_h.m4 b/gl/m4/sys_ioctl_h.m4
new file mode 100644
index 0000000..8c7d112
--- /dev/null
+++ b/gl/m4/sys_ioctl_h.m4
@@ -0,0 +1,64 @@
+# sys_ioctl_h.m4 serial 10
+dnl Copyright (C) 2008-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Bruno Haible.
+
+AC_DEFUN([gl_SYS_IOCTL_H],
+[
+  dnl Use AC_REQUIRE here, so that the default behavior below is expanded
+  dnl once only, before all statements that occur in other macros.
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+
+  AC_CHECK_HEADERS_ONCE([sys/ioctl.h])
+  if test $ac_cv_header_sys_ioctl_h = yes; then
+    HAVE_SYS_IOCTL_H=1
+    dnl Test whether <sys/ioctl.h> declares ioctl(), or whether some other
+    dnl header file, such as <unistd.h> or <stropts.h>, is needed for that.
+    AC_CACHE_CHECK([whether <sys/ioctl.h> declares ioctl],
+      [gl_cv_decl_ioctl_in_sys_ioctl_h],
+      [dnl We cannot use AC_CHECK_DECL because it produces its own messages.
+       AC_COMPILE_IFELSE(
+         [AC_LANG_PROGRAM(
+            [AC_INCLUDES_DEFAULT([#include <sys/ioctl.h>])],
+            [(void) ioctl;])],
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=yes],
+         [gl_cv_decl_ioctl_in_sys_ioctl_h=no])
+      ])
+  else
+    HAVE_SYS_IOCTL_H=0
+  fi
+  AC_SUBST([HAVE_SYS_IOCTL_H])
+  dnl <sys/ioctl.h> is always overridden, because of GNULIB_POSIXCHECK.
+  gl_CHECK_NEXT_HEADERS([sys/ioctl.h])
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[#include <sys/ioctl.h>
+/* Some platforms declare ioctl in the wrong header.  */
+#if !(defined __GLIBC__ && !defined __UCLIBC__)
+# include <unistd.h>
+#endif
+    ]], [ioctl])
+])
+
+AC_DEFUN([gl_SYS_IOCTL_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_SYS_IOCTL_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_SYS_IOCTL_H_DEFAULTS],
+[
+  GNULIB_IOCTL=0;         AC_SUBST([GNULIB_IOCTL])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  SYS_IOCTL_H_HAVE_WINSOCK2_H=0; AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H])
+  SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS=0;
+                        AC_SUBST([SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS])
+  REPLACE_IOCTL=0;      AC_SUBST([REPLACE_IOCTL])
+])
diff --git a/gl/m4/sys_select_h.m4 b/gl/m4/sys_select_h.m4
new file mode 100644
index 0000000..b1914fb
--- /dev/null
+++ b/gl/m4/sys_select_h.m4
@@ -0,0 +1,95 @@
+# sys_select_h.m4 serial 20
+dnl Copyright (C) 2006-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_HEADER_SYS_SELECT],
+[
+  AC_REQUIRE([AC_C_RESTRICT])
+  AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
+  AC_CACHE_CHECK([whether <sys/select.h> is self-contained],
+    [gl_cv_header_sys_select_h_selfcontained],
+    [
+      dnl Test against two bugs:
+      dnl 1. On many platforms, <sys/select.h> assumes prior inclusion of
+      dnl    <sys/types.h>.
+      dnl 2. On OSF/1 4.0, <sys/select.h> provides only a forward declaration
+      dnl    of 'struct timeval', and no definition of this type.
+      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/select.h>]],
+                                         [[struct timeval b;]])],
+        [gl_cv_header_sys_select_h_selfcontained=yes],
+        [gl_cv_header_sys_select_h_selfcontained=no])
+      dnl Test against another bug:
+      dnl 3. On Solaris 10, <sys/select.h> provides an FD_ZERO implementation
+      dnl    that relies on memset(), but without including <string.h>.
+      if test $gl_cv_header_sys_select_h_selfcontained = yes; then
+        AC_COMPILE_IFELSE(
+          [AC_LANG_PROGRAM([[#include <sys/select.h>]],
+                           [[int memset; int bzero;]])
+          ],
+          [AC_LINK_IFELSE(
+             [AC_LANG_PROGRAM([[#include <sys/select.h>]], [[
+                  #undef memset
+                  #define memset nonexistent_memset
+                  extern
+                  #ifdef __cplusplus
+                  "C"
+                  #endif
+                  void *memset (void *, int, unsigned long);
+                  #undef bzero
+                  #define bzero nonexistent_bzero
+                  extern
+                  #ifdef __cplusplus
+                  "C"
+                  #endif
+                  void bzero (void *, unsigned long);
+                  fd_set fds;
+                  FD_ZERO (&fds);
+                ]])
+             ],
+             [],
+             [gl_cv_header_sys_select_h_selfcontained=no])
+          ])
+      fi
+    ])
+  dnl <sys/select.h> is always overridden, because of GNULIB_POSIXCHECK.
+  gl_CHECK_NEXT_HEADERS([sys/select.h])
+  if test $ac_cv_header_sys_select_h = yes; then
+    HAVE_SYS_SELECT_H=1
+  else
+    HAVE_SYS_SELECT_H=0
+  fi
+  AC_SUBST([HAVE_SYS_SELECT_H])
+  gl_PREREQ_SYS_H_WINSOCK2
+
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[
+/* Some systems require prerequisite headers.  */
+#include <sys/types.h>
+#if !(defined __GLIBC__ && !defined __UCLIBC__) && HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#include <sys/select.h>
+    ]], [pselect select])
+])
+
+AC_DEFUN([gl_SYS_SELECT_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_SYS_SELECT_H_DEFAULTS])
+  gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+  dnl Define it also as a C macro, for the benefit of the unit tests.
+  gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_SYS_SELECT_H_DEFAULTS],
+[
+  GNULIB_PSELECT=0; AC_SUBST([GNULIB_PSELECT])
+  GNULIB_SELECT=0; AC_SUBST([GNULIB_SELECT])
+  dnl Assume proper GNU behavior unless another module says otherwise.
+  HAVE_PSELECT=1; AC_SUBST([HAVE_PSELECT])
+  REPLACE_PSELECT=0; AC_SUBST([REPLACE_PSELECT])
+  REPLACE_SELECT=0; AC_SUBST([REPLACE_SELECT])
+])
diff --git a/gl/m4/sys_stat_h.m4 b/gl/m4/sys_stat_h.m4
index a3e46ca..83ebac6 100644
--- a/gl/m4/sys_stat_h.m4
+++ b/gl/m4/sys_stat_h.m4
@@ -1,4 +1,4 @@
-# sys_stat_h.m4 serial 25   -*- Autoconf -*-
+# sys_stat_h.m4 serial 26   -*- Autoconf -*-
 dnl Copyright (C) 2006-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -33,7 +33,7 @@ AC_DEFUN([gl_HEADER_SYS_STAT_H],
   dnl Check for declarations of anything we want to poison if the
   dnl corresponding gnulib module is not in use.
   gl_WARN_ON_USE_PREPARE([[#include <sys/stat.h>
-    ]], [fchmodat fstatat futimens lchmod lstat mkdirat mkfifo mkfifoat
+    ]], [fchmodat fstat fstatat futimens lchmod lstat mkdirat mkfifo mkfifoat
     mknod mknodat stat utimensat])
 ]) # gl_HEADER_SYS_STAT_H
 
@@ -50,6 +50,7 @@ AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for REPLACE_FCHDIR
   GNULIB_FCHMODAT=0;    AC_SUBST([GNULIB_FCHMODAT])
+  GNULIB_FSTAT=0;       AC_SUBST([GNULIB_FSTAT])
   GNULIB_FSTATAT=0;     AC_SUBST([GNULIB_FSTATAT])
   GNULIB_FUTIMENS=0;    AC_SUBST([GNULIB_FUTIMENS])
   GNULIB_LCHMOD=0;      AC_SUBST([GNULIB_LCHMOD])
diff --git a/gl/m4/thread.m4 b/gl/m4/thread.m4
new file mode 100644
index 0000000..49a4bc7
--- /dev/null
+++ b/gl/m4/thread.m4
@@ -0,0 +1,18 @@
+# thread.m4 serial 2
+dnl Copyright (C) 2008-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_THREAD],
+[
+  AC_REQUIRE([gl_THREADLIB])
+  AC_REQUIRE([AC_C_INLINE])
+
+  if test $gl_threads_api = posix; then
+    gl_save_LIBS="$LIBS"
+    LIBS="$LIBS $LIBMULTITHREAD"
+    AC_CHECK_FUNCS([pthread_atfork])
+    LIBS="$gl_save_LIBS"
+  fi
+])
diff --git a/gl/m4/unistd_h.m4 b/gl/m4/unistd_h.m4
index 720e0fd..57c8094 100644
--- a/gl/m4/unistd_h.m4
+++ b/gl/m4/unistd_h.m4
@@ -1,4 +1,4 @@
-# unistd_h.m4 serial 59
+# unistd_h.m4 serial 61
 dnl Copyright (C) 2006-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -39,7 +39,7 @@ AC_DEFUN([gl_UNISTD_H],
 #  include <io.h>
 # endif
 #endif
-    ]], [chown dup2 dup3 environ euidaccess faccessat fchdir fchownat
+    ]], [chdir chown dup dup2 dup3 environ euidaccess faccessat fchdir fchownat
     fdatasync fsync ftruncate getcwd getdomainname getdtablesize getgroups
     gethostname getlogin getlogin_r getpagesize getusershell setusershell
     endusershell group_member lchown link linkat lseek pipe pipe2 pread pwrite
@@ -58,8 +58,10 @@ AC_DEFUN([gl_UNISTD_MODULE_INDICATOR],
 
 AC_DEFUN([gl_UNISTD_H_DEFAULTS],
 [
+  GNULIB_CHDIR=0;                AC_SUBST([GNULIB_CHDIR])
   GNULIB_CHOWN=0;                AC_SUBST([GNULIB_CHOWN])
   GNULIB_CLOSE=0;                AC_SUBST([GNULIB_CLOSE])
+  GNULIB_DUP=0;                  AC_SUBST([GNULIB_DUP])
   GNULIB_DUP2=0;                 AC_SUBST([GNULIB_DUP2])
   GNULIB_DUP3=0;                 AC_SUBST([GNULIB_DUP3])
   GNULIB_ENVIRON=0;              AC_SUBST([GNULIB_ENVIRON])
diff --git a/gl/m4/valgrind-tests.m4 b/gl/m4/valgrind-tests.m4
index 98d4487..9c4d029 100644
--- a/gl/m4/valgrind-tests.m4
+++ b/gl/m4/valgrind-tests.m4
@@ -23,7 +23,7 @@ AC_DEFUN([gl_VALGRIND_TESTS],
 
   if test -n "$VALGRIND" && $VALGRIND -q true > /dev/null 2>&1; then
     opt_valgrind_tests=yes
-    VALGRIND="$VALGRIND -q --error-exitcode=1"
+    VALGRIND="$VALGRIND -q --error-exitcode=1 
--suppressions=suppressions.valgrind"
   else
     opt_valgrind_tests=no
     VALGRIND=
diff --git a/gl/m4/vasnprintf.m4 b/gl/m4/vasnprintf.m4
index 749d708..da0a6d9 100644
--- a/gl/m4/vasnprintf.m4
+++ b/gl/m4/vasnprintf.m4
@@ -1,4 +1,4 @@
-# vasnprintf.m4 serial 33
+# vasnprintf.m4 serial 34
 dnl Copyright (C) 2002-2004, 2006-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -64,6 +64,9 @@ AC_DEFUN_ONCE([gl_PREREQ_VASNPRINTF],
   dnl Use the _snprintf function only if it is declared (because on NetBSD it
   dnl is defined as a weak alias of snprintf; we prefer to use the latter).
   AC_CHECK_DECLS([_snprintf], , , [[#include <stdio.h>]])
+  dnl Knowing DBL_EXPBIT0_WORD and DBL_EXPBIT0_BIT enables an optimization
+  dnl in the code for NEED_PRINTF_LONG_DOUBLE || NEED_PRINTF_DOUBLE.
+  AC_REQUIRE([gl_DOUBLE_EXPONENT_LOCATION])
   dnl We can avoid a lot of code by assuming that snprintf's return value
   dnl conforms to ISO C99. So check that.
   AC_REQUIRE([gl_SNPRINTF_RETVAL_C99])
diff --git a/gl/m4/yield.m4 b/gl/m4/yield.m4
new file mode 100644
index 0000000..15d5ac2
--- /dev/null
+++ b/gl/m4/yield.m4
@@ -0,0 +1,19 @@
+# yield.m4 serial 2
+dnl Copyright (C) 2005-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_YIELD],
+[
+  AC_REQUIRE([gl_THREADLIB])
+  dnl On some systems, sched_yield is in librt, rather than in libpthread.
+  YIELD_LIB=
+  if test $gl_threads_api = posix; then
+    dnl Solaris has sched_yield in librt, not in libpthread or libc.
+    AC_CHECK_LIB([rt], [sched_yield], [YIELD_LIB=-lrt],
+      [dnl Solaris 2.5.1, 2.6 has sched_yield in libposix4, not librt.
+       AC_CHECK_LIB([posix4], [sched_yield], [YIELD_LIB=-lposix4])])
+  fi
+  AC_SUBST([YIELD_LIB])
+])
diff --git a/gl/math.in.h b/gl/math.in.h
index afbc9cb..eadb489 100644
--- a/gl/math.in.h
+++ b/gl/math.in.h
@@ -35,6 +35,44 @@
 
 /* The definition of _GL_WARN_ON_USE is copied here.  */
 
+#ifdef __cplusplus
+/* Helper macros to define type-generic function FUNC as overloaded functions,
+   rather than as macros like in C.  POSIX declares these with an argument of
+   real-floating (that is, one of float, double, or long double).  */
+# define _GL_MATH_CXX_REAL_FLOATING_DECL_1(func) \
+static inline int                                                   \
+_gl_cxx_ ## func ## f (float f)                                     \
+{                                                                   \
+  return func (f);                                                  \
+}                                                                   \
+static inline int                                                   \
+_gl_cxx_ ## func ## d (double d)                                    \
+{                                                                   \
+  return func (d);                                                  \
+}                                                                   \
+static inline int                                                   \
+_gl_cxx_ ## func ## l (long double l)                               \
+{                                                                   \
+  return func (l);                                                  \
+}
+# define _GL_MATH_CXX_REAL_FLOATING_DECL_2(func) \
+inline int                                                          \
+func (float f)                                                      \
+{                                                                   \
+  return _gl_cxx_ ## func ## f (f);                                 \
+}                                                                   \
+inline int                                                          \
+func (double d)                                                     \
+{                                                                   \
+  return _gl_cxx_ ## func ## d (d);                                 \
+}                                                                   \
+inline int                                                          \
+func (long double l)                                                \
+{                                                                   \
+  return _gl_cxx_ ## func ## l (l);                                 \
+}
+#endif
+
 /* Helper macros to define a portability warning for the
    classification macro FUNC called with VALUE.  POSIX declares the
    classification macros with an argument of real-floating (that is,
@@ -67,6 +105,14 @@ _GL_WARN_ON_USE (rpl_ ## func ## l, #func " is unportable - 
"       \
    : rpl_ ## func ## l (value))
 
 
+#if @REPLACE_ITOLD@
+/* Pull in a function that fixes the 'int' to 'long double' conversion
+   of glibc 2.7.  */
+_GL_EXTERN_C void _Qp_itoq (long double *, int);
+static void (*_gl_math_fix_itold) (long double *, int) = _Qp_itoq;
+#endif
+
+
 /* POSIX allows platforms that don't support NAN.  But all major
    machines in the past 15 years have supported something close to
    IEEE NaN, so we define this unconditionally.  We also must define
@@ -100,45 +146,21 @@ _NaN ()
 #endif
 
 
-/* Write x as
-     x = mantissa * 2^exp
-   where
-     If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
-     If x is zero: mantissa = x, exp = 0.
-     If x is infinite or NaN: mantissa = x, exp unspecified.
-   Store exp in *EXPPTR and return mantissa.  */
-#if @GNULIB_FREXP@
-# if @REPLACE_FREXP@
-#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#   define frexp rpl_frexp
-#  endif
-_GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL 
((2)));
-_GL_CXXALIAS_RPL (frexp, double, (double x, int *expptr));
-# else
-_GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr));
+#if @GNULIB_ACOSF@
+# if address@hidden@
+#  undef acosf
+_GL_FUNCDECL_SYS (acosf, float, (float x));
 # endif
-_GL_CXXALIASWARN (frexp);
+_GL_CXXALIAS_SYS (acosf, float, (float x));
+_GL_CXXALIASWARN (acosf);
 #elif defined GNULIB_POSIXCHECK
-# undef frexp
-/* Assume frexp is always declared.  */
-_GL_WARN_ON_USE (frexp, "frexp is unportable - "
-                 "use gnulib module frexp for portability");
-#endif
-
-
-#if @GNULIB_LOGB@
-# if address@hidden@
-_GL_EXTERN_C double logb (double x);
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef logb
-# if HAVE_RAW_DECL_LOGB
-_GL_WARN_ON_USE (logb, "logb is unportable - "
-                 "use gnulib module logb for portability");
+# undef acosf
+# if HAVE_RAW_DECL_ACOSF
+_GL_WARN_ON_USE (acosf, "acosf is unportable - "
+                 "use gnulib module acosf for portability");
 # endif
 #endif
 
-
 #if @GNULIB_ACOSL@
 # if address@hidden@ || address@hidden@
 _GL_FUNCDECL_SYS (acosl, long double, (long double x));
@@ -154,6 +176,21 @@ _GL_WARN_ON_USE (acosl, "acosl is unportable - "
 #endif
 
 
+#if @GNULIB_ASINF@
+# if address@hidden@
+#  undef asinf
+_GL_FUNCDECL_SYS (asinf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (asinf, float, (float x));
+_GL_CXXALIASWARN (asinf);
+#elif defined GNULIB_POSIXCHECK
+# undef asinf
+# if HAVE_RAW_DECL_ASINF
+_GL_WARN_ON_USE (asinf, "asinf is unportable - "
+                 "use gnulib module asinf for portability");
+# endif
+#endif
+
 #if @GNULIB_ASINL@
 # if address@hidden@ || address@hidden@
 _GL_FUNCDECL_SYS (asinl, long double, (long double x));
@@ -169,6 +206,21 @@ _GL_WARN_ON_USE (asinl, "asinl is unportable - "
 #endif
 
 
+#if @GNULIB_ATANF@
+# if address@hidden@
+#  undef atanf
+_GL_FUNCDECL_SYS (atanf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (atanf, float, (float x));
+_GL_CXXALIASWARN (atanf);
+#elif defined GNULIB_POSIXCHECK
+# undef atanf
+# if HAVE_RAW_DECL_ATANF
+_GL_WARN_ON_USE (atanf, "atanf is unportable - "
+                 "use gnulib module atanf for portability");
+# endif
+#endif
+
 #if @GNULIB_ATANL@
 # if address@hidden@ || address@hidden@
 _GL_FUNCDECL_SYS (atanl, long double, (long double x));
@@ -184,6 +236,22 @@ _GL_WARN_ON_USE (atanl, "atanl is unportable - "
 #endif
 
 
+#if @GNULIB_ATAN2F@
+# if address@hidden@
+#  undef atan2f
+_GL_FUNCDECL_SYS (atan2f, float, (float y, float x));
+# endif
+_GL_CXXALIAS_SYS (atan2f, float, (float y, float x));
+_GL_CXXALIASWARN (atan2f);
+#elif defined GNULIB_POSIXCHECK
+# undef atan2f
+# if HAVE_RAW_DECL_ATAN2F
+_GL_WARN_ON_USE (atan2f, "atan2f is unportable - "
+                 "use gnulib module atan2f for portability");
+# endif
+#endif
+
+
 #if @GNULIB_CEILF@
 # if @REPLACE_CEILF@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -244,6 +312,64 @@ _GL_WARN_ON_USE (ceill, "ceill is unportable - "
 #endif
 
 
+#if @GNULIB_COPYSIGNF@
+# if address@hidden@
+_GL_FUNCDECL_SYS (copysignf, float, (float x, float y));
+# endif
+_GL_CXXALIAS_SYS (copysignf, float, (float x, float y));
+_GL_CXXALIASWARN (copysignf);
+#elif defined GNULIB_POSIXCHECK
+# undef copysignf
+# if HAVE_RAW_DECL_COPYSIGNF
+_GL_WARN_ON_USE (copysignf, "copysignf is unportable - "
+                 "use gnulib module copysignf for portability");
+# endif
+#endif
+
+#if @GNULIB_COPYSIGN@
+# if address@hidden@
+_GL_FUNCDECL_SYS (copysign, double, (double x, double y));
+# endif
+_GL_CXXALIAS_SYS (copysign, double, (double x, double y));
+_GL_CXXALIASWARN (copysign);
+#elif defined GNULIB_POSIXCHECK
+# undef copysign
+# if HAVE_RAW_DECL_COPYSIGN
+_GL_WARN_ON_USE (copysign, "copysign is unportable - "
+                 "use gnulib module copysign for portability");
+# endif
+#endif
+
+#if @GNULIB_COPYSIGNL@
+# if address@hidden@
+_GL_FUNCDECL_SYS (copysignl, long double, (long double x, long double y));
+# endif
+_GL_CXXALIAS_SYS (copysignl, long double, (long double x, long double y));
+_GL_CXXALIASWARN (copysignl);
+#elif defined GNULIB_POSIXCHECK
+# undef copysignl
+# if HAVE_RAW_DECL_COPYSIGNL
+_GL_WARN_ON_USE (copysign, "copysignl is unportable - "
+                 "use gnulib module copysignl for portability");
+# endif
+#endif
+
+
+#if @GNULIB_COSF@
+# if address@hidden@
+#  undef cosf
+_GL_FUNCDECL_SYS (cosf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (cosf, float, (float x));
+_GL_CXXALIASWARN (cosf);
+#elif defined GNULIB_POSIXCHECK
+# undef cosf
+# if HAVE_RAW_DECL_COSF
+_GL_WARN_ON_USE (cosf, "cosf is unportable - "
+                 "use gnulib module cosf for portability");
+# endif
+#endif
+
 #if @GNULIB_COSL@
 # if address@hidden@ || address@hidden@
 _GL_FUNCDECL_SYS (cosl, long double, (long double x));
@@ -259,6 +385,37 @@ _GL_WARN_ON_USE (cosl, "cosl is unportable - "
 #endif
 
 
+#if @GNULIB_COSHF@
+# if address@hidden@
+#  undef coshf
+_GL_FUNCDECL_SYS (coshf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (coshf, float, (float x));
+_GL_CXXALIASWARN (coshf);
+#elif defined GNULIB_POSIXCHECK
+# undef coshf
+# if HAVE_RAW_DECL_COSHF
+_GL_WARN_ON_USE (coshf, "coshf is unportable - "
+                 "use gnulib module coshf for portability");
+# endif
+#endif
+
+
+#if @GNULIB_EXPF@
+# if address@hidden@
+#  undef expf
+_GL_FUNCDECL_SYS (expf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (expf, float, (float x));
+_GL_CXXALIASWARN (expf);
+#elif defined GNULIB_POSIXCHECK
+# undef expf
+# if HAVE_RAW_DECL_EXPF
+_GL_WARN_ON_USE (expf, "expf is unportable - "
+                 "use gnulib module expf for portability");
+# endif
+#endif
+
 #if @GNULIB_EXPL@
 # if address@hidden@ || address@hidden@
 _GL_FUNCDECL_SYS (expl, long double, (long double x));
@@ -274,6 +431,22 @@ _GL_WARN_ON_USE (expl, "expl is unportable - "
 #endif
 
 
+#if @GNULIB_FABSF@
+# if address@hidden@
+#  undef fabsf
+_GL_FUNCDECL_SYS (fabsf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (fabsf, float, (float x));
+_GL_CXXALIASWARN (fabsf);
+#elif defined GNULIB_POSIXCHECK
+# undef fabsf
+# if HAVE_RAW_DECL_FABSF
+_GL_WARN_ON_USE (fabsf, "fabsf is unportable - "
+                 "use gnulib module fabsf for portability");
+# endif
+#endif
+
+
 #if @GNULIB_FLOORF@
 # if @REPLACE_FLOORF@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -334,6 +507,152 @@ _GL_WARN_ON_USE (floorl, "floorl is unportable - "
 #endif
 
 
+#if @GNULIB_FMAF@
+# if @REPLACE_FMAF@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fmaf
+#   define fmaf rpl_fmaf
+#  endif
+_GL_FUNCDECL_RPL (fmaf, float, (float x, float y, float z));
+_GL_CXXALIAS_RPL (fmaf, float, (float x, float y, float z));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (fmaf, float, (float x, float y, float z));
+#  endif
+_GL_CXXALIAS_SYS (fmaf, float, (float x, float y, float z));
+# endif
+_GL_CXXALIASWARN (fmaf);
+#elif defined GNULIB_POSIXCHECK
+# undef fmaf
+# if HAVE_RAW_DECL_FMAF
+_GL_WARN_ON_USE (fmaf, "fmaf is unportable - "
+                 "use gnulib module fmaf for portability");
+# endif
+#endif
+
+#if @GNULIB_FMA@
+# if @REPLACE_FMA@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fma
+#   define fma rpl_fma
+#  endif
+_GL_FUNCDECL_RPL (fma, double, (double x, double y, double z));
+_GL_CXXALIAS_RPL (fma, double, (double x, double y, double z));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (fma, double, (double x, double y, double z));
+#  endif
+_GL_CXXALIAS_SYS (fma, double, (double x, double y, double z));
+# endif
+_GL_CXXALIASWARN (fma);
+#elif defined GNULIB_POSIXCHECK
+# undef fma
+# if HAVE_RAW_DECL_FMA
+_GL_WARN_ON_USE (fma, "fma is unportable - "
+                 "use gnulib module fma for portability");
+# endif
+#endif
+
+#if @GNULIB_FMAL@
+# if @REPLACE_FMAL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fmal
+#   define fmal rpl_fmal
+#  endif
+_GL_FUNCDECL_RPL (fmal, long double,
+                  (long double x, long double y, long double z));
+_GL_CXXALIAS_RPL (fmal, long double,
+                  (long double x, long double y, long double z));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (fmal, long double,
+                  (long double x, long double y, long double z));
+#  endif
+_GL_CXXALIAS_SYS (fmal, long double,
+                  (long double x, long double y, long double z));
+# endif
+_GL_CXXALIASWARN (fmal);
+#elif defined GNULIB_POSIXCHECK
+# undef fmal
+# if HAVE_RAW_DECL_FMAL
+_GL_WARN_ON_USE (fmal, "fmal is unportable - "
+                 "use gnulib module fmal for portability");
+# endif
+#endif
+
+
+#if @GNULIB_FMODF@
+# if address@hidden@
+#  undef fmodf
+_GL_FUNCDECL_SYS (fmodf, float, (float x, float y));
+# endif
+_GL_CXXALIAS_SYS (fmodf, float, (float x, float y));
+_GL_CXXALIASWARN (fmodf);
+#elif defined GNULIB_POSIXCHECK
+# undef fmodf
+# if HAVE_RAW_DECL_FMODF
+_GL_WARN_ON_USE (fmodf, "fmodf is unportable - "
+                 "use gnulib module fmodf for portability");
+# endif
+#endif
+
+
+/* Write x as
+     x = mantissa * 2^exp
+   where
+     If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
+     If x is zero: mantissa = x, exp = 0.
+     If x is infinite or NaN: mantissa = x, exp unspecified.
+   Store exp in *EXPPTR and return mantissa.  */
+#if @GNULIB_FREXPF@
+# if @REPLACE_FREXPF@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef frexpf
+#   define frexpf rpl_frexpf
+#  endif
+_GL_FUNCDECL_RPL (frexpf, float, (float x, int *expptr) _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (frexpf, float, (float x, int *expptr));
+# else
+#  if address@hidden@
+#   undef frexpf
+_GL_FUNCDECL_SYS (frexpf, float, (float x, int *expptr) _GL_ARG_NONNULL ((2)));
+#  endif
+_GL_CXXALIAS_SYS (frexpf, float, (float x, int *expptr));
+# endif
+_GL_CXXALIASWARN (frexpf);
+#elif defined GNULIB_POSIXCHECK
+# undef frexpf
+# if HAVE_RAW_DECL_FREXPF
+_GL_WARN_ON_USE (frexpf, "frexpf is unportable - "
+                 "use gnulib module frexpf for portability");
+# endif
+#endif
+
+/* Write x as
+     x = mantissa * 2^exp
+   where
+     If x finite and nonzero: 0.5 <= |mantissa| < 1.0.
+     If x is zero: mantissa = x, exp = 0.
+     If x is infinite or NaN: mantissa = x, exp unspecified.
+   Store exp in *EXPPTR and return mantissa.  */
+#if @GNULIB_FREXP@
+# if @REPLACE_FREXP@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define frexp rpl_frexp
+#  endif
+_GL_FUNCDECL_RPL (frexp, double, (double x, int *expptr) _GL_ARG_NONNULL 
((2)));
+_GL_CXXALIAS_RPL (frexp, double, (double x, int *expptr));
+# else
+_GL_CXXALIAS_SYS (frexp, double, (double x, int *expptr));
+# endif
+_GL_CXXALIASWARN (frexp);
+#elif defined GNULIB_POSIXCHECK
+# undef frexp
+/* Assume frexp is always declared.  */
+_GL_WARN_ON_USE (frexp, "frexp is unportable - "
+                 "use gnulib module frexp for portability");
+#endif
+
 /* Write x as
      x = mantissa * 2^exp
    where
@@ -371,6 +690,22 @@ _GL_WARN_ON_USE (frexpl, "frexpl is unportable - "
 
 
 /* Return x * 2^exp.  */
+#if @GNULIB_LDEXPF@
+# if address@hidden@
+#  undef ldexpf
+_GL_FUNCDECL_SYS (ldexpf, float, (float x, int exp));
+# endif
+_GL_CXXALIAS_SYS (ldexpf, float, (float x, int exp));
+_GL_CXXALIASWARN (ldexpf);
+#elif defined GNULIB_POSIXCHECK
+# undef ldexpf
+# if HAVE_RAW_DECL_LDEXPF
+_GL_WARN_ON_USE (ldexpf, "ldexpf is unportable - "
+                 "use gnulib module ldexpf for portability");
+# endif
+#endif
+
+/* Return x * 2^exp.  */
 #if @GNULIB_LDEXPL@ && @REPLACE_LDEXPL@
 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #  undef ldexpl
@@ -398,6 +733,34 @@ _GL_WARN_ON_USE (ldexpl, "ldexpl is unportable - "
 #endif
 
 
+#if @GNULIB_LOGB@
+# if address@hidden@
+_GL_EXTERN_C double logb (double x);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef logb
+# if HAVE_RAW_DECL_LOGB
+_GL_WARN_ON_USE (logb, "logb is unportable - "
+                 "use gnulib module logb for portability");
+# endif
+#endif
+
+
+#if @GNULIB_LOGF@
+# if address@hidden@
+#  undef logf
+_GL_FUNCDECL_SYS (logf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (logf, float, (float x));
+_GL_CXXALIASWARN (logf);
+#elif defined GNULIB_POSIXCHECK
+# undef logf
+# if HAVE_RAW_DECL_LOGF
+_GL_WARN_ON_USE (logf, "logf is unportable - "
+                 "use gnulib module logf for portability");
+# endif
+#endif
+
 #if @GNULIB_LOGL@
 # if address@hidden@ || address@hidden@
 _GL_FUNCDECL_SYS (logl, long double, (long double x));
@@ -413,6 +776,97 @@ _GL_WARN_ON_USE (logl, "logl is unportable - "
 #endif
 
 
+#if @GNULIB_LOG10F@
+# if address@hidden@
+#  undef log10f
+_GL_FUNCDECL_SYS (log10f, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (log10f, float, (float x));
+_GL_CXXALIASWARN (log10f);
+#elif defined GNULIB_POSIXCHECK
+# undef log10f
+# if HAVE_RAW_DECL_LOG10F
+_GL_WARN_ON_USE (log10f, "log10f is unportable - "
+                 "use gnulib module log10f for portability");
+# endif
+#endif
+
+
+#if @GNULIB_MODFF@
+# if address@hidden@
+#  undef modff
+_GL_FUNCDECL_SYS (modff, float, (float x, float *iptr) _GL_ARG_NONNULL ((2)));
+# endif
+_GL_CXXALIAS_SYS (modff, float, (float x, float *iptr));
+_GL_CXXALIASWARN (modff);
+#elif defined GNULIB_POSIXCHECK
+# undef modff
+# if HAVE_RAW_DECL_MODFF
+_GL_WARN_ON_USE (modff, "modff is unportable - "
+                 "use gnulib module modff for portability");
+# endif
+#endif
+
+
+#if @GNULIB_POWF@
+# if address@hidden@
+#  undef powf
+_GL_FUNCDECL_SYS (powf, float, (float x, float y));
+# endif
+_GL_CXXALIAS_SYS (powf, float, (float x, float y));
+_GL_CXXALIASWARN (powf);
+#elif defined GNULIB_POSIXCHECK
+# undef powf
+# if HAVE_RAW_DECL_POWF
+_GL_WARN_ON_USE (powf, "powf is unportable - "
+                 "use gnulib module powf for portability");
+# endif
+#endif
+
+
+#if @GNULIB_RINTF@
+# if address@hidden@
+_GL_FUNCDECL_SYS (rintf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (rintf, float, (float x));
+_GL_CXXALIASWARN (rintf);
+#elif defined GNULIB_POSIXCHECK
+# undef rintf
+# if HAVE_RAW_DECL_RINTF
+_GL_WARN_ON_USE (rintf, "rintf is unportable - "
+                 "use gnulib module rintf for portability");
+# endif
+#endif
+
+#if @GNULIB_RINT@
+# if address@hidden@
+_GL_FUNCDECL_SYS (rint, double, (double x));
+# endif
+_GL_CXXALIAS_SYS (rint, double, (double x));
+_GL_CXXALIASWARN (rint);
+#elif defined GNULIB_POSIXCHECK
+# undef rint
+# if HAVE_RAW_DECL_RINT
+_GL_WARN_ON_USE (rint, "rint is unportable - "
+                 "use gnulib module rint for portability");
+# endif
+#endif
+
+#if @GNULIB_RINTL@
+# if address@hidden@
+_GL_FUNCDECL_SYS (rintl, long double, (long double x));
+# endif
+_GL_CXXALIAS_SYS (rintl, long double, (long double x));
+_GL_CXXALIASWARN (rintl);
+#elif defined GNULIB_POSIXCHECK
+# undef rintl
+# if HAVE_RAW_DECL_RINTL
+_GL_WARN_ON_USE (rintl, "rintl is unportable - "
+                 "use gnulib module rintl for portability");
+# endif
+#endif
+
+
 #if @GNULIB_ROUNDF@
 # if @REPLACE_ROUNDF@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -483,6 +937,21 @@ _GL_WARN_ON_USE (roundl, "roundl is unportable - "
 #endif
 
 
+#if @GNULIB_SINF@
+# if address@hidden@
+#  undef sinf
+_GL_FUNCDECL_SYS (sinf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (sinf, float, (float x));
+_GL_CXXALIASWARN (sinf);
+#elif defined GNULIB_POSIXCHECK
+# undef sinf
+# if HAVE_RAW_DECL_SINF
+_GL_WARN_ON_USE (sinf, "sinf is unportable - "
+                 "use gnulib module sinf for portability");
+# endif
+#endif
+
 #if @GNULIB_SINL@
 # if address@hidden@ || address@hidden@
 _GL_FUNCDECL_SYS (sinl, long double, (long double x));
@@ -498,6 +967,37 @@ _GL_WARN_ON_USE (sinl, "sinl is unportable - "
 #endif
 
 
+#if @GNULIB_SINHF@
+# if address@hidden@
+#  undef sinhf
+_GL_FUNCDECL_SYS (sinhf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (sinhf, float, (float x));
+_GL_CXXALIASWARN (sinhf);
+#elif defined GNULIB_POSIXCHECK
+# undef sinhf
+# if HAVE_RAW_DECL_SINHF
+_GL_WARN_ON_USE (sinhf, "sinhf is unportable - "
+                 "use gnulib module sinhf for portability");
+# endif
+#endif
+
+
+#if @GNULIB_SQRTF@
+# if address@hidden@
+#  undef sqrtf
+_GL_FUNCDECL_SYS (sqrtf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (sqrtf, float, (float x));
+_GL_CXXALIASWARN (sqrtf);
+#elif defined GNULIB_POSIXCHECK
+# undef sqrtf
+# if HAVE_RAW_DECL_SQRTF
+_GL_WARN_ON_USE (sqrtf, "sqrtf is unportable - "
+                 "use gnulib module sqrtf for portability");
+# endif
+#endif
+
 #if @GNULIB_SQRTL@
 # if address@hidden@ || address@hidden@
 _GL_FUNCDECL_SYS (sqrtl, long double, (long double x));
@@ -513,6 +1013,21 @@ _GL_WARN_ON_USE (sqrtl, "sqrtl is unportable - "
 #endif
 
 
+#if @GNULIB_TANF@
+# if address@hidden@
+#  undef tanf
+_GL_FUNCDECL_SYS (tanf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (tanf, float, (float x));
+_GL_CXXALIASWARN (tanf);
+#elif defined GNULIB_POSIXCHECK
+# undef tanf
+# if HAVE_RAW_DECL_TANF
+_GL_WARN_ON_USE (tanf, "tanf is unportable - "
+                 "use gnulib module tanf for portability");
+# endif
+#endif
+
 #if @GNULIB_TANL@
 # if address@hidden@ || address@hidden@
 _GL_FUNCDECL_SYS (tanl, long double, (long double x));
@@ -528,6 +1043,22 @@ _GL_WARN_ON_USE (tanl, "tanl is unportable - "
 #endif
 
 
+#if @GNULIB_TANHF@
+# if address@hidden@
+#  undef tanhf
+_GL_FUNCDECL_SYS (tanhf, float, (float x));
+# endif
+_GL_CXXALIAS_SYS (tanhf, float, (float x));
+_GL_CXXALIASWARN (tanhf);
+#elif defined GNULIB_POSIXCHECK
+# undef tanhf
+# if HAVE_RAW_DECL_TANHF
+_GL_WARN_ON_USE (tanhf, "tanhf is unportable - "
+                 "use gnulib module tanhf for portability");
+# endif
+#endif
+
+
 #if @GNULIB_TRUNCF@
 # if @REPLACE_TRUNCF@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
@@ -596,6 +1127,10 @@ _GL_WARN_ON_USE (truncl, "truncl is unportable - "
 #endif
 
 
+/* Definitions of function-like macros come here, after the function
+   declarations.  */
+
+
 #if @GNULIB_ISFINITE@
 # if @REPLACE_ISFINITE@
 _GL_EXTERN_C int gl_isfinitef (float x);
@@ -607,6 +1142,13 @@ _GL_EXTERN_C int gl_isfinitel (long double x);
     sizeof (x) == sizeof (double) ? gl_isfinited (x) : \
     gl_isfinitef (x))
 # endif
+# ifdef __cplusplus
+#  ifdef isfinite
+_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isfinite)
+#   undef isfinite
+_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isfinite)
+#  endif
+# endif
 #elif defined GNULIB_POSIXCHECK
 # if defined isfinite
 _GL_WARN_REAL_FLOATING_DECL (isfinite);
@@ -627,6 +1169,13 @@ _GL_EXTERN_C int gl_isinfl (long double x);
     sizeof (x) == sizeof (double) ? gl_isinfd (x) : \
     gl_isinff (x))
 # endif
+# ifdef __cplusplus
+#  ifdef isinf
+_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isinf)
+#   undef isinf
+_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isinf)
+#  endif
+# endif
 #elif defined GNULIB_POSIXCHECK
 # if defined isinf
 _GL_WARN_REAL_FLOATING_DECL (isinf);
@@ -738,9 +1287,17 @@ _GL_EXTERN_C int rpl_isnanl (long double x);
     sizeof (x) == sizeof (double) ? __builtin_isnan ((double)(x)) : \
     __builtin_isnanf ((float)(x)))
 # endif
+# ifdef __cplusplus
+#  ifdef isnan
+_GL_MATH_CXX_REAL_FLOATING_DECL_1 (isnan)
+#   undef isnan
+_GL_MATH_CXX_REAL_FLOATING_DECL_2 (isnan)
+#  endif
+# else
 /* Ensure isnan is a macro.  */
-# ifndef isnan
-#  define isnan isnan
+#  ifndef isnan
+#   define isnan isnan
+#  endif
 # endif
 #elif defined GNULIB_POSIXCHECK
 # if defined isnan
@@ -765,7 +1322,7 @@ _GL_WARN_REAL_FLOATING_DECL (isnan);
 _GL_EXTERN_C int gl_signbitf (float arg);
 _GL_EXTERN_C int gl_signbitd (double arg);
 _GL_EXTERN_C int gl_signbitl (long double arg);
-#  if __GNUC__ >= 2 && !__STRICT_ANSI__
+#  if __GNUC__ >= 2 && !defined __STRICT_ANSI__
 #   define _GL_NUM_UINT_WORDS(type) \
       ((sizeof (type) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
 #   if defined FLT_SIGNBIT_WORD && defined FLT_SIGNBIT_BIT && !defined 
gl_signbitf
@@ -804,6 +1361,13 @@ _GL_EXTERN_C int gl_signbitl (long double arg);
     sizeof (x) == sizeof (double) ? gl_signbitd (x) : \
     gl_signbitf (x))
 # endif
+# ifdef __cplusplus
+#  ifdef signbit
+_GL_MATH_CXX_REAL_FLOATING_DECL_1 (signbit)
+#   undef signbit
+_GL_MATH_CXX_REAL_FLOATING_DECL_2 (signbit)
+#  endif
+# endif
 #elif defined GNULIB_POSIXCHECK
 # if defined signbit
 _GL_WARN_REAL_FLOATING_DECL (signbit);
diff --git a/gl/md5.c b/gl/md5.c
deleted file mode 100644
index b7fad63..0000000
--- a/gl/md5.c
+++ /dev/null
@@ -1,462 +0,0 @@
-/* Functions to compute MD5 message digest of files or memory blocks.
-   according to the definition of MD5 in RFC 1321 from April 1992.
-   Copyright (C) 1995-1997, 1999-2001, 2005-2006, 2008-2011 Free Software
-   Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 3, or (at your option) any
-   later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Ulrich Drepper <address@hidden>, 1995.  */
-
-#include <config.h>
-
-#include "md5.h"
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-
-#if USE_UNLOCKED_IO
-# include "unlocked-io.h"
-#endif
-
-#ifdef _LIBC
-# include <endian.h>
-# if __BYTE_ORDER == __BIG_ENDIAN
-#  define WORDS_BIGENDIAN 1
-# endif
-/* We need to keep the namespace clean so define the MD5 function
-   protected using leading __ .  */
-# define md5_init_ctx __md5_init_ctx
-# define md5_process_block __md5_process_block
-# define md5_process_bytes __md5_process_bytes
-# define md5_finish_ctx __md5_finish_ctx
-# define md5_read_ctx __md5_read_ctx
-# define md5_stream __md5_stream
-# define md5_buffer __md5_buffer
-#endif
-
-#ifdef WORDS_BIGENDIAN
-# define SWAP(n)                                                        \
-    (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
-#else
-# define SWAP(n) (n)
-#endif
-
-#define BLOCKSIZE 32768
-#if BLOCKSIZE % 64 != 0
-# error "invalid BLOCKSIZE"
-#endif
-
-/* This array contains the bytes used to pad the buffer to the next
-   64-byte boundary.  (RFC 1321, 3.1: Step 1)  */
-static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ...  */ };
-
-
-/* Initialize structure containing state of computation.
-   (RFC 1321, 3.3: Step 3)  */
-void
-md5_init_ctx (struct md5_ctx *ctx)
-{
-  ctx->A = 0x67452301;
-  ctx->B = 0xefcdab89;
-  ctx->C = 0x98badcfe;
-  ctx->D = 0x10325476;
-
-  ctx->total[0] = ctx->total[1] = 0;
-  ctx->buflen = 0;
-}
-
-/* Copy the 4 byte value from v into the memory location pointed to by *cp,
-   If your architecture allows unaligned access this is equivalent to
-   * (uint32_t *) cp = v  */
-static inline void
-set_uint32 (char *cp, uint32_t v)
-{
-  memcpy (cp, &v, sizeof v);
-}
-
-/* Put result from CTX in first 16 bytes following RESBUF.  The result
-   must be in little endian byte order.  */
-void *
-md5_read_ctx (const struct md5_ctx *ctx, void *resbuf)
-{
-  char *r = resbuf;
-  set_uint32 (r + 0 * sizeof ctx->A, SWAP (ctx->A));
-  set_uint32 (r + 1 * sizeof ctx->B, SWAP (ctx->B));
-  set_uint32 (r + 2 * sizeof ctx->C, SWAP (ctx->C));
-  set_uint32 (r + 3 * sizeof ctx->D, SWAP (ctx->D));
-
-  return resbuf;
-}
-
-/* Process the remaining bytes in the internal buffer and the usual
-   prolog according to the standard and write the result to RESBUF.  */
-void *
-md5_finish_ctx (struct md5_ctx *ctx, void *resbuf)
-{
-  /* Take yet unprocessed bytes into account.  */
-  uint32_t bytes = ctx->buflen;
-  size_t size = (bytes < 56) ? 64 / 4 : 64 * 2 / 4;
-
-  /* Now count remaining bytes.  */
-  ctx->total[0] += bytes;
-  if (ctx->total[0] < bytes)
-    ++ctx->total[1];
-
-  /* Put the 64-bit file length in *bits* at the end of the buffer.  */
-  ctx->buffer[size - 2] = SWAP (ctx->total[0] << 3);
-  ctx->buffer[size - 1] = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29));
-
-  memcpy (&((char *) ctx->buffer)[bytes], fillbuf, (size - 2) * 4 - bytes);
-
-  /* Process last bytes.  */
-  md5_process_block (ctx->buffer, size * 4, ctx);
-
-  return md5_read_ctx (ctx, resbuf);
-}
-
-/* Compute MD5 message digest for bytes read from STREAM.  The
-   resulting message digest number will be written into the 16 bytes
-   beginning at RESBLOCK.  */
-int
-md5_stream (FILE *stream, void *resblock)
-{
-  struct md5_ctx ctx;
-  size_t sum;
-
-  char *buffer = malloc (BLOCKSIZE + 72);
-  if (!buffer)
-    return 1;
-
-  /* Initialize the computation context.  */
-  md5_init_ctx (&ctx);
-
-  /* Iterate over full file contents.  */
-  while (1)
-    {
-      /* We read the file in blocks of BLOCKSIZE bytes.  One call of the
-         computation function processes the whole buffer so that with the
-         next round of the loop another block can be read.  */
-      size_t n;
-      sum = 0;
-
-      /* Read block.  Take care for partial reads.  */
-      while (1)
-        {
-          n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream);
-
-          sum += n;
-
-          if (sum == BLOCKSIZE)
-            break;
-
-          if (n == 0)
-            {
-              /* Check for the error flag IFF N == 0, so that we don't
-                 exit the loop after a partial read due to e.g., EAGAIN
-                 or EWOULDBLOCK.  */
-              if (ferror (stream))
-                {
-                  free (buffer);
-                  return 1;
-                }
-              goto process_partial_block;
-            }
-
-          /* We've read at least one byte, so ignore errors.  But always
-             check for EOF, since feof may be true even though N > 0.
-             Otherwise, we could end up calling fread after EOF.  */
-          if (feof (stream))
-            goto process_partial_block;
-        }
-
-      /* Process buffer with BLOCKSIZE bytes.  Note that
-         BLOCKSIZE % 64 == 0
-       */
-      md5_process_block (buffer, BLOCKSIZE, &ctx);
-    }
-
-process_partial_block:
-
-  /* Process any remaining bytes.  */
-  if (sum > 0)
-    md5_process_bytes (buffer, sum, &ctx);
-
-  /* Construct result in desired memory.  */
-  md5_finish_ctx (&ctx, resblock);
-  free (buffer);
-  return 0;
-}
-
-/* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
-   result is always in little endian byte order, so that a byte-wise
-   output yields to the wanted ASCII representation of the message
-   digest.  */
-void *
-md5_buffer (const char *buffer, size_t len, void *resblock)
-{
-  struct md5_ctx ctx;
-
-  /* Initialize the computation context.  */
-  md5_init_ctx (&ctx);
-
-  /* Process whole buffer but last len % 64 bytes.  */
-  md5_process_bytes (buffer, len, &ctx);
-
-  /* Put result in desired memory area.  */
-  return md5_finish_ctx (&ctx, resblock);
-}
-
-
-void
-md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx)
-{
-  /* When we already have some bits in our internal buffer concatenate
-     both inputs first.  */
-  if (ctx->buflen != 0)
-    {
-      size_t left_over = ctx->buflen;
-      size_t add = 128 - left_over > len ? len : 128 - left_over;
-
-      memcpy (&((char *) ctx->buffer)[left_over], buffer, add);
-      ctx->buflen += add;
-
-      if (ctx->buflen > 64)
-        {
-          md5_process_block (ctx->buffer, ctx->buflen & ~63, ctx);
-
-          ctx->buflen &= 63;
-          /* The regions in the following copy operation cannot overlap.  */
-          memcpy (ctx->buffer,
-                  &((char *) ctx->buffer)[(left_over + add) & ~63],
-                  ctx->buflen);
-        }
-
-      buffer = (const char *) buffer + add;
-      len -= add;
-    }
-
-  /* Process available complete blocks.  */
-  if (len >= 64)
-    {
-#if !_STRING_ARCH_unaligned
-# define alignof(type) offsetof (struct { char c; type x; }, x)
-# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
-      if (UNALIGNED_P (buffer))
-        while (len > 64)
-          {
-            md5_process_block (memcpy (ctx->buffer, buffer, 64), 64, ctx);
-            buffer = (const char *) buffer + 64;
-            len -= 64;
-          }
-      else
-#endif
-        {
-          md5_process_block (buffer, len & ~63, ctx);
-          buffer = (const char *) buffer + (len & ~63);
-          len &= 63;
-        }
-    }
-
-  /* Move remaining bytes in internal buffer.  */
-  if (len > 0)
-    {
-      size_t left_over = ctx->buflen;
-
-      memcpy (&((char *) ctx->buffer)[left_over], buffer, len);
-      left_over += len;
-      if (left_over >= 64)
-        {
-          md5_process_block (ctx->buffer, 64, ctx);
-          left_over -= 64;
-          memcpy (ctx->buffer, &ctx->buffer[16], left_over);
-        }
-      ctx->buflen = left_over;
-    }
-}
-
-
-/* These are the four functions used in the four steps of the MD5 algorithm
-   and defined in the RFC 1321.  The first function is a little bit optimized
-   (as found in Colin Plumbs public domain implementation).  */
-/* #define FF(b, c, d) ((b & c) | (~b & d)) */
-#define FF(b, c, d) (d ^ (b & (c ^ d)))
-#define FG(b, c, d) FF (d, b, c)
-#define FH(b, c, d) (b ^ c ^ d)
-#define FI(b, c, d) (c ^ (b | ~d))
-
-/* Process LEN bytes of BUFFER, accumulating context into CTX.
-   It is assumed that LEN % 64 == 0.  */
-
-void
-md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx)
-{
-  uint32_t correct_words[16];
-  const uint32_t *words = buffer;
-  size_t nwords = len / sizeof (uint32_t);
-  const uint32_t *endp = words + nwords;
-  uint32_t A = ctx->A;
-  uint32_t B = ctx->B;
-  uint32_t C = ctx->C;
-  uint32_t D = ctx->D;
-
-  /* First increment the byte count.  RFC 1321 specifies the possible
-     length of the file up to 2^64 bits.  Here we only compute the
-     number of bytes.  Do a double word increment.  */
-  ctx->total[0] += len;
-  if (ctx->total[0] < len)
-    ++ctx->total[1];
-
-  /* Process all bytes in the buffer with 64 bytes in each round of
-     the loop.  */
-  while (words < endp)
-    {
-      uint32_t *cwp = correct_words;
-      uint32_t A_save = A;
-      uint32_t B_save = B;
-      uint32_t C_save = C;
-      uint32_t D_save = D;
-
-      /* First round: using the given function, the context and a constant
-         the next context is computed.  Because the algorithms processing
-         unit is a 32-bit word and it is determined to work on words in
-         little endian byte order we perhaps have to change the byte order
-         before the computation.  To reduce the work for the next steps
-         we store the swapped words in the array CORRECT_WORDS.  */
-
-#define OP(a, b, c, d, s, T)                                            \
-      do                                                                \
-        {                                                               \
-          a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T;             \
-          ++words;                                                      \
-          CYCLIC (a, s);                                                \
-          a += b;                                                       \
-        }                                                               \
-      while (0)
-
-      /* It is unfortunate that C does not provide an operator for
-         cyclic rotation.  Hope the C compiler is smart enough.  */
-#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s)))
-
-      /* Before we start, one word to the strange constants.
-         They are defined in RFC 1321 as
-
-         T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64
-
-         Here is an equivalent invocation using Perl:
-
-         perl -e 'foreach(1..64){printf "0x%08x\n", int (4294967296 * abs (sin 
$_))}'
-       */
-
-      /* Round 1.  */
-      OP (A, B, C, D, 7, 0xd76aa478);
-      OP (D, A, B, C, 12, 0xe8c7b756);
-      OP (C, D, A, B, 17, 0x242070db);
-      OP (B, C, D, A, 22, 0xc1bdceee);
-      OP (A, B, C, D, 7, 0xf57c0faf);
-      OP (D, A, B, C, 12, 0x4787c62a);
-      OP (C, D, A, B, 17, 0xa8304613);
-      OP (B, C, D, A, 22, 0xfd469501);
-      OP (A, B, C, D, 7, 0x698098d8);
-      OP (D, A, B, C, 12, 0x8b44f7af);
-      OP (C, D, A, B, 17, 0xffff5bb1);
-      OP (B, C, D, A, 22, 0x895cd7be);
-      OP (A, B, C, D, 7, 0x6b901122);
-      OP (D, A, B, C, 12, 0xfd987193);
-      OP (C, D, A, B, 17, 0xa679438e);
-      OP (B, C, D, A, 22, 0x49b40821);
-
-      /* For the second to fourth round we have the possibly swapped words
-         in CORRECT_WORDS.  Redefine the macro to take an additional first
-         argument specifying the function to use.  */
-#undef OP
-#define OP(f, a, b, c, d, k, s, T)                                      \
-      do                                                                \
-        {                                                               \
-          a += f (b, c, d) + correct_words[k] + T;                      \
-          CYCLIC (a, s);                                                \
-          a += b;                                                       \
-        }                                                               \
-      while (0)
-
-      /* Round 2.  */
-      OP (FG, A, B, C, D, 1, 5, 0xf61e2562);
-      OP (FG, D, A, B, C, 6, 9, 0xc040b340);
-      OP (FG, C, D, A, B, 11, 14, 0x265e5a51);
-      OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa);
-      OP (FG, A, B, C, D, 5, 5, 0xd62f105d);
-      OP (FG, D, A, B, C, 10, 9, 0x02441453);
-      OP (FG, C, D, A, B, 15, 14, 0xd8a1e681);
-      OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8);
-      OP (FG, A, B, C, D, 9, 5, 0x21e1cde6);
-      OP (FG, D, A, B, C, 14, 9, 0xc33707d6);
-      OP (FG, C, D, A, B, 3, 14, 0xf4d50d87);
-      OP (FG, B, C, D, A, 8, 20, 0x455a14ed);
-      OP (FG, A, B, C, D, 13, 5, 0xa9e3e905);
-      OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8);
-      OP (FG, C, D, A, B, 7, 14, 0x676f02d9);
-      OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a);
-
-      /* Round 3.  */
-      OP (FH, A, B, C, D, 5, 4, 0xfffa3942);
-      OP (FH, D, A, B, C, 8, 11, 0x8771f681);
-      OP (FH, C, D, A, B, 11, 16, 0x6d9d6122);
-      OP (FH, B, C, D, A, 14, 23, 0xfde5380c);
-      OP (FH, A, B, C, D, 1, 4, 0xa4beea44);
-      OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9);
-      OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60);
-      OP (FH, B, C, D, A, 10, 23, 0xbebfbc70);
-      OP (FH, A, B, C, D, 13, 4, 0x289b7ec6);
-      OP (FH, D, A, B, C, 0, 11, 0xeaa127fa);
-      OP (FH, C, D, A, B, 3, 16, 0xd4ef3085);
-      OP (FH, B, C, D, A, 6, 23, 0x04881d05);
-      OP (FH, A, B, C, D, 9, 4, 0xd9d4d039);
-      OP (FH, D, A, B, C, 12, 11, 0xe6db99e5);
-      OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8);
-      OP (FH, B, C, D, A, 2, 23, 0xc4ac5665);
-
-      /* Round 4.  */
-      OP (FI, A, B, C, D, 0, 6, 0xf4292244);
-      OP (FI, D, A, B, C, 7, 10, 0x432aff97);
-      OP (FI, C, D, A, B, 14, 15, 0xab9423a7);
-      OP (FI, B, C, D, A, 5, 21, 0xfc93a039);
-      OP (FI, A, B, C, D, 12, 6, 0x655b59c3);
-      OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92);
-      OP (FI, C, D, A, B, 10, 15, 0xffeff47d);
-      OP (FI, B, C, D, A, 1, 21, 0x85845dd1);
-      OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f);
-      OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0);
-      OP (FI, C, D, A, B, 6, 15, 0xa3014314);
-      OP (FI, B, C, D, A, 13, 21, 0x4e0811a1);
-      OP (FI, A, B, C, D, 4, 6, 0xf7537e82);
-      OP (FI, D, A, B, C, 11, 10, 0xbd3af235);
-      OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb);
-      OP (FI, B, C, D, A, 9, 21, 0xeb86d391);
-
-      /* Add the starting values of the context.  */
-      A += A_save;
-      B += B_save;
-      C += C_save;
-      D += D_save;
-    }
-
-  /* Put checksum in context given as argument.  */
-  ctx->A = A;
-  ctx->B = B;
-  ctx->C = C;
-  ctx->D = D;
-}
diff --git a/gl/md5.h b/gl/md5.h
deleted file mode 100644
index 53e6048..0000000
--- a/gl/md5.h
+++ /dev/null
@@ -1,126 +0,0 @@
-/* Declaration of functions and data types used for MD5 sum computing
-   library functions.
-   Copyright (C) 1995-1997, 1999-2001, 2004-2006, 2008-2011 Free Software
-   Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 3, or (at your option) any
-   later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef _MD5_H
-#define _MD5_H 1
-
-#include <stdio.h>
-#include <stdint.h>
-
-#define MD5_DIGEST_SIZE 16
-#define MD5_BLOCK_SIZE 64
-
-#ifndef __GNUC_PREREQ
-# if defined __GNUC__ && defined __GNUC_MINOR__
-#  define __GNUC_PREREQ(maj, min)                                       \
-  ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
-# else
-#  define __GNUC_PREREQ(maj, min) 0
-# endif
-#endif
-
-#ifndef __THROW
-# if defined __cplusplus && __GNUC_PREREQ (2,8)
-#  define __THROW       throw ()
-# else
-#  define __THROW
-# endif
-#endif
-
-#ifndef _LIBC
-# define __md5_buffer md5_buffer
-# define __md5_finish_ctx md5_finish_ctx
-# define __md5_init_ctx md5_init_ctx
-# define __md5_process_block md5_process_block
-# define __md5_process_bytes md5_process_bytes
-# define __md5_read_ctx md5_read_ctx
-# define __md5_stream md5_stream
-#endif
-
-# ifdef __cplusplus
-extern "C" {
-# endif
-
-/* Structure to save state of computation between the single steps.  */
-struct md5_ctx
-{
-  uint32_t A;
-  uint32_t B;
-  uint32_t C;
-  uint32_t D;
-
-  uint32_t total[2];
-  uint32_t buflen;
-  uint32_t buffer[32];
-};
-
-/*
- * The following three functions are build up the low level used in
- * the functions `md5_stream' and `md5_buffer'.
- */
-
-/* Initialize structure containing state of computation.
-   (RFC 1321, 3.3: Step 3)  */
-extern void __md5_init_ctx (struct md5_ctx *ctx) __THROW;
-
-/* Starting with the result of former calls of this function (or the
-   initialization function update the context for the next LEN bytes
-   starting at BUFFER.
-   It is necessary that LEN is a multiple of 64!!! */
-extern void __md5_process_block (const void *buffer, size_t len,
-                                 struct md5_ctx *ctx) __THROW;
-
-/* Starting with the result of former calls of this function (or the
-   initialization function update the context for the next LEN bytes
-   starting at BUFFER.
-   It is NOT required that LEN is a multiple of 64.  */
-extern void __md5_process_bytes (const void *buffer, size_t len,
-                                 struct md5_ctx *ctx) __THROW;
-
-/* Process the remaining bytes in the buffer and put result from CTX
-   in first 16 bytes following RESBUF.  The result is always in little
-   endian byte order, so that a byte-wise output yields to the wanted
-   ASCII representation of the message digest.  */
-extern void *__md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) __THROW;
-
-
-/* Put result from CTX in first 16 bytes following RESBUF.  The result is
-   always in little endian byte order, so that a byte-wise output yields
-   to the wanted ASCII representation of the message digest.  */
-extern void *__md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) __THROW;
-
-
-/* Compute MD5 message digest for bytes read from STREAM.  The
-   resulting message digest number will be written into the 16 bytes
-   beginning at RESBLOCK.  */
-extern int __md5_stream (FILE *stream, void *resblock) __THROW;
-
-/* Compute MD5 message digest for LEN bytes beginning at BUFFER.  The
-   result is always in little endian byte order, so that a byte-wise
-   output yields to the wanted ASCII representation of the message
-   digest.  */
-extern void *__md5_buffer (const char *buffer, size_t len,
-                           void *resblock) __THROW;
-
-# ifdef __cplusplus
-}
-# endif
-
-#endif /* md5.h */
diff --git a/gl/memxor.c b/gl/memxor.c
deleted file mode 100644
index b80b430..0000000
--- a/gl/memxor.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/* memxor.c -- perform binary exclusive OR operation of two memory blocks.
-   Copyright (C) 2005-2006, 2009-2011 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Simon Josefsson.  The interface was inspired by memxor
-   in Niels Möller's Nettle. */
-
-#include <config.h>
-
-#include "memxor.h"
-
-void *
-gl_memxor (void *restrict dest, const void *restrict src, size_t n)
-{
-  char const *s = src;
-  char *d = dest;
-
-  for (; n > 0; n--)
-    *d++ ^= *s++;
-
-  return dest;
-}
diff --git a/gl/memxor.h b/gl/memxor.h
deleted file mode 100644
index fbf2ac3..0000000
--- a/gl/memxor.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* memxor.h -- perform binary exclusive OR operation on memory blocks.
-   Copyright (C) 2005, 2009-2011 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-/* Written by Simon Josefsson.  The interface was inspired by memxor
-   in Niels Möller's Nettle. */
-
-#ifndef MEMXOR_H
-# define MEMXOR_H
-
-#include <stddef.h>
-
-/* Compute binary exclusive OR of memory areas DEST and SRC, putting
-   the result in DEST, of length N bytes.  Returns a pointer to
-   DEST. */
-void *gl_memxor (void *restrict dest, const void *restrict src, size_t n);
-
-#endif /* MEMXOR_H */
diff --git a/gl/msvc-inval.c b/gl/msvc-inval.c
new file mode 100644
index 0000000..d10099e
--- /dev/null
+++ b/gl/msvc-inval.c
@@ -0,0 +1,130 @@
+/* Invalid parameter handler for MSVC runtime libraries.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "msvc-inval.h"
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+    && !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
+
+/* Get _invalid_parameter_handler type and _set_invalid_parameter_handler
+   declaration.  */
+# include <stdlib.h>
+
+# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+
+static void cdecl
+gl_msvc_invalid_parameter_handler (const wchar_t *expression,
+                                   const wchar_t *function,
+                                   const wchar_t *file,
+                                   unsigned int line,
+                                   uintptr_t dummy)
+{
+}
+
+# else
+
+/* Get declarations of the Win32 API functions.  */
+#  define WIN32_LEAN_AND_MEAN
+#  include <windows.h>
+
+#  if defined _MSC_VER
+
+static void cdecl
+gl_msvc_invalid_parameter_handler (const wchar_t *expression,
+                                   const wchar_t *function,
+                                   const wchar_t *file,
+                                   unsigned int line,
+                                   uintptr_t dummy)
+{
+  RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
+}
+
+#  else
+
+/* An index to thread-local storage.  */
+static DWORD tls_index;
+static int tls_initialized /* = 0 */;
+
+/* Used as a fallback only.  */
+static struct gl_msvc_inval_per_thread not_per_thread;
+
+struct gl_msvc_inval_per_thread *
+gl_msvc_inval_current (void)
+{
+  if (!tls_initialized)
+    {
+      tls_index = TlsAlloc ();
+      tls_initialized = 1;
+    }
+  if (tls_index == TLS_OUT_OF_INDEXES)
+    /* TlsAlloc had failed.  */
+    return &not_per_thread;
+  else
+    {
+      struct gl_msvc_inval_per_thread *pointer =
+        (struct gl_msvc_inval_per_thread *) TlsGetValue (tls_index);
+      if (pointer == NULL)
+        {
+          /* First call.  Allocate a new 'struct gl_msvc_inval_per_thread'.  */
+          pointer =
+            (struct gl_msvc_inval_per_thread *)
+            malloc (sizeof (struct gl_msvc_inval_per_thread));
+          if (pointer == NULL)
+            /* Could not allocate memory.  Use the global storage.  */
+            pointer = &not_per_thread;
+          TlsSetValue (tls_index, pointer);
+        }
+      return pointer;
+    }
+}
+
+static void cdecl
+gl_msvc_invalid_parameter_handler (const wchar_t *expression,
+                                   const wchar_t *function,
+                                   const wchar_t *file,
+                                   unsigned int line,
+                                   uintptr_t dummy)
+{
+  struct gl_msvc_inval_per_thread *current = gl_msvc_inval_current ();
+  if (current->restart_valid)
+    longjmp (current->restart, 1);
+  else
+    /* An invalid parameter notification from outside the gnulib code.
+       Give the caller a chance to intervene.  */
+    RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
+}
+
+#  endif
+
+# endif
+
+static int gl_msvc_inval_initialized /* = 0 */;
+
+void
+gl_msvc_inval_ensure_handler (void)
+{
+  if (gl_msvc_inval_initialized == 0)
+    {
+      _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
+      gl_msvc_inval_initialized = 1;
+    }
+}
+
+#endif
diff --git a/gl/msvc-inval.h b/gl/msvc-inval.h
new file mode 100644
index 0000000..393272e
--- /dev/null
+++ b/gl/msvc-inval.h
@@ -0,0 +1,223 @@
+/* Invalid parameter handler for MSVC runtime libraries.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifndef _MSVC_INVAL_H
+#define _MSVC_INVAL_H
+
+/* With MSVC runtime libraries with the "invalid parameter handler" concept,
+   functions like fprintf(), dup2(), or close() crash when the caller passes
+   an invalid argument.  But POSIX wants error codes (such as EINVAL or EBADF)
+   instead.
+   This file defines macros that turn such an invalid parameter notification
+   into a non-local exit.  An error code can then be produced at the target
+   of this exit.  You can thus write code like
+
+     TRY_MSVC_INVAL
+       {
+         <Code that can trigger an invalid parameter notification
+          but does not do 'return', 'break', 'continue', nor 'goto'.>
+       }
+     CATCH_MSVC_INVAL
+       {
+         <Code that handles an invalid parameter notification
+          but does not do 'return', 'break', 'continue', nor 'goto'.>
+       }
+     DONE_MSVC_INVAL;
+
+   This entire block expands to a single statement.
+
+   The handling of invalid parameters can be done in three ways:
+
+     * The default way, which is reasonable for programs (not libraries):
+       AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [DEFAULT_HANDLING])
+
+     * The way for libraries that make "hairy" calls (like close(-1), or
+       fclose(fp) where fileno(fp) is closed, or simply getdtablesize()):
+       AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [HAIRY_LIBRARY_HANDLING])
+
+     * The way for libraries that make no "hairy" calls:
+       AC_DEFINE([MSVC_INVALID_PARAMETER_HANDLING], [SANE_LIBRARY_HANDLING])
+ */
+
+#define DEFAULT_HANDLING       0
+#define HAIRY_LIBRARY_HANDLING 1
+#define SANE_LIBRARY_HANDLING  2
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+    && !(MSVC_INVALID_PARAMETER_HANDLING == SANE_LIBRARY_HANDLING)
+/* A native Windows platform with the "invalid parameter handler" concept,
+   and either DEFAULT_HANDLING or HAIRY_LIBRARY_HANDLING.  */
+
+# if MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+/* Default handling.  */
+
+#  ifdef __cplusplus
+extern "C" {
+#  endif
+
+/* Ensure that the invalid parameter handler in installed that just returns.
+   Because we assume no other part of the program installs a different
+   invalid parameter handler, this solution is multithread-safe.  */
+extern void gl_msvc_inval_ensure_handler (void);
+
+#  ifdef __cplusplus
+}
+#  endif
+
+#  define TRY_MSVC_INVAL \
+     do                                                                        
\
+       {                                                                       
\
+         gl_msvc_inval_ensure_handler ();                                      
\
+         if (1)
+#  define CATCH_MSVC_INVAL \
+         else
+#  define DONE_MSVC_INVAL \
+       }                                                                       
\
+     while (0)
+
+# else
+/* Handling for hairy libraries.  */
+
+#  include <excpt.h>
+
+/* Gnulib can define its own status codes, as described in the page
+   "Raising Software Exceptions" on microsoft.com
+   <http://msdn.microsoft.com/en-us/library/het71c37.aspx>.
+   Our status codes are composed of
+     - 0xE0000000, mandatory for all user-defined status codes,
+     - 0x474E550, a API identifier ("GNU"),
+     - 0, 1, 2, ..., used to distinguish different status codes from the
+       same API.  */
+#  define STATUS_GNULIB_INVALID_PARAMETER (0xE0000000 + 0x474E550 + 0)
+
+#  if defined _MSC_VER
+/* A compiler that supports __try/__except, as described in the page
+   "try-except statement" on microsoft.com
+   <http://msdn.microsoft.com/en-us/library/s58ftw19.aspx>.
+   With __try/__except, we can use the multithread-safe exception handling.  */
+
+#   ifdef __cplusplus
+extern "C" {
+#   endif
+
+/* Ensure that the invalid parameter handler in installed that raises a
+   software exception with code STATUS_GNULIB_INVALID_PARAMETER.
+   Because we assume no other part of the program installs a different
+   invalid parameter handler, this solution is multithread-safe.  */
+extern void gl_msvc_inval_ensure_handler (void);
+
+#   ifdef __cplusplus
+}
+#   endif
+
+#   define TRY_MSVC_INVAL \
+      do                                                                       
\
+        {                                                                      
\
+          gl_msvc_inval_ensure_handler ();                                     
\
+          __try
+#   define CATCH_MSVC_INVAL \
+          __except (GetExceptionCode () == STATUS_GNULIB_INVALID_PARAMETER     
\
+                    ? EXCEPTION_EXECUTE_HANDLER                                
\
+                    : EXCEPTION_CONTINUE_SEARCH)
+#   define DONE_MSVC_INVAL \
+        }                                                                      
\
+      while (0)
+
+#  else
+/* Any compiler.
+   We can only use setjmp/longjmp.  */
+
+#   include <setjmp.h>
+
+#   ifdef __cplusplus
+extern "C" {
+#   endif
+
+struct gl_msvc_inval_per_thread
+{
+  /* The restart that will resume execution at the code between
+     CATCH_MSVC_INVAL and DONE_MSVC_INVAL.  It is enabled only between
+     TRY_MSVC_INVAL and CATCH_MSVC_INVAL.  */
+  jmp_buf restart;
+
+  /* Tells whether the contents of restart is valid.  */
+  int restart_valid;
+};
+
+/* Ensure that the invalid parameter handler in installed that passes
+   control to the gl_msvc_inval_restart if it is valid, or raises a
+   software exception with code STATUS_GNULIB_INVALID_PARAMETER otherwise.
+   Because we assume no other part of the program installs a different
+   invalid parameter handler, this solution is multithread-safe.  */
+extern void gl_msvc_inval_ensure_handler (void);
+
+/* Return a pointer to the per-thread data for the current thread.  */
+extern struct gl_msvc_inval_per_thread *gl_msvc_inval_current (void);
+
+#   ifdef __cplusplus
+}
+#   endif
+
+#   define TRY_MSVC_INVAL \
+      do                                                                       
\
+        {                                                                      
\
+          struct gl_msvc_inval_per_thread *msvc_inval_current;                 
\
+          gl_msvc_inval_ensure_handler ();                                     
\
+          msvc_inval_current = gl_msvc_inval_current ();                       
\
+          /* First, initialize gl_msvc_inval_restart.  */                      
\
+          if (setjmp (msvc_inval_current->restart) == 0)                       
\
+            {                                                                  
\
+              /* Then, mark it as valid.  */                                   
\
+              msvc_inval_current->restart_valid = 1;
+#   define CATCH_MSVC_INVAL \
+              /* Execution completed.                                          
\
+                 Mark gl_msvc_inval_restart as invalid.  */                    
\
+              msvc_inval_current->restart_valid = 0;                           
\
+            }                                                                  
\
+          else                                                                 
\
+            {                                                                  
\
+              /* Execution triggered an invalid parameter notification.        
\
+                 Mark gl_msvc_inval_restart as invalid.  */                    
\
+              msvc_inval_current->restart_valid = 0;
+#   define DONE_MSVC_INVAL \
+            }                                                                  
\
+        }                                                                      
\
+      while (0)
+
+#  endif
+
+# endif
+
+#else
+/* A platform that does not need to the invalid parameter handler,
+   or when SANE_LIBRARY_HANDLING is desired.  */
+
+/* The braces here avoid GCC warnings like
+   "warning: suggest explicit braces to avoid ambiguous `else'".  */
+# define TRY_MSVC_INVAL \
+    do                                                                         
\
+      {                                                                        
\
+        if (1)
+# define CATCH_MSVC_INVAL \
+        else
+# define DONE_MSVC_INVAL \
+      }                                                                        
\
+    while (0)
+
+#endif
+
+#endif /* _MSVC_INVAL_H */
diff --git a/gl/msvc-nothrow.c b/gl/msvc-nothrow.c
new file mode 100644
index 0000000..8965140
--- /dev/null
+++ b/gl/msvc-nothrow.c
@@ -0,0 +1,50 @@
+/* Wrappers that don't throw invalid parameter notifications
+   with MSVC runtime libraries.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "msvc-nothrow.h"
+
+/* Get declarations of the Win32 API functions.  */
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#include "msvc-inval.h"
+
+#undef _get_osfhandle
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+intptr_t
+_gl_nothrow_get_osfhandle (int fd)
+{
+  intptr_t result;
+
+  TRY_MSVC_INVAL
+    {
+      result = _get_osfhandle (fd);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = (intptr_t) INVALID_HANDLE_VALUE;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#endif
diff --git a/gl/msvc-nothrow.h b/gl/msvc-nothrow.h
new file mode 100644
index 0000000..462fb67
--- /dev/null
+++ b/gl/msvc-nothrow.h
@@ -0,0 +1,44 @@
+/* Wrappers that don't throw invalid parameter notifications
+   with MSVC runtime libraries.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifndef _MSVC_NOTHROW_H
+#define _MSVC_NOTHROW_H
+
+/* With MSVC runtime libraries with the "invalid parameter handler" concept,
+   functions like fprintf(), dup2(), or close() crash when the caller passes
+   an invalid argument.  But POSIX wants error codes (such as EINVAL or EBADF)
+   instead.
+   This file defines wrappers that turn such an invalid parameter notification
+   into an error code.  */
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* Get original declaration of _get_osfhandle.  */
+# include <io.h>
+
+# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+
+/* Override _get_osfhandle.  */
+extern intptr_t _gl_nothrow_get_osfhandle (int fd);
+#  define _get_osfhandle _gl_nothrow_get_osfhandle
+
+# endif
+
+#endif
+
+#endif /* _MSVC_NOTHROW_H */
diff --git a/gl/opendir.c b/gl/opendir.c
index 06c611f..20ae75e 100644
--- a/gl/opendir.c
+++ b/gl/opendir.c
@@ -20,6 +20,7 @@
 #include <dirent.h>
 
 #include <errno.h>
+#include <stddef.h>
 
 #if HAVE_OPENDIR
 
@@ -28,7 +29,6 @@
 
 #else
 
-# include <stddef.h>
 # include <stdlib.h>
 
 # include "dirent-private.h"
@@ -36,6 +36,10 @@
 
 #endif
 
+#if REPLACE_FCHDIR
+# include <unistd.h>
+#endif
+
 DIR *
 opendir (const char *dir_name)
 {
diff --git a/gl/override/lib/gettext.h.diff b/gl/override/lib/gettext.h.diff
deleted file mode 100644
index 78c04c1..0000000
--- a/gl/override/lib/gettext.h.diff
+++ /dev/null
@@ -1,112 +0,0 @@
---- gl/gettext.h.orig  2010-01-26 15:37:52.000000000 +0100
-+++ gl/gettext.h       2010-01-26 15:37:59.000000000 +0100
-@@ -172,109 +172,4 @@
-     return translation;
- }
- 
--/* The same thing extended for non-constant arguments.  Here MSGCTXT and MSGID
--   can be arbitrary expressions.  But for string literals these macros are
--   less efficient than those above.  */
--
--#include <string.h>
--
--#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
--  (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \
--   /* || __STDC_VERSION__ >= 199901L */ )
--
--#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
--#include <stdlib.h>
--#endif
--
--#define pgettext_expr(Msgctxt, Msgid) \
--  dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
--#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
--  dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
--
--#ifdef __GNUC__
--__inline
--#else
--#ifdef __cplusplus
--inline
--#endif
--#endif
--static const char *
--dcpgettext_expr (const char *domain,
--                 const char *msgctxt, const char *msgid,
--                 int category)
--{
--  size_t msgctxt_len = strlen (msgctxt) + 1;
--  size_t msgid_len = strlen (msgid) + 1;
--  const char *translation;
--#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
--  char msg_ctxt_id[msgctxt_len + msgid_len];
--#else
--  char buf[1024];
--  char *msg_ctxt_id =
--    (msgctxt_len + msgid_len <= sizeof (buf)
--     ? buf
--     : (char *) malloc (msgctxt_len + msgid_len));
--  if (msg_ctxt_id != NULL)
--#endif
--    {
--      memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
--      msg_ctxt_id[msgctxt_len - 1] = '\004';
--      memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
--      translation = dcgettext (domain, msg_ctxt_id, category);
--#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
--      if (msg_ctxt_id != buf)
--        free (msg_ctxt_id);
--#endif
--      if (translation != msg_ctxt_id)
--        return translation;
--    }
--  return msgid;
--}
--
--#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
--  dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
--#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
--  dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
--
--#ifdef __GNUC__
--__inline
--#else
--#ifdef __cplusplus
--inline
--#endif
--#endif
--static const char *
--dcnpgettext_expr (const char *domain,
--                  const char *msgctxt, const char *msgid,
--                  const char *msgid_plural, unsigned long int n,
--                  int category)
--{
--  size_t msgctxt_len = strlen (msgctxt) + 1;
--  size_t msgid_len = strlen (msgid) + 1;
--  const char *translation;
--#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
--  char msg_ctxt_id[msgctxt_len + msgid_len];
--#else
--  char buf[1024];
--  char *msg_ctxt_id =
--    (msgctxt_len + msgid_len <= sizeof (buf)
--     ? buf
--     : (char *) malloc (msgctxt_len + msgid_len));
--  if (msg_ctxt_id != NULL)
--#endif
--    {
--      memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
--      msg_ctxt_id[msgctxt_len - 1] = '\004';
--      memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
--      translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, 
category);
--#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
--      if (msg_ctxt_id != buf)
--        free (msg_ctxt_id);
--#endif
--      if (!(translation == msg_ctxt_id || translation == msgid_plural))
--        return translation;
--    }
--  return (n == 1 ? msgid : msgid_plural);
--}
--
- #endif /* _LIBGETTEXT_H */
diff --git a/gl/override/lib/hmac-md5.c.diff b/gl/override/lib/hmac-md5.c.diff
deleted file mode 100644
index 1f80022..0000000
--- a/gl/override/lib/hmac-md5.c.diff
+++ /dev/null
@@ -1,20 +0,0 @@
---- hmac-md5.c.orig    2011-05-21 09:36:49.076074063 +0200
-+++ hmac-md5.c 2011-05-21 09:37:51.911556830 +0200
-@@ -58,7 +58,7 @@
-   md5_init_ctx (&inner);
- 
-   memset (block, IPAD, sizeof (block));
--  memxor (block, key, keylen);
-+  gl_memxor (block, key, keylen);
- 
-   md5_process_block (block, 64, &inner);
-   md5_process_bytes (in, inlen, &inner);
-@@ -70,7 +70,7 @@
-   md5_init_ctx (&outer);
- 
-   memset (block, OPAD, sizeof (block));
--  memxor (block, key, keylen);
-+  gl_memxor (block, key, keylen);
- 
-   md5_process_block (block, 64, &outer);
-   md5_process_bytes (innerhash, 16, &outer);
diff --git a/gl/override/lib/memxor.c.diff b/gl/override/lib/memxor.c.diff
deleted file mode 100644
index 5b1049c..0000000
--- a/gl/override/lib/memxor.c.diff
+++ /dev/null
@@ -1,11 +0,0 @@
---- memxor.c.orig      2011-05-21 09:38:04.328055463 +0200
-+++ memxor.c   2011-05-21 09:38:14.369054337 +0200
-@@ -23,7 +23,7 @@
- #include "memxor.h"
- 
- void *
--memxor (void *restrict dest, const void *restrict src, size_t n)
-+gl_memxor (void *restrict dest, const void *restrict src, size_t n)
- {
-   char const *s = src;
-   char *d = dest;
diff --git a/gl/override/lib/memxor.h.diff b/gl/override/lib/memxor.h.diff
deleted file mode 100644
index c7b6ca4..0000000
--- a/gl/override/lib/memxor.h.diff
+++ /dev/null
@@ -1,10 +0,0 @@
---- memxor.h.orig      2011-05-21 09:38:26.471555934 +0200
-+++ memxor.h   2011-05-21 09:38:30.668058152 +0200
-@@ -26,6 +26,6 @@
- /* Compute binary exclusive OR of memory areas DEST and SRC, putting
-    the result in DEST, of length N bytes.  Returns a pointer to
-    DEST. */
--void *memxor (void *restrict dest, const void *restrict src, size_t n);
-+void *gl_memxor (void *restrict dest, const void *restrict src, size_t n);
- 
- #endif /* MEMXOR_H */
diff --git a/gl/override/m4/valgrind-tests.m4.diff 
b/gl/override/m4/valgrind-tests.m4.diff
index 8a4f643..dac9a24 100644
--- a/gl/override/m4/valgrind-tests.m4.diff
+++ b/gl/override/m4/valgrind-tests.m4.diff
@@ -5,7 +5,7 @@
    if test -n "$VALGRIND" && $VALGRIND -q true > /dev/null 2>&1; then
      opt_valgrind_tests=yes
 -    VALGRIND="$VALGRIND -q --error-exitcode=1 --leak-check=full"
-+    VALGRIND="$VALGRIND -q --error-exitcode=1"
++    VALGRIND="$VALGRIND -q --error-exitcode=1 
--suppressions=suppressions.valgrind"
    else
      opt_valgrind_tests=no
      VALGRIND=
diff --git a/gl/printf-frexp.c b/gl/printf-frexp.c
index 7f7e0ec..267081c 100644
--- a/gl/printf-frexp.c
+++ b/gl/printf-frexp.c
@@ -14,7 +14,9 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include <config.h>
+#if ! defined USE_LONG_DOUBLE
+# include <config.h>
+#endif
 
 /* Specification.  */
 #ifdef USE_LONG_DOUBLE
diff --git a/gl/printf-frexpl.c b/gl/printf-frexpl.c
index f19f321..2de6528 100644
--- a/gl/printf-frexpl.c
+++ b/gl/printf-frexpl.c
@@ -14,5 +14,24 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#define USE_LONG_DOUBLE
-#include "printf-frexp.c"
+#include <config.h>
+
+#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
+
+/* Specification.  */
+# include "printf-frexpl.h"
+
+# include "printf-frexp.h"
+
+long double
+printf_frexpl (long double x, int *expptr)
+{
+  return printf_frexp (x, expptr);
+}
+
+#else
+
+# define USE_LONG_DOUBLE
+# include "printf-frexp.c"
+
+#endif
diff --git a/gl/recv.c b/gl/recv.c
new file mode 100644
index 0000000..4755f63
--- /dev/null
+++ b/gl/recv.c
@@ -0,0 +1,49 @@
+/* recv.c --- wrappers for Windows recv function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef recv
+
+ssize_t
+rpl_recv (int fd, void *buf, size_t len, int flags)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = recv (sock, buf, len, flags);
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
+}
diff --git a/gl/recvfrom.c b/gl/recvfrom.c
new file mode 100644
index 0000000..5ce2b12
--- /dev/null
+++ b/gl/recvfrom.c
@@ -0,0 +1,58 @@
+/* recvfrom.c --- wrappers for Windows recvfrom function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef recvfrom
+
+ssize_t
+rpl_recvfrom (int fd, void *buf, size_t len, int flags, struct sockaddr *from,
+              socklen_t *fromlen)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int frombufsize = (from != NULL ? *fromlen : 0);
+      int r = recvfrom (sock, buf, len, flags, from, fromlen);
+
+      if (r < 0)
+        set_winsock_errno ();
+
+      /* Winsock recvfrom() only returns a valid 'from' when the socket is
+         connectionless.  POSIX gives a valid 'from' for all types of
+         sockets.  */
+      else if (from != NULL && *fromlen == frombufsize)
+        rpl_getpeername (fd, from, fromlen);
+
+      return r;
+    }
+}
diff --git a/gl/select.c b/gl/select.c
new file mode 100644
index 0000000..236b951
--- /dev/null
+++ b/gl/select.c
@@ -0,0 +1,492 @@
+/* Emulation for select(2)
+   Contributed by Paolo Bonzini.
+
+   Copyright 2008-2011 Free Software Foundation, Inc.
+
+   This file is part of gnulib.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+#include <alloca.h>
+#include <assert.h>
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Native Win32.  */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <limits.h>
+
+#include <winsock2.h>
+#include <windows.h>
+#include <io.h>
+#include <stdio.h>
+#include <conio.h>
+#include <time.h>
+
+#include "msvc-nothrow.h"
+
+struct bitset {
+  unsigned char in[FD_SETSIZE / CHAR_BIT];
+  unsigned char out[FD_SETSIZE / CHAR_BIT];
+};
+
+/* Declare data structures for ntdll functions.  */
+typedef struct _FILE_PIPE_LOCAL_INFORMATION {
+  ULONG NamedPipeType;
+  ULONG NamedPipeConfiguration;
+  ULONG MaximumInstances;
+  ULONG CurrentInstances;
+  ULONG InboundQuota;
+  ULONG ReadDataAvailable;
+  ULONG OutboundQuota;
+  ULONG WriteQuotaAvailable;
+  ULONG NamedPipeState;
+  ULONG NamedPipeEnd;
+} FILE_PIPE_LOCAL_INFORMATION, *PFILE_PIPE_LOCAL_INFORMATION;
+
+typedef struct _IO_STATUS_BLOCK
+{
+  union {
+    DWORD Status;
+    PVOID Pointer;
+  } u;
+  ULONG_PTR Information;
+} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
+
+typedef enum _FILE_INFORMATION_CLASS {
+  FilePipeLocalInformation = 24
+} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
+
+typedef DWORD (WINAPI *PNtQueryInformationFile)
+         (HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS);
+
+#ifndef PIPE_BUF
+#define PIPE_BUF        512
+#endif
+
+#define IsConsoleHandle(h) (((long) (h) & 3) == 3)
+
+static BOOL
+IsSocketHandle (HANDLE h)
+{
+  WSANETWORKEVENTS ev;
+
+  if (IsConsoleHandle (h))
+    return FALSE;
+
+  /* Under Wine, it seems that getsockopt returns 0 for pipes too.
+     WSAEnumNetworkEvents instead distinguishes the two correctly.  */
+  ev.lNetworkEvents = 0xDEADBEEF;
+  WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev);
+  return ev.lNetworkEvents != 0xDEADBEEF;
+}
+
+/* Compute output fd_sets for libc descriptor FD (whose Win32 handle is H).  */
+
+static int
+win32_poll_handle (HANDLE h, int fd, struct bitset *rbits, struct bitset 
*wbits,
+                   struct bitset *xbits)
+{
+  BOOL read, write, except;
+  int i, ret;
+  INPUT_RECORD *irbuffer;
+  DWORD avail, nbuffer;
+  BOOL bRet;
+  IO_STATUS_BLOCK iosb;
+  FILE_PIPE_LOCAL_INFORMATION fpli;
+  static PNtQueryInformationFile NtQueryInformationFile;
+  static BOOL once_only;
+
+  read = write = except = FALSE;
+  switch (GetFileType (h))
+    {
+    case FILE_TYPE_DISK:
+      read = TRUE;
+      write = TRUE;
+      break;
+
+    case FILE_TYPE_PIPE:
+      if (!once_only)
+        {
+          NtQueryInformationFile = (PNtQueryInformationFile)
+            GetProcAddress (GetModuleHandle ("ntdll.dll"),
+                            "NtQueryInformationFile");
+          once_only = TRUE;
+        }
+
+      if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0)
+        {
+          if (avail)
+            read = TRUE;
+        }
+      else if (GetLastError () == ERROR_BROKEN_PIPE)
+        ;
+
+      else
+        {
+          /* It was the write-end of the pipe.  Check if it is writable.
+             If NtQueryInformationFile fails, optimistically assume the pipe is
+             writable.  This could happen on Win9x, where 
NtQueryInformationFile
+             is not available, or if we inherit a pipe that doesn't permit
+             FILE_READ_ATTRIBUTES access on the write end (I think this should
+             not happen since WinXP SP2; WINE seems fine too).  Otherwise,
+             ensure that enough space is available for atomic writes.  */
+          memset (&iosb, 0, sizeof (iosb));
+          memset (&fpli, 0, sizeof (fpli));
+
+          if (!NtQueryInformationFile
+              || NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli),
+                                         FilePipeLocalInformation)
+              || fpli.WriteQuotaAvailable >= PIPE_BUF
+              || (fpli.OutboundQuota < PIPE_BUF &&
+                  fpli.WriteQuotaAvailable == fpli.OutboundQuota))
+            write = TRUE;
+        }
+      break;
+
+    case FILE_TYPE_CHAR:
+      write = TRUE;
+      if (!(rbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1)))))
+        break;
+
+      ret = WaitForSingleObject (h, 0);
+      if (ret == WAIT_OBJECT_0)
+        {
+          if (!IsConsoleHandle (h))
+            {
+              read = TRUE;
+              break;
+            }
+
+          nbuffer = avail = 0;
+          bRet = GetNumberOfConsoleInputEvents (h, &nbuffer);
+
+          /* Screen buffers handles are filtered earlier.  */
+          assert (bRet);
+          if (nbuffer == 0)
+            {
+              except = TRUE;
+              break;
+            }
+
+          irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD));
+          bRet = PeekConsoleInput (h, irbuffer, nbuffer, &avail);
+          if (!bRet || avail == 0)
+            {
+              except = TRUE;
+              break;
+            }
+
+          for (i = 0; i < avail; i++)
+            if (irbuffer[i].EventType == KEY_EVENT)
+              read = TRUE;
+        }
+      break;
+
+    default:
+      ret = WaitForSingleObject (h, 0);
+      write = TRUE;
+      if (ret == WAIT_OBJECT_0)
+        read = TRUE;
+
+      break;
+    }
+
+  ret = 0;
+  if (read && (rbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1)))))
+    {
+      rbits->out[fd / CHAR_BIT] |= (1 << (fd & (CHAR_BIT - 1)));
+      ret++;
+    }
+
+  if (write && (wbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1)))))
+    {
+      wbits->out[fd / CHAR_BIT] |= (1 << (fd & (CHAR_BIT - 1)));
+      ret++;
+    }
+
+  if (except && (xbits->in[fd / CHAR_BIT] & (1 << (fd & (CHAR_BIT - 1)))))
+    {
+      xbits->out[fd / CHAR_BIT] |= (1 << (fd & (CHAR_BIT - 1)));
+      ret++;
+    }
+
+  return ret;
+}
+
+int
+rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
+            struct timeval *timeout)
+{
+  static struct timeval tv0;
+  static HANDLE hEvent;
+  HANDLE h, handle_array[FD_SETSIZE + 2];
+  fd_set handle_rfds, handle_wfds, handle_xfds;
+  struct bitset rbits, wbits, xbits;
+  unsigned char anyfds_in[FD_SETSIZE / CHAR_BIT];
+  DWORD ret, wait_timeout, nhandles, nsock, nbuffer;
+  MSG msg;
+  int i, fd, rc;
+
+  if (nfds > FD_SETSIZE)
+    nfds = FD_SETSIZE;
+
+  if (!timeout)
+    wait_timeout = INFINITE;
+  else
+    {
+      wait_timeout = timeout->tv_sec * 1000 + timeout->tv_usec / 1000;
+
+      /* select is also used as a portable usleep.  */
+      if (!rfds && !wfds && !xfds)
+        {
+          Sleep (wait_timeout);
+          return 0;
+        }
+    }
+
+  if (!hEvent)
+    hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
+
+  handle_array[0] = hEvent;
+  nhandles = 1;
+  nsock = 0;
+
+  /* Copy descriptors to bitsets.  At the same time, eliminate
+     bits in the "wrong" direction for console input buffers
+     and screen buffers, because screen buffers are waitable
+     and they will block until a character is available.  */
+  memset (&rbits, 0, sizeof (rbits));
+  memset (&wbits, 0, sizeof (wbits));
+  memset (&xbits, 0, sizeof (xbits));
+  memset (anyfds_in, 0, sizeof (anyfds_in));
+  if (rfds)
+    for (i = 0; i < rfds->fd_count; i++)
+      {
+        fd = rfds->fd_array[i];
+        h = (HANDLE) _get_osfhandle (fd);
+        if (IsConsoleHandle (h)
+            && !GetNumberOfConsoleInputEvents (h, &nbuffer))
+          continue;
+
+        rbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
+        anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
+      }
+  else
+    rfds = (fd_set *) alloca (sizeof (fd_set));
+
+  if (wfds)
+    for (i = 0; i < wfds->fd_count; i++)
+      {
+        fd = wfds->fd_array[i];
+        h = (HANDLE) _get_osfhandle (fd);
+        if (IsConsoleHandle (h)
+            && GetNumberOfConsoleInputEvents (h, &nbuffer))
+          continue;
+
+        wbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
+        anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
+      }
+  else
+    wfds = (fd_set *) alloca (sizeof (fd_set));
+
+  if (xfds)
+    for (i = 0; i < xfds->fd_count; i++)
+      {
+        fd = xfds->fd_array[i];
+        xbits.in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
+        anyfds_in[fd / CHAR_BIT] |= 1 << (fd & (CHAR_BIT - 1));
+      }
+  else
+    xfds = (fd_set *) alloca (sizeof (fd_set));
+
+  /* Zero all the fd_sets, including the application's.  */
+  FD_ZERO (rfds);
+  FD_ZERO (wfds);
+  FD_ZERO (xfds);
+  FD_ZERO (&handle_rfds);
+  FD_ZERO (&handle_wfds);
+  FD_ZERO (&handle_xfds);
+
+  /* Classify handles.  Create fd sets for sockets, poll the others. */
+  for (i = 0; i < nfds; i++)
+    {
+      if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0)
+        continue;
+
+      h = (HANDLE) _get_osfhandle (i);
+      if (!h)
+        {
+          errno = EBADF;
+          return -1;
+        }
+
+      if (IsSocketHandle (h))
+        {
+          int requested = FD_CLOSE;
+
+          /* See above; socket handles are mapped onto select, but we
+             need to map descriptors to handles.  */
+          if (rbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+            {
+              requested |= FD_READ | FD_ACCEPT;
+              FD_SET ((SOCKET) h, rfds);
+              FD_SET ((SOCKET) h, &handle_rfds);
+            }
+          if (wbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+            {
+              requested |= FD_WRITE | FD_CONNECT;
+              FD_SET ((SOCKET) h, wfds);
+              FD_SET ((SOCKET) h, &handle_wfds);
+            }
+          if (xbits.in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+            {
+              requested |= FD_OOB;
+              FD_SET ((SOCKET) h, xfds);
+              FD_SET ((SOCKET) h, &handle_xfds);
+            }
+
+          WSAEventSelect ((SOCKET) h, hEvent, requested);
+          nsock++;
+        }
+      else
+        {
+          handle_array[nhandles++] = h;
+
+          /* Poll now.  If we get an event, do not wait below.  */
+          if (wait_timeout != 0
+              && win32_poll_handle (h, i, &rbits, &wbits, &xbits))
+            wait_timeout = 0;
+        }
+    }
+
+  if (wait_timeout == 0 || nsock == 0)
+    rc = 0;
+  else
+    {
+      /* See if we need to wait in the loop below.  If any select is ready,
+         do MsgWaitForMultipleObjects anyway to dispatch messages, but
+         no need to call select again.  */
+      rc = select (0, &handle_rfds, &handle_wfds, &handle_xfds, &tv0);
+      if (rc == 0)
+        {
+          /* Restore the fd_sets for the other select we do below.  */
+          memcpy (&handle_rfds, rfds, sizeof (fd_set));
+          memcpy (&handle_wfds, wfds, sizeof (fd_set));
+          memcpy (&handle_xfds, xfds, sizeof (fd_set));
+        }
+      else
+        wait_timeout = 0;
+    }
+
+  for (;;)
+    {
+      ret = MsgWaitForMultipleObjects (nhandles, handle_array, FALSE,
+                                       wait_timeout, QS_ALLINPUT);
+
+      if (ret == WAIT_OBJECT_0 + nhandles)
+        {
+          /* new input of some other kind */
+          BOOL bRet;
+          while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0)
+            {
+              TranslateMessage (&msg);
+              DispatchMessage (&msg);
+            }
+        }
+      else
+        break;
+    }
+
+  /* If we haven't done it yet, check the status of the sockets.  */
+  if (rc == 0 && nsock > 0)
+    rc = select (0, &handle_rfds, &handle_wfds, &handle_xfds, &tv0);
+
+  /* Now fill in the results.  */
+  FD_ZERO (rfds);
+  FD_ZERO (wfds);
+  FD_ZERO (xfds);
+
+  /* Place a sentinel at the end of the array.  */
+  handle_array[nhandles] = NULL;
+  nhandles = 1;
+  for (i = 0; i < nfds; i++)
+    {
+      if ((anyfds_in[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1)))) == 0)
+        continue;
+
+      h = (HANDLE) _get_osfhandle (i);
+      if (h != handle_array[nhandles])
+        {
+          /* Perform handle->descriptor mapping.  Don't update rc, as these
+             results are counted in the return value of Winsock's select.  */
+          WSAEventSelect ((SOCKET) h, NULL, 0);
+          if (FD_ISSET (h, &handle_rfds))
+            FD_SET (i, rfds);
+          if (FD_ISSET (h, &handle_wfds))
+            FD_SET (i, wfds);
+          if (FD_ISSET (h, &handle_xfds))
+            FD_SET (i, xfds);
+        }
+      else
+        {
+          /* Not a socket.  */
+          nhandles++;
+          win32_poll_handle (h, i, &rbits, &wbits, &xbits);
+          if (rbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+            {
+              rc++;
+              FD_SET (i, rfds);
+            }
+          if (wbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+            {
+              rc++;
+              FD_SET (i, wfds);
+            }
+          if (xbits.out[i / CHAR_BIT] & (1 << (i & (CHAR_BIT - 1))))
+            {
+              rc++;
+              FD_SET (i, xfds);
+            }
+        }
+    }
+
+  return rc;
+}
+
+#else /* ! Native Win32.  */
+
+#include <sys/select.h>
+
+#undef select
+
+int
+rpl_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *xfds,
+            struct timeval *timeout)
+{
+  /* Interix 3.5 has a bug: it does not support nfds == 0.  */
+  if (nfds == 0)
+    {
+      nfds = 1;
+      rfds = NULL;
+      wfds = NULL;
+      xfds = NULL;
+    }
+  return select (nfds, rfds, wfds, xfds, timeout);
+}
+
+#endif
diff --git a/gl/send.c b/gl/send.c
new file mode 100644
index 0000000..cd21482
--- /dev/null
+++ b/gl/send.c
@@ -0,0 +1,49 @@
+/* send.c --- wrappers for Windows send function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef send
+
+ssize_t
+rpl_send (int fd, const void *buf, size_t len, int flags)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = send (sock, buf, len, flags);
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
+}
diff --git a/gl/sendto.c b/gl/sendto.c
new file mode 100644
index 0000000..95efab8
--- /dev/null
+++ b/gl/sendto.c
@@ -0,0 +1,50 @@
+/* sendto.c --- wrappers for Windows sendto function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef sendto
+
+ssize_t
+rpl_sendto (int fd, const void *buf, size_t len, int flags,
+            const struct sockaddr *to, socklen_t tolen)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = sendto (sock, buf, len, flags, to, tolen);
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
+}
diff --git a/gl/setsockopt.c b/gl/setsockopt.c
new file mode 100644
index 0000000..6a7ca5e
--- /dev/null
+++ b/gl/setsockopt.c
@@ -0,0 +1,65 @@
+/* setsockopt.c --- wrappers for Windows setsockopt function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get struct timeval. */
+#include <sys/time.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef setsockopt
+
+int
+rpl_setsockopt (int fd, int level, int optname, const void *optval, socklen_t 
optlen)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+  int r;
+
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      if (level == SOL_SOCKET
+          && (optname == SO_RCVTIMEO || optname == SO_SNDTIMEO))
+        {
+          const struct timeval *tv = optval;
+          int milliseconds = tv->tv_sec * 1000 + tv->tv_usec / 1000;
+          optval = &milliseconds;
+          r = setsockopt (sock, level, optname, optval, sizeof (int));
+        }
+      else
+        {
+          r = setsockopt (sock, level, optname, optval, optlen);
+        }
+
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
+}
diff --git a/gl/shutdown.c b/gl/shutdown.c
new file mode 100644
index 0000000..1c302a2
--- /dev/null
+++ b/gl/shutdown.c
@@ -0,0 +1,49 @@
+/* shutdown.c --- wrappers for Windows shutdown function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#undef shutdown
+
+int
+rpl_shutdown (int fd, int how)
+{
+  SOCKET sock = FD_TO_SOCKET (fd);
+
+  if (sock == INVALID_SOCKET)
+    {
+      errno = EBADF;
+      return -1;
+    }
+  else
+    {
+      int r = shutdown (sock, how);
+      if (r < 0)
+        set_winsock_errno ();
+
+      return r;
+    }
+}
diff --git a/gl/signal.in.h b/gl/signal.in.h
new file mode 100644
index 0000000..e18e0b2
--- /dev/null
+++ b/gl/signal.in.h
@@ -0,0 +1,447 @@
+/* A GNU-like <signal.h>.
+
+   Copyright (C) 2006-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#if __GNUC__ >= 3
address@hidden@
+#endif
address@hidden@
+
+#if defined __need_sig_atomic_t || defined __need_sigset_t || defined 
_GL_ALREADY_INCLUDING_SIGNAL_H || (defined _SIGNAL_H && !defined 
__SIZEOF_PTHREAD_MUTEX_T)
+/* Special invocation convention:
+   - Inside glibc header files.
+   - On glibc systems we have a sequence of nested includes
+     <signal.h> -> <ucontext.h> -> <signal.h>.
+     In this situation, the functions are not yet declared, therefore we cannot
+     provide the C++ aliases.
+   - On glibc systems with GCC 4.3 we have a sequence of nested includes
+     <csignal> -> </usr/include/signal.h> -> <sys/ucontext.h> -> <signal.h>.
+     In this situation, some of the functions are not yet declared, therefore
+     we cannot provide the C++ aliases.  */
+
+# @INCLUDE_NEXT@ @NEXT_SIGNAL_H@
+
+#else
+/* Normal invocation convention.  */
+
+#ifndef address@hidden@_SIGNAL_H
+
+#define _GL_ALREADY_INCLUDING_SIGNAL_H
+
+/* Define pid_t, uid_t.
+   Also, mingw defines sigset_t not in <signal.h>, but in <sys/types.h>.
+   On Solaris 10, <signal.h> includes <sys/types.h>, which eventually includes
+   us; so include <sys/types.h> now, before the second inclusion guard.  */
+#include <sys/types.h>
+
+/* The include_next requires a split double-inclusion guard.  */
address@hidden@ @NEXT_SIGNAL_H@
+
+#undef _GL_ALREADY_INCLUDING_SIGNAL_H
+
+#ifndef address@hidden@_SIGNAL_H
+#define address@hidden@_SIGNAL_H
+
+/* MacOS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6 declare
+   pthread_sigmask in <pthread.h>, not in <signal.h>.
+   But avoid namespace pollution on glibc systems.*/
+#if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \
+    && ((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || 
defined __OpenBSD__ || defined __osf__ || defined __sun) \
+    && ! defined __GLIBC__
+# include <pthread.h>
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_ARG_NONNULL is copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+/* On AIX, sig_atomic_t already includes volatile.  C99 requires that
+   'volatile sig_atomic_t' ignore the extra modifier, but C89 did not.
+   Hence, redefine this to a non-volatile type as needed.  */
+#if ! @HAVE_TYPE_VOLATILE_SIG_ATOMIC_T@
+# if !GNULIB_defined_sig_atomic_t
+typedef int rpl_sig_atomic_t;
+#  undef sig_atomic_t
+#  define sig_atomic_t rpl_sig_atomic_t
+#  define GNULIB_defined_sig_atomic_t 1
+# endif
+#endif
+
+/* A set or mask of signals.  */
+#if address@hidden@
+# if !GNULIB_defined_sigset_t
+typedef unsigned int sigset_t;
+#  define GNULIB_defined_sigset_t 1
+# endif
+#endif
+
+/* Define sighandler_t, the type of signal handlers.  A GNU extension.  */
+#if address@hidden@
+# ifdef __cplusplus
+extern "C" {
+# endif
+# if !GNULIB_defined_sighandler_t
+typedef void (*sighandler_t) (int);
+#  define GNULIB_defined_sighandler_t 1
+# endif
+# ifdef __cplusplus
+}
+# endif
+#endif
+
+
+#if @GNULIB_SIGNAL_H_SIGPIPE@
+# ifndef SIGPIPE
+/* Define SIGPIPE to a value that does not overlap with other signals.  */
+#  define SIGPIPE 13
+#  define GNULIB_defined_SIGPIPE 1
+/* To actually use SIGPIPE, you also need the gnulib modules 'sigprocmask',
+   'write', 'stdio'.  */
+# endif
+#endif
+
+
+/* Maximum signal number + 1.  */
+#ifndef NSIG
+# if defined __TANDEM
+#  define NSIG 32
+# endif
+#endif
+
+
+#if @GNULIB_PTHREAD_SIGMASK@
+# if @REPLACE_PTHREAD_SIGMASK@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef pthread_sigmask
+#   define pthread_sigmask rpl_pthread_sigmask
+#  endif
+_GL_FUNCDECL_RPL (pthread_sigmask, int,
+                  (int how, const sigset_t *new_mask, sigset_t *old_mask));
+_GL_CXXALIAS_RPL (pthread_sigmask, int,
+                  (int how, const sigset_t *new_mask, sigset_t *old_mask));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (pthread_sigmask, int,
+                  (int how, const sigset_t *new_mask, sigset_t *old_mask));
+#  endif
+_GL_CXXALIAS_SYS (pthread_sigmask, int,
+                  (int how, const sigset_t *new_mask, sigset_t *old_mask));
+# endif
+_GL_CXXALIASWARN (pthread_sigmask);
+#elif defined GNULIB_POSIXCHECK
+# undef pthread_sigmask
+# if HAVE_RAW_DECL_PTHREAD_SIGMASK
+_GL_WARN_ON_USE (pthread_sigmask, "pthread_sigmask is not portable - "
+                 "use gnulib module pthread_sigmask for portability");
+# endif
+#endif
+
+
+#if @GNULIB_RAISE@
+# if @REPLACE_RAISE@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef raise
+#   define raise rpl_raise
+#  endif
+_GL_FUNCDECL_RPL (raise, int, (int sig));
+_GL_CXXALIAS_RPL (raise, int, (int sig));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (raise, int, (int sig));
+#  endif
+_GL_CXXALIAS_SYS (raise, int, (int sig));
+# endif
+_GL_CXXALIASWARN (raise);
+#elif defined GNULIB_POSIXCHECK
+# undef raise
+/* Assume raise is always declared.  */
+_GL_WARN_ON_USE (raise, "raise can crash on native Windows - "
+                 "use gnulib module raise for portability");
+#endif
+
+
+#if @GNULIB_SIGPROCMASK@
+# if address@hidden@
+
+#  ifndef GNULIB_defined_signal_blocking
+#   define GNULIB_defined_signal_blocking 1
+#  endif
+
+/* Maximum signal number + 1.  */
+#  ifndef NSIG
+#   define NSIG 32
+#  endif
+
+/* This code supports only 32 signals.  */
+#  if !GNULIB_defined_verify_NSIG_constraint
+typedef int verify_NSIG_constraint[NSIG <= 32 ? 1 : -1];
+#   define GNULIB_defined_verify_NSIG_constraint 1
+#  endif
+
+# endif
+
+/* Test whether a given signal is contained in a signal set.  */
+# if @HAVE_POSIX_SIGNALBLOCKING@
+/* This function is defined as a macro on MacOS X.  */
+#  if defined __cplusplus && defined GNULIB_NAMESPACE
+#   undef sigismember
+#  endif
+# else
+_GL_FUNCDECL_SYS (sigismember, int, (const sigset_t *set, int sig)
+                                    _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigismember, int, (const sigset_t *set, int sig));
+_GL_CXXALIASWARN (sigismember);
+
+/* Initialize a signal set to the empty set.  */
+# if @HAVE_POSIX_SIGNALBLOCKING@
+/* This function is defined as a macro on MacOS X.  */
+#  if defined __cplusplus && defined GNULIB_NAMESPACE
+#   undef sigemptyset
+#  endif
+# else
+_GL_FUNCDECL_SYS (sigemptyset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigemptyset, int, (sigset_t *set));
+_GL_CXXALIASWARN (sigemptyset);
+
+/* Add a signal to a signal set.  */
+# if @HAVE_POSIX_SIGNALBLOCKING@
+/* This function is defined as a macro on MacOS X.  */
+#  if defined __cplusplus && defined GNULIB_NAMESPACE
+#   undef sigaddset
+#  endif
+# else
+_GL_FUNCDECL_SYS (sigaddset, int, (sigset_t *set, int sig)
+                                  _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigaddset, int, (sigset_t *set, int sig));
+_GL_CXXALIASWARN (sigaddset);
+
+/* Remove a signal from a signal set.  */
+# if @HAVE_POSIX_SIGNALBLOCKING@
+/* This function is defined as a macro on MacOS X.  */
+#  if defined __cplusplus && defined GNULIB_NAMESPACE
+#   undef sigdelset
+#  endif
+# else
+_GL_FUNCDECL_SYS (sigdelset, int, (sigset_t *set, int sig)
+                                  _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigdelset, int, (sigset_t *set, int sig));
+_GL_CXXALIASWARN (sigdelset);
+
+/* Fill a signal set with all possible signals.  */
+# if @HAVE_POSIX_SIGNALBLOCKING@
+/* This function is defined as a macro on MacOS X.  */
+#  if defined __cplusplus && defined GNULIB_NAMESPACE
+#   undef sigfillset
+#  endif
+# else
+_GL_FUNCDECL_SYS (sigfillset, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigfillset, int, (sigset_t *set));
+_GL_CXXALIASWARN (sigfillset);
+
+/* Return the set of those blocked signals that are pending.  */
+# if address@hidden@
+_GL_FUNCDECL_SYS (sigpending, int, (sigset_t *set) _GL_ARG_NONNULL ((1)));
+# endif
+_GL_CXXALIAS_SYS (sigpending, int, (sigset_t *set));
+_GL_CXXALIASWARN (sigpending);
+
+/* If OLD_SET is not NULL, put the current set of blocked signals in *OLD_SET.
+   Then, if SET is not NULL, affect the current set of blocked signals by
+   combining it with *SET as indicated in OPERATION.
+   In this implementation, you are not allowed to change a signal handler
+   while the signal is blocked.  */
+# if address@hidden@
+#  define SIG_BLOCK   0  /* blocked_set = blocked_set | *set; */
+#  define SIG_SETMASK 1  /* blocked_set = *set; */
+#  define SIG_UNBLOCK 2  /* blocked_set = blocked_set & ~*set; */
+_GL_FUNCDECL_SYS (sigprocmask, int,
+                  (int operation, const sigset_t *set, sigset_t *old_set));
+# endif
+_GL_CXXALIAS_SYS (sigprocmask, int,
+                  (int operation, const sigset_t *set, sigset_t *old_set));
+_GL_CXXALIASWARN (sigprocmask);
+
+/* Install the handler FUNC for signal SIG, and return the previous
+   handler.  */
+# ifdef __cplusplus
+extern "C" {
+# endif
+# if !GNULIB_defined_function_taking_int_returning_void_t
+typedef void (*_gl_function_taking_int_returning_void_t) (int);
+#  define GNULIB_defined_function_taking_int_returning_void_t 1
+# endif
+# ifdef __cplusplus
+}
+# endif
+# if address@hidden@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define signal rpl_signal
+#  endif
+_GL_FUNCDECL_RPL (signal, _gl_function_taking_int_returning_void_t,
+                  (int sig, _gl_function_taking_int_returning_void_t func));
+_GL_CXXALIAS_RPL (signal, _gl_function_taking_int_returning_void_t,
+                  (int sig, _gl_function_taking_int_returning_void_t func));
+# else
+_GL_CXXALIAS_SYS (signal, _gl_function_taking_int_returning_void_t,
+                  (int sig, _gl_function_taking_int_returning_void_t func));
+# endif
+_GL_CXXALIASWARN (signal);
+
+# if address@hidden@ && GNULIB_defined_SIGPIPE
+/* Raise signal SIGPIPE.  */
+_GL_EXTERN_C int _gl_raise_SIGPIPE (void);
+# endif
+
+#elif defined GNULIB_POSIXCHECK
+# undef sigaddset
+# if HAVE_RAW_DECL_SIGADDSET
+_GL_WARN_ON_USE (sigaddset, "sigaddset is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigdelset
+# if HAVE_RAW_DECL_SIGDELSET
+_GL_WARN_ON_USE (sigdelset, "sigdelset is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigemptyset
+# if HAVE_RAW_DECL_SIGEMPTYSET
+_GL_WARN_ON_USE (sigemptyset, "sigemptyset is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigfillset
+# if HAVE_RAW_DECL_SIGFILLSET
+_GL_WARN_ON_USE (sigfillset, "sigfillset is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigismember
+# if HAVE_RAW_DECL_SIGISMEMBER
+_GL_WARN_ON_USE (sigismember, "sigismember is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigpending
+# if HAVE_RAW_DECL_SIGPENDING
+_GL_WARN_ON_USE (sigpending, "sigpending is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+# undef sigprocmask
+# if HAVE_RAW_DECL_SIGPROCMASK
+_GL_WARN_ON_USE (sigprocmask, "sigprocmask is unportable - "
+                 "use the gnulib module sigprocmask for portability");
+# endif
+#endif /* @GNULIB_SIGPROCMASK@ */
+
+
+#if @GNULIB_SIGACTION@
+# if address@hidden@
+
+#  if address@hidden@
+
+#   if !GNULIB_defined_siginfo_types
+
+/* Present to allow compilation, but unsupported by gnulib.  */
+union sigval
+{
+  int sival_int;
+  void *sival_ptr;
+};
+
+/* Present to allow compilation, but unsupported by gnulib.  */
+struct siginfo_t
+{
+  int si_signo;
+  int si_code;
+  int si_errno;
+  pid_t si_pid;
+  uid_t si_uid;
+  void *si_addr;
+  int si_status;
+  long si_band;
+  union sigval si_value;
+};
+typedef struct siginfo_t siginfo_t;
+
+#    define GNULIB_defined_siginfo_types 1
+#   endif
+
+#  endif /* address@hidden@ */
+
+/* We assume that platforms which lack the sigaction() function also lack
+   the 'struct sigaction' type, and vice versa.  */
+
+#  if !GNULIB_defined_struct_sigaction
+
+struct sigaction
+{
+  union
+  {
+    void (*_sa_handler) (int);
+    /* Present to allow compilation, but unsupported by gnulib.  POSIX
+       says that implementations may, but not must, make sa_sigaction
+       overlap with sa_handler, but we know of no implementation where
+       they do not overlap.  */
+    void (*_sa_sigaction) (int, siginfo_t *, void *);
+  } _sa_func;
+  sigset_t sa_mask;
+  /* Not all POSIX flags are supported.  */
+  int sa_flags;
+};
+#   define sa_handler _sa_func._sa_handler
+#   define sa_sigaction _sa_func._sa_sigaction
+/* Unsupported flags are not present.  */
+#   define SA_RESETHAND 1
+#   define SA_NODEFER 2
+#   define SA_RESTART 4
+
+#   define GNULIB_defined_struct_sigaction 1
+#  endif
+
+_GL_FUNCDECL_SYS (sigaction, int, (int, const struct sigaction *restrict,
+                                   struct sigaction *restrict));
+
+# elif address@hidden@
+
+#  define sa_sigaction sa_handler
+
+# endif /* address@hidden@, address@hidden@ */
+
+_GL_CXXALIAS_SYS (sigaction, int, (int, const struct sigaction *restrict,
+                                   struct sigaction *restrict));
+_GL_CXXALIASWARN (sigaction);
+
+#elif defined GNULIB_POSIXCHECK
+# undef sigaction
+# if HAVE_RAW_DECL_SIGACTION
+_GL_WARN_ON_USE (sigaction, "sigaction is unportable - "
+                 "use the gnulib module sigaction for portability");
+# endif
+#endif
+
+/* Some systems don't have SA_NODEFER.  */
+#ifndef SA_NODEFER
+# define SA_NODEFER 0
+#endif
+
+
+#endif /* address@hidden@_SIGNAL_H */
+#endif /* address@hidden@_SIGNAL_H */
+#endif
diff --git a/gl/socket.c b/gl/socket.c
new file mode 100644
index 0000000..af6be25
--- /dev/null
+++ b/gl/socket.c
@@ -0,0 +1,49 @@
+/* socket.c --- wrappers for Windows socket function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#define WIN32_LEAN_AND_MEAN
+/* Get winsock2.h. */
+#include <sys/socket.h>
+
+/* Get set_winsock_errno, FD_TO_SOCKET etc. */
+#include "w32sock.h"
+
+#include "sockets.h"
+
+int
+rpl_socket (int domain, int type, int protocol)
+{
+  SOCKET fh;
+
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* We have to use WSASocket() to create non-overlapped IO sockets.
+     Overlapped IO sockets cannot be used with read/write.  */
+  fh = WSASocket (domain, type, protocol, NULL, 0, 0);
+
+  if (fh == INVALID_SOCKET)
+    {
+      set_winsock_errno ();
+      return -1;
+    }
+  else
+    return SOCKET_TO_FD (fh);
+}
diff --git a/gl/sockets.c b/gl/sockets.c
index 53cb66e..39939b0 100644
--- a/gl/sockets.c
+++ b/gl/sockets.c
@@ -28,6 +28,7 @@
 # include <sys/socket.h>
 
 # include "fd-hook.h"
+# include "msvc-nothrow.h"
 
 /* Get set_winsock_errno, FD_TO_SOCKET etc. */
 # include "w32sock.h"
diff --git a/gl/sockets.h b/gl/sockets.h
index 93ae5d2..323f68c 100644
--- a/gl/sockets.h
+++ b/gl/sockets.h
@@ -36,6 +36,8 @@ int gl_sockets_cleanup (void);
 
 #include <sys/socket.h>
 
+#include "msvc-nothrow.h"
+
 static inline SOCKET
 gl_fd_to_handle (int fd)
 {
diff --git a/gl/stdalign.in.h b/gl/stdalign.in.h
new file mode 100644
index 0000000..79e5691
--- /dev/null
+++ b/gl/stdalign.in.h
@@ -0,0 +1,89 @@
+/* A substitute for ISO C 1x <stdalign.h>.
+
+   Copyright 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* Written by Paul Eggert and Bruno Haible.  */
+
+#ifndef _GL_STDALIGN_H
+#define _GL_STDALIGN_H
+
+/* ISO C1X <stdalign.h> for platforms that lack it.
+
+   References:
+   ISO C1X <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf>
+   sections 6.5.3.4, 6.7.5, 7.15.
+   C++0X <http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf>
+   section 18.10. */
+
+/* alignof (TYPE), also known as _Alignof (TYPE), yields the alignment
+   requirement of a structure member (i.e., slot or field) that is of
+   type TYPE, as an integer constant expression.
+
+   This differs from GCC's __alignof__ operator, which can yield a
+   better-performing alignment for an object of that type.  For
+   example, on x86 with GCC, __alignof__ (double) and __alignof__
+   (long long) are 8, whereas alignof (double) and alignof (long long)
+   are 4 unless the option '-malign-double' is used.
+
+   The result cannot be used as a value for an 'enum' constant, if you
+   want to be portable to HP-UX 10.20 cc and AIX 3.2.5 xlc.  */
+#include <stddef.h>
+#if defined __cplusplus
+   template <class __t> struct __alignof_helper { char __a; __t __b; };
+# define _Alignof(type) offsetof (__alignof_helper<type>, __b)
+#else
+# define _Alignof(type) offsetof (struct { char __a; type __b; }, __b)
+#endif
+#define alignof _Alignof
+#define __alignof_is_defined 1
+
+/* alignas (A), also known as _Alignas (A), aligns a variable or type
+   to the alignment A, where A is an integer constant expression.  For
+   example:
+
+      int alignas (8) foo;
+      struct s { int a; int alignas (8) bar; };
+
+   aligns the address of FOO and the offset of BAR to be multiples of 8.
+
+   A should be a power of two that is at least the type's alignment
+   and at most the implementation's alignment limit.  This limit is
+   2**28 on typical GNUish hosts, and 2**13 on MSVC.  To be portable
+   to MSVC through at least version 10.0, A should be an integer
+   constant, as MSVC does not support expressions such as 1 << 3.
+   To be portable to Sun C 5.11, do not align auto variables to
+   anything stricter than their default alignment.
+
+   The following draft C1X requirements are not supported here:
+
+     - If A is zero, alignas has no effect.
+     - alignas can be used multiple times; the strictest one wins.
+     - alignas (TYPE) is equivalent to alignas (alignof (TYPE)).
+
+   */
+
+#if __GNUC__ || __IBMC__ || __IBMCPP__ || 0x5110 <= __SUNPRO_C
+# define _Alignas(a) __attribute__ ((__aligned__ (a)))
+#elif 1300 <= _MSC_VER
+# define _Alignas(a) __declspec (align (a))
+#endif
+#ifdef _Alignas
+# define alignas _Alignas
+# define __alignas_is_defined 1
+#endif
+
+#endif /* _GL_STDALIGN_H */
diff --git a/gl/stdio.in.h b/gl/stdio.in.h
index 6917d25..ce00af5 100644
--- a/gl/stdio.in.h
+++ b/gl/stdio.in.h
@@ -170,6 +170,26 @@ _GL_WARN_ON_USE (fclose, "fclose is not always POSIX 
compliant - "
                  "use gnulib module fclose for portable POSIX compliance");
 #endif
 
+#if @GNULIB_FDOPEN@
+# if @REPLACE_FDOPEN@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fdopen
+#   define fdopen rpl_fdopen
+#  endif
+_GL_FUNCDECL_RPL (fdopen, FILE *, (int fd, const char *mode)
+                                  _GL_ARG_NONNULL ((2)));
+_GL_CXXALIAS_RPL (fdopen, FILE *, (int fd, const char *mode));
+# else
+_GL_CXXALIAS_SYS (fdopen, FILE *, (int fd, const char *mode));
+# endif
+_GL_CXXALIASWARN (fdopen);
+#elif defined GNULIB_POSIXCHECK
+# undef fdopen
+/* Assume fdopen is always declared.  */
+_GL_WARN_ON_USE (fdopen, "fdopen on Win32 platforms is not POSIX compatible - "
+                 "use gnulib module fdopen for portability");
+#endif
+
 #if @GNULIB_FFLUSH@
 /* Flush all pending data on STREAM according to POSIX rules.  Both
    output and seekable input streams are supported.
diff --git a/gl/stdlib.in.h b/gl/stdlib.in.h
index 047fac1..1a8df49 100644
--- a/gl/stdlib.in.h
+++ b/gl/stdlib.in.h
@@ -247,7 +247,7 @@ _GL_CXXALIASWARN (grantpt);
 #elif defined GNULIB_POSIXCHECK
 # undef grantpt
 # if HAVE_RAW_DECL_GRANTPT
-_GL_WARN_ON_USE (ptsname, "grantpt is not portable - "
+_GL_WARN_ON_USE (grantpt, "grantpt is not portable - "
                  "use gnulib module grantpt for portability");
 # endif
 #endif
@@ -423,6 +423,22 @@ _GL_WARN_ON_USE (mkstemps, "mkstemps is unportable - "
 # endif
 #endif
 
+#if @GNULIB_POSIX_OPENPT@
+/* Return an FD open to the master side of a pseudo-terminal.  Flags should
+   include O_RDWR, and may also include O_NOCTTY.  */
+# if address@hidden@
+_GL_FUNCDECL_SYS (posix_openpt, int, (int flags));
+# endif
+_GL_CXXALIAS_SYS (posix_openpt, int, (int flags));
+_GL_CXXALIASWARN (posix_openpt);
+#elif defined GNULIB_POSIXCHECK
+# undef posix_openpt
+# if HAVE_RAW_DECL_POSIX_OPENPT
+_GL_WARN_ON_USE (posix_openpt, "posix_openpt is not portable - "
+                 "use gnulib module posix_openpt for portability");
+# endif
+#endif
+
 #if @GNULIB_PTSNAME@
 /* Return the pathname of the pseudo-terminal slave associated with
    the master FD is open on, or NULL on errors.  */
diff --git a/gl/strerror-override.c b/gl/strerror-override.c
index d6ecf2e..4e2c32b 100644
--- a/gl/strerror-override.c
+++ b/gl/strerror-override.c
@@ -23,7 +23,7 @@
 
 #include <errno.h>
 
-#if GNULIB_defined_ESOCK /* native Windows platforms */
+#if GNULIB_defined_EWINSOCK /* native Windows platforms */
 # if HAVE_WINSOCK2_H
 #  include <winsock2.h>
 # endif
@@ -42,13 +42,7 @@ strerror_override (int errnum)
       return "Success";
 #endif
 
-#if GNULIB_defined_ETXTBSY
-    case ETXTBSY:
-      return "Text file busy";
-#endif
-
-#if GNULIB_defined_ESOCK /* native Windows platforms */
-      /* EWOULDBLOCK is the same as EAGAIN.  */
+#if GNULIB_defined_ESOCK /* native Windows platforms with older <errno.h> */
     case EINPROGRESS:
       return "Operation now in progress";
     case EALREADY:
@@ -65,12 +59,8 @@ strerror_override (int errnum)
       return "Protocol not available";
     case EPROTONOSUPPORT:
       return "Protocol not supported";
-    case ESOCKTNOSUPPORT:
-      return "Socket type not supported";
     case EOPNOTSUPP:
       return "Operation not supported";
-    case EPFNOSUPPORT:
-      return "Protocol family not supported";
     case EAFNOSUPPORT:
       return "Address family not supported by protocol";
     case EADDRINUSE:
@@ -81,10 +71,6 @@ strerror_override (int errnum)
       return "Network is down";
     case ENETUNREACH:
       return "Network is unreachable";
-    case ENETRESET:
-      return "Network dropped connection on reset";
-    case ECONNABORTED:
-      return "Software caused connection abort";
     case ECONNRESET:
       return "Connection reset by peer";
     case ENOBUFS:
@@ -93,20 +79,44 @@ strerror_override (int errnum)
       return "Transport endpoint is already connected";
     case ENOTCONN:
       return "Transport endpoint is not connected";
-    case ESHUTDOWN:
-      return "Cannot send after transport endpoint shutdown";
-    case ETOOMANYREFS:
-      return "Too many references: cannot splice";
     case ETIMEDOUT:
       return "Connection timed out";
     case ECONNREFUSED:
       return "Connection refused";
     case ELOOP:
       return "Too many levels of symbolic links";
-    case EHOSTDOWN:
-      return "Host is down";
     case EHOSTUNREACH:
       return "No route to host";
+    case EWOULDBLOCK:
+      return "Operation would block";
+    case ETXTBSY:
+      return "Text file busy";
+    case ENODATA:
+      return "No data available";
+    case ENOSR:
+      return "Out of streams resources";
+    case ENOSTR:
+      return "Device not a stream";
+    case ENOTRECOVERABLE:
+      return "State not recoverable";
+    case EOWNERDEAD:
+      return "Owner died";
+    case ETIME:
+      return "Timer expired";
+    case EOTHER:
+      return "Other error";
+#endif
+#if GNULIB_defined_EWINSOCK /* native Windows platforms */
+    case ESOCKTNOSUPPORT:
+      return "Socket type not supported";
+    case EPFNOSUPPORT:
+      return "Protocol family not supported";
+    case ESHUTDOWN:
+      return "Cannot send after transport endpoint shutdown";
+    case ETOOMANYREFS:
+      return "Too many references: cannot splice";
+    case EHOSTDOWN:
+      return "Host is down";
     case EPROCLIM:
       return "Too many processes";
     case EUSERS:
@@ -134,36 +144,36 @@ strerror_override (int errnum)
       /* WSAEINVAL maps to EINVAL */
       /* WSAEMFILE maps to EMFILE */
       /* WSAEWOULDBLOCK maps to EWOULDBLOCK */
-      /* WSAEINPROGRESS is EINPROGRESS */
-      /* WSAEALREADY is EALREADY */
-      /* WSAENOTSOCK is ENOTSOCK */
-      /* WSAEDESTADDRREQ is EDESTADDRREQ */
-      /* WSAEMSGSIZE is EMSGSIZE */
-      /* WSAEPROTOTYPE is EPROTOTYPE */
-      /* WSAENOPROTOOPT is ENOPROTOOPT */
-      /* WSAEPROTONOSUPPORT is EPROTONOSUPPORT */
+      /* WSAEINPROGRESS maps to EINPROGRESS */
+      /* WSAEALREADY maps to EALREADY */
+      /* WSAENOTSOCK maps to ENOTSOCK */
+      /* WSAEDESTADDRREQ maps to EDESTADDRREQ */
+      /* WSAEMSGSIZE maps to EMSGSIZE */
+      /* WSAEPROTOTYPE maps to EPROTOTYPE */
+      /* WSAENOPROTOOPT maps to ENOPROTOOPT */
+      /* WSAEPROTONOSUPPORT maps to EPROTONOSUPPORT */
       /* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
-      /* WSAEOPNOTSUPP is EOPNOTSUPP */
+      /* WSAEOPNOTSUPP maps to EOPNOTSUPP */
       /* WSAEPFNOSUPPORT is EPFNOSUPPORT */
-      /* WSAEAFNOSUPPORT is EAFNOSUPPORT */
-      /* WSAEADDRINUSE is EADDRINUSE */
-      /* WSAEADDRNOTAVAIL is EADDRNOTAVAIL */
-      /* WSAENETDOWN is ENETDOWN */
-      /* WSAENETUNREACH is ENETUNREACH */
-      /* WSAENETRESET is ENETRESET */
-      /* WSAECONNABORTED is ECONNABORTED */
-      /* WSAECONNRESET is ECONNRESET */
-      /* WSAENOBUFS is ENOBUFS */
-      /* WSAEISCONN is EISCONN */
-      /* WSAENOTCONN is ENOTCONN */
+      /* WSAEAFNOSUPPORT maps to EAFNOSUPPORT */
+      /* WSAEADDRINUSE maps to EADDRINUSE */
+      /* WSAEADDRNOTAVAIL maps to EADDRNOTAVAIL */
+      /* WSAENETDOWN maps to ENETDOWN */
+      /* WSAENETUNREACH maps to ENETUNREACH */
+      /* WSAENETRESET maps to ENETRESET */
+      /* WSAECONNABORTED maps to ECONNABORTED */
+      /* WSAECONNRESET maps to ECONNRESET */
+      /* WSAENOBUFS maps to ENOBUFS */
+      /* WSAEISCONN maps to EISCONN */
+      /* WSAENOTCONN maps to ENOTCONN */
       /* WSAESHUTDOWN is ESHUTDOWN */
       /* WSAETOOMANYREFS is ETOOMANYREFS */
-      /* WSAETIMEDOUT is ETIMEDOUT */
-      /* WSAECONNREFUSED is ECONNREFUSED */
-      /* WSAELOOP is ELOOP */
+      /* WSAETIMEDOUT maps to ETIMEDOUT */
+      /* WSAECONNREFUSED maps to ECONNREFUSED */
+      /* WSAELOOP maps to ELOOP */
       /* WSAENAMETOOLONG maps to ENAMETOOLONG */
       /* WSAEHOSTDOWN is EHOSTDOWN */
-      /* WSAEHOSTUNREACH is EHOSTUNREACH */
+      /* WSAEHOSTUNREACH maps to EHOSTUNREACH */
       /* WSAENOTEMPTY maps to ENOTEMPTY */
       /* WSAEPROCLIM is EPROCLIM */
       /* WSAEUSERS is EUSERS */
diff --git a/gl/strerror-override.h b/gl/strerror-override.h
index 81e4a50..09540b9 100644
--- a/gl/strerror-override.h
+++ b/gl/strerror-override.h
@@ -29,8 +29,8 @@
 /* If ERRNUM maps to an errno value defined by gnulib, return a string
    describing the error.  Otherwise return NULL.  */
 # if REPLACE_STRERROR_0 \
-     || GNULIB_defined_ETXTBSY \
      || GNULIB_defined_ESOCK \
+     || GNULIB_defined_EWINSOCK \
      || GNULIB_defined_ENOMSG \
      || GNULIB_defined_EIDRM \
      || GNULIB_defined_ENOLINK \
diff --git a/gl/strings.in.h b/gl/strings.in.h
index 42600b9..8bb455e 100644
--- a/gl/strings.in.h
+++ b/gl/strings.in.h
@@ -37,6 +37,11 @@
 #ifndef address@hidden@_STRINGS_H
 #define address@hidden@_STRINGS_H
 
+#if ! @HAVE_DECL_STRNCASECMP@
+/* Get size_t.  */
+# include <stddef.h>
+#endif
+
 
 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
 
diff --git a/gl/sys_select.in.h b/gl/sys_select.in.h
new file mode 100644
index 0000000..4406a7a
--- /dev/null
+++ b/gl/sys_select.in.h
@@ -0,0 +1,288 @@
+/* Substitute for <sys/select.h>.
+   Copyright (C) 2007-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+# if __GNUC__ >= 3
address@hidden@
+# endif
address@hidden@
+
+/* On OSF/1, <sys/types.h> and <sys/time.h> include <sys/select.h>.
+   Simply delegate to the system's header in this case.  */
+#if @HAVE_SYS_SELECT_H@ && defined __osf__ && (defined _SYS_TYPES_H_ && 
!defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H) && defined _OSF_SOURCE
+
+# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
+
+#elif @HAVE_SYS_SELECT_H@ && defined __osf__ && (defined _SYS_TIME_H_ && 
!defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H) && defined _OSF_SOURCE
+
+# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
+
+/* On IRIX 6.5, <sys/timespec.h> includes <sys/types.h>, which includes
+   <sys/bsd_types.h>, which includes <sys/select.h>.  At this point we cannot
+   include <signal.h>, because that includes <internal/signal_core.h>, which
+   gives a syntax error because <sys/timespec.h> has not been completely
+   processed.  Simply delegate to the system's header in this case.  */
+#elif @HAVE_SYS_SELECT_H@ && defined __sgi && (defined _SYS_BSD_TYPES_H && 
!defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H)
+
+# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_BSD_TYPES_H
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
+
+#else
+
+#ifndef address@hidden@_SYS_SELECT_H
+
+/* On many platforms, <sys/select.h> assumes prior inclusion of
+   <sys/types.h>.  Also, mingw defines sigset_t there, instead of
+   in <signal.h> where it belongs.  */
+#include <sys/types.h>
+
+/* Get definition of 'sigset_t'.
+   But avoid namespace pollution on glibc systems.  */
+#if !(defined __GLIBC__ && !defined __UCLIBC__)
+# include <signal.h>
+#endif
+
+#if @HAVE_SYS_SELECT_H@
+
+/* On OSF/1 4.0, <sys/select.h> provides only a forward declaration
+   of 'struct timeval', and no definition of this type.
+   Also, MacOS X, AIX, HP-UX, IRIX, Solaris, Interix declare select()
+   in <sys/time.h>.
+   But avoid namespace pollution on glibc systems.  */
+# ifndef __GLIBC__
+#  include <sys/time.h>
+# endif
+
+/* On AIX 7 and Solaris 10, <sys/select.h> provides an FD_ZERO implementation
+   that relies on memset(), but without including <string.h>.
+   But in any case avoid namespace pollution on glibc systems.  */
+# if (defined __OpenBSD__ || defined _AIX || defined __sun || defined __osf__ 
|| defined __BEOS__) \
+     && ! defined __GLIBC__
+#  include <string.h>
+# endif
+
+/* The include_next requires a split double-inclusion guard.  */
+# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
+
+#endif
+
+#ifndef address@hidden@_SYS_SELECT_H
+#define address@hidden@_SYS_SELECT_H
+
+#if address@hidden@
+/* A platform that lacks <sys/select.h>.  */
+/* Get the 'struct timeval' and 'fd_set' types and the FD_* macros
+   on most platforms.  */
+# include <sys/time.h>
+/* On HP-UX 11, <sys/time.h> provides an FD_ZERO implementation
+   that relies on memset(), but without including <string.h>.  */
+# if defined __hpux
+#  include <string.h>
+# endif
+/* On native Windows platforms:
+   Get the 'fd_set' type.
+   Get the close() declaration before we override it.  */
+# if @HAVE_WINSOCK2_H@
+#  if !defined _GL_INCLUDING_WINSOCK2_H
+#   define _GL_INCLUDING_WINSOCK2_H
+#   include <winsock2.h>
+#   undef _GL_INCLUDING_WINSOCK2_H
+#  endif
+#  include <io.h>
+# endif
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+
+/* Fix some definitions from <winsock2.h>.  */
+
+#if @HAVE_WINSOCK2_H@
+
+# if !GNULIB_defined_rpl_fd_isset
+
+/* Re-define FD_ISSET to avoid a WSA call while we are not using
+   network sockets.  */
+static inline int
+rpl_fd_isset (SOCKET fd, fd_set * set)
+{
+  u_int i;
+  if (set == NULL)
+    return 0;
+
+  for (i = 0; i < set->fd_count; i++)
+    if (set->fd_array[i] == fd)
+      return 1;
+
+  return 0;
+}
+
+#  define GNULIB_defined_rpl_fd_isset 1
+# endif
+
+# undef FD_ISSET
+# define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
+
+#endif
+
+/* Hide some function declarations from <winsock2.h>.  */
+
+#if @HAVE_WINSOCK2_H@
+# if !defined address@hidden@_UNISTD_H
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef close
+#   define close close_used_without_including_unistd_h
+#  else
+    _GL_WARN_ON_USE (close,
+                     "close() used without including <unistd.h>");
+#  endif
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef gethostname
+#   define gethostname gethostname_used_without_including_unistd_h
+#  else
+    _GL_WARN_ON_USE (gethostname,
+                     "gethostname() used without including <unistd.h>");
+#  endif
+# endif
+# if !defined address@hidden@_SYS_SOCKET_H
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef socket
+#   define socket              socket_used_without_including_sys_socket_h
+#   undef connect
+#   define connect             connect_used_without_including_sys_socket_h
+#   undef accept
+#   define accept              accept_used_without_including_sys_socket_h
+#   undef bind
+#   define bind                bind_used_without_including_sys_socket_h
+#   undef getpeername
+#   define getpeername         getpeername_used_without_including_sys_socket_h
+#   undef getsockname
+#   define getsockname         getsockname_used_without_including_sys_socket_h
+#   undef getsockopt
+#   define getsockopt          getsockopt_used_without_including_sys_socket_h
+#   undef listen
+#   define listen              listen_used_without_including_sys_socket_h
+#   undef recv
+#   define recv                recv_used_without_including_sys_socket_h
+#   undef send
+#   define send                send_used_without_including_sys_socket_h
+#   undef recvfrom
+#   define recvfrom            recvfrom_used_without_including_sys_socket_h
+#   undef sendto
+#   define sendto              sendto_used_without_including_sys_socket_h
+#   undef setsockopt
+#   define setsockopt          setsockopt_used_without_including_sys_socket_h
+#   undef shutdown
+#   define shutdown            shutdown_used_without_including_sys_socket_h
+#  else
+    _GL_WARN_ON_USE (socket,
+                     "socket() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (connect,
+                     "connect() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (accept,
+                     "accept() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (bind,
+                     "bind() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (getpeername,
+                     "getpeername() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (getsockname,
+                     "getsockname() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (getsockopt,
+                     "getsockopt() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (listen,
+                     "listen() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (recv,
+                     "recv() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (send,
+                     "send() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (recvfrom,
+                     "recvfrom() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (sendto,
+                     "sendto() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (setsockopt,
+                     "setsockopt() used without including <sys/socket.h>");
+    _GL_WARN_ON_USE (shutdown,
+                     "shutdown() used without including <sys/socket.h>");
+#  endif
+# endif
+#endif
+
+
+#if @GNULIB_PSELECT@
+# if @REPLACE_PSELECT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef pselect
+#   define pselect rpl_pselect
+#  endif
+_GL_FUNCDECL_RPL (pselect, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timespec const *restrict, const sigset_t *restrict));
+_GL_CXXALIAS_RPL (pselect, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timespec const *restrict, const sigset_t *restrict));
+# else
+#  if address@hidden@
+_GL_FUNCDECL_SYS (pselect, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timespec const *restrict, const sigset_t *restrict));
+#  endif
+_GL_CXXALIAS_SYS (pselect, int,
+                  (int, fd_set *restrict, fd_set *restrict, fd_set *restrict,
+                   struct timespec const *restrict, const sigset_t *restrict));
+# endif
+_GL_CXXALIASWARN (pselect);
+#elif defined GNULIB_POSIXCHECK
+# undef pselect
+# if HAVE_RAW_DECL_PSELECT
+_GL_WARN_ON_USE (pselect, "pselect is not portable - "
+                 "use gnulib module pselect for portability");
+# endif
+#endif
+
+#if @GNULIB_SELECT@
+# if @REPLACE_SELECT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef select
+#   define select rpl_select
+#  endif
+_GL_FUNCDECL_RPL (select, int,
+                  (int, fd_set *, fd_set *, fd_set *, struct timeval *));
+_GL_CXXALIAS_RPL (select, int,
+                  (int, fd_set *, fd_set *, fd_set *, struct timeval *));
+# else
+_GL_CXXALIAS_SYS (select, int,
+                  (int, fd_set *, fd_set *, fd_set *, struct timeval *));
+# endif
+_GL_CXXALIASWARN (select);
+#elif @HAVE_WINSOCK2_H@
+# undef select
+# define select select_used_without_requesting_gnulib_module_select
+#elif defined GNULIB_POSIXCHECK
+# undef select
+# if HAVE_RAW_DECL_SELECT
+_GL_WARN_ON_USE (select, "select is not always POSIX compliant - "
+                 "use gnulib module select for portability");
+# endif
+#endif
+
+
+#endif /* address@hidden@_SYS_SELECT_H */
+#endif /* address@hidden@_SYS_SELECT_H */
+#endif /* OSF/1 */
diff --git a/gl/sys_socket.in.h b/gl/sys_socket.in.h
index aba28f8..43681a4 100644
--- a/gl/sys_socket.in.h
+++ b/gl/sys_socket.in.h
@@ -85,7 +85,7 @@ typedef unsigned short  sa_family_t;
 #  endif
 # endif
 #else
-# include <alignof.h>
+# include <stdalign.h>
 /* Code taken from glibc sysdeps/unix/sysv/linux/bits/socket.h on
    2009-05-08, licensed under LGPLv2.1+, plus portability fixes. */
 # define __ss_aligntype unsigned long int
diff --git a/gl/sys_stat.in.h b/gl/sys_stat.in.h
index 43c15c3..77a7177 100644
--- a/gl/sys_stat.in.h
+++ b/gl/sys_stat.in.h
@@ -55,10 +55,11 @@
 /* The definition of _GL_WARN_ON_USE is copied here.  */
 
 /* Before doing "#define mkdir rpl_mkdir" below, we need to include all
-   headers that may declare mkdir().  */
+   headers that may declare mkdir().  Native Windows platforms declare mkdir
+   in <io.h> and/or <direct.h>, not in <unistd.h>.  */
 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 # include <io.h>     /* mingw32, mingw64 */
-# include <direct.h> /* mingw64 */
+# include <direct.h> /* mingw64, MSVC 9 */
 #endif
 
 #ifndef S_IFIFO
@@ -318,16 +319,25 @@ _GL_WARN_ON_USE (fchmodat, "fchmodat is not portable - "
 #endif
 
 
-#if @REPLACE_FSTAT@
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#  define fstat rpl_fstat
-# endif
+#if @GNULIB_FSTAT@
+# if @REPLACE_FSTAT@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef fstat
+#   define fstat rpl_fstat
+#  endif
 _GL_FUNCDECL_RPL (fstat, int, (int fd, struct stat *buf) _GL_ARG_NONNULL 
((2)));
 _GL_CXXALIAS_RPL (fstat, int, (int fd, struct stat *buf));
-#else
+# else
 _GL_CXXALIAS_SYS (fstat, int, (int fd, struct stat *buf));
-#endif
+# endif
 _GL_CXXALIASWARN (fstat);
+#elif defined GNULIB_POSIXCHECK
+# undef fstat
+# if HAVE_RAW_DECL_FSTAT
+_GL_WARN_ON_USE (fstat, "fstat has portability problems - "
+                 "use gnulib module fstat for portability");
+# endif
+#endif
 
 
 #if @GNULIB_FSTATAT@
diff --git a/gl/tests/Makefile.am b/gl/tests/Makefile.am
index ba41456..0edbe38 100644
--- a/gl/tests/Makefile.am
+++ b/gl/tests/Makefile.am
@@ -2,15 +2,27 @@
 ## Process this file with automake to produce Makefile.in.
 # Copyright (C) 2002-2011 Free Software Foundation, Inc.
 #
-# This file is free software, distributed under the terms of the GNU
-# General Public License.  As a special exception to the GNU General
-# Public License, this file may be distributed as part of a program
-# that contains a configuration script generated by Autoconf, under
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this file.  If not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License,
+# this file may be distributed as part of a program that
+# contains a configuration script generated by Autoconf, under
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
 
-AUTOMAKE_OPTIONS = 1.5 foreign
+AUTOMAKE_OPTIONS = 1.5 foreign subdir-objects
 
 SUBDIRS = .
 TESTS =
@@ -46,6 +58,15 @@ AM_LIBTOOLFLAGS = --preserve-dup-deps
 
 TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
 
+## begin gnulib module accept-tests
+
+TESTS += test-accept
+check_PROGRAMS += test-accept
+test_accept_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-accept.c signature.h macros.h
+
+## end   gnulib module accept-tests
+
 ## begin gnulib module alloca-opt-tests
 
 TESTS += test-alloca-opt
@@ -64,6 +85,14 @@ EXTRA_DIST += test-argp.c test-argp-2.sh
 
 ## end   gnulib module argp-tests
 
+## begin gnulib module arpa_inet-tests
+
+TESTS += test-arpa_inet
+check_PROGRAMS += test-arpa_inet
+EXTRA_DIST += test-arpa_inet.c
+
+## end   gnulib module arpa_inet-tests
+
 ## begin gnulib module binary-io
 
 libtests_a_SOURCES += binary-io.h
@@ -79,6 +108,15 @@ EXTRA_DIST += test-binary-io.sh test-binary-io.c macros.h
 
 ## end   gnulib module binary-io-tests
 
+## begin gnulib module bind-tests
+
+TESTS += test-bind
+check_PROGRAMS += test-bind
+test_bind_LDADD = $(LDADD) @LIBSOCKET@ $(INET_PTON_LIB)
+EXTRA_DIST += test-bind.c signature.h macros.h
+
+## end   gnulib module bind-tests
+
 ## begin gnulib module byteswap-tests
 
 TESTS += test-byteswap
@@ -96,21 +134,22 @@ EXTRA_DIST += test-c-ctype.c macros.h
 
 ## end   gnulib module c-ctype-tests
 
-## begin gnulib module crypto/hmac-md5-tests
+## begin gnulib module close-tests
 
-TESTS += test-hmac-md5
-check_PROGRAMS += test-hmac-md5
-EXTRA_DIST += test-hmac-md5.c
+TESTS += test-close
+check_PROGRAMS += test-close
+EXTRA_DIST += test-close.c signature.h macros.h
 
-## end   gnulib module crypto/hmac-md5-tests
+## end   gnulib module close-tests
 
-## begin gnulib module crypto/md5-tests
+## begin gnulib module connect-tests
 
-TESTS += test-md5
-check_PROGRAMS += test-md5
-EXTRA_DIST += test-md5.c
+TESTS += test-connect
+check_PROGRAMS += test-connect
+test_connect_LDADD = $(LDADD) @LIBSOCKET@ $(INET_PTON_LIB)
+EXTRA_DIST += test-connect.c signature.h macros.h
 
-## end   gnulib module crypto/md5-tests
+## end   gnulib module connect-tests
 
 ## begin gnulib module dirent-tests
 
@@ -198,6 +237,15 @@ EXTRA_DIST += test-fcntl-h.c
 
 ## end   gnulib module fcntl-h-tests
 
+## begin gnulib module fdopen
+
+
+EXTRA_DIST += fdopen.c
+
+EXTRA_libtests_a_SOURCES += fdopen.c
+
+## end   gnulib module fdopen
+
 ## begin gnulib module fdopen-tests
 
 TESTS += test-fdopen
@@ -222,6 +270,22 @@ EXTRA_DIST += test-float.c macros.h
 
 ## end   gnulib module float-tests
 
+## begin gnulib module fputc-tests
+
+TESTS += test-fputc
+check_PROGRAMS += test-fputc
+EXTRA_DIST += test-fputc.c signature.h macros.h
+
+## end   gnulib module fputc-tests
+
+## begin gnulib module fread-tests
+
+TESTS += test-fread
+check_PROGRAMS += test-fread
+EXTRA_DIST += test-fread.c signature.h macros.h
+
+## end   gnulib module fread-tests
+
 ## begin gnulib module frexp-nolibm-tests
 
 TESTS += test-frexp-nolibm
@@ -291,6 +355,23 @@ EXTRA_DIST += test-ftello.c test-ftello.sh test-ftello2.sh 
test-ftello3.c test-f
 
 ## end   gnulib module ftello-tests
 
+## begin gnulib module ftruncate
+
+
+EXTRA_DIST += ftruncate.c
+
+EXTRA_libtests_a_SOURCES += ftruncate.c
+
+## end   gnulib module ftruncate
+
+## begin gnulib module ftruncate-tests
+
+TESTS += test-ftruncate.sh
+check_PROGRAMS += test-ftruncate
+EXTRA_DIST += test-ftruncate.c test-ftruncate.sh signature.h macros.h
+
+## end   gnulib module ftruncate-tests
+
 ## begin gnulib module func-tests
 
 TESTS += test-func
@@ -299,6 +380,14 @@ EXTRA_DIST += test-func.c macros.h
 
 ## end   gnulib module func-tests
 
+## begin gnulib module fwrite-tests
+
+TESTS += test-fwrite
+check_PROGRAMS += test-fwrite
+EXTRA_DIST += test-fwrite.c signature.h macros.h
+
+## end   gnulib module fwrite-tests
+
 ## begin gnulib module getcwd-lgpl
 
 
@@ -312,6 +401,7 @@ EXTRA_libtests_a_SOURCES += getcwd-lgpl.c
 
 TESTS += test-getcwd-lgpl
 check_PROGRAMS += test-getcwd-lgpl
+test_getcwd_lgpl_LDADD = $(LDADD) $(LIBINTL)
 EXTRA_DIST += test-getcwd-lgpl.c signature.h macros.h
 
 ## end   gnulib module getcwd-lgpl-tests
@@ -352,6 +442,15 @@ EXTRA_libtests_a_SOURCES += getpagesize.c
 
 ## end   gnulib module getpagesize
 
+## begin gnulib module getpeername-tests
+
+TESTS += test-getpeername
+check_PROGRAMS += test-getpeername
+test_getpeername_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-getpeername.c signature.h macros.h
+
+## end   gnulib module getpeername-tests
+
 ## begin gnulib module gettimeofday-tests
 
 TESTS += test-gettimeofday
@@ -376,6 +475,24 @@ EXTRA_DIST += test-ignore-value.c
 
 ## end   gnulib module ignore-value-tests
 
+## begin gnulib module inet_ntop-tests
+
+TESTS += test-inet_ntop
+check_PROGRAMS += test-inet_ntop
+test_inet_ntop_LDADD = $(LDADD) @INET_NTOP_LIB@
+EXTRA_DIST += test-inet_ntop.c signature.h macros.h
+
+## end   gnulib module inet_ntop-tests
+
+## begin gnulib module inet_pton-tests
+
+TESTS += test-inet_pton
+check_PROGRAMS += test-inet_pton
+test_inet_pton_LDADD = $(LDADD) @INET_PTON_LIB@
+EXTRA_DIST += test-inet_pton.c signature.h macros.h
+
+## end   gnulib module inet_pton-tests
+
 ## begin gnulib module intprops-tests
 
 TESTS += test-intprops
@@ -434,6 +551,23 @@ EXTRA_DIST += test-inttypes.c
 
 ## end   gnulib module inttypes-tests
 
+## begin gnulib module ioctl
+
+
+EXTRA_DIST += ioctl.c w32sock.h
+
+EXTRA_libtests_a_SOURCES += ioctl.c
+
+## end   gnulib module ioctl
+
+## begin gnulib module ioctl-tests
+
+TESTS += test-ioctl
+check_PROGRAMS += test-ioctl
+EXTRA_DIST += test-ioctl.c signature.h macros.h
+
+## end   gnulib module ioctl-tests
+
 ## begin gnulib module isnand-nolibm-tests
 
 TESTS += test-isnand-nolibm
@@ -461,6 +595,30 @@ EXTRA_DIST += test-isnanl-nolibm.c test-isnanl.h 
minus-zero.h infinity.h nan.h m
 
 ## end   gnulib module isnanl-nolibm-tests
 
+## begin gnulib module listen-tests
+
+TESTS += test-listen
+check_PROGRAMS += test-listen
+test_listen_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-listen.c signature.h macros.h
+
+## end   gnulib module listen-tests
+
+## begin gnulib module lock
+
+libtests_a_SOURCES += glthread/lock.h glthread/lock.c
+
+## end   gnulib module lock
+
+## begin gnulib module lock-tests
+
+TESTS += test-lock
+check_PROGRAMS += test-lock
+test_lock_LDADD = $(LDADD) @LIBMULTITHREAD@ @YIELD_LIB@
+EXTRA_DIST += test-lock.c
+
+## end   gnulib module lock-tests
+
 ## begin gnulib module lstat
 
 
@@ -519,15 +677,6 @@ EXTRA_DIST += test-memchr.c zerosize-ptr.h signature.h 
macros.h
 
 ## end   gnulib module memchr-tests
 
-## begin gnulib module msvc-inval
-
-
-EXTRA_DIST += msvc-inval.c msvc-inval.h
-
-EXTRA_libtests_a_SOURCES += msvc-inval.c
-
-## end   gnulib module msvc-inval
-
 ## begin gnulib module netdb-tests
 
 TESTS += test-netdb
@@ -576,6 +725,40 @@ EXTRA_DIST += test-pathmax.c
 
 ## end   gnulib module pathmax-tests
 
+## begin gnulib module perror
+
+
+EXTRA_DIST += perror.c
+
+EXTRA_libtests_a_SOURCES += perror.c
+
+## end   gnulib module perror
+
+## begin gnulib module perror-tests
+
+TESTS += test-perror.sh test-perror2
+check_PROGRAMS += test-perror test-perror2
+EXTRA_DIST += init.sh macros.h signature.h test-perror.c test-perror2.c 
test-perror.sh
+
+## end   gnulib module perror-tests
+
+## begin gnulib module pipe-posix
+
+
+EXTRA_DIST += pipe.c
+
+EXTRA_libtests_a_SOURCES += pipe.c
+
+## end   gnulib module pipe-posix
+
+## begin gnulib module pipe-posix-tests
+
+TESTS += test-pipe
+check_PROGRAMS += test-pipe
+EXTRA_DIST += test-pipe.c signature.h macros.h
+
+## end   gnulib module pipe-posix-tests
+
 ## begin gnulib module printf-frexp-tests
 
 TESTS += test-printf-frexp
@@ -617,6 +800,24 @@ EXTRA_DIST += test-read-file.c
 
 ## end   gnulib module read-file-tests
 
+## begin gnulib module recv-tests
+
+TESTS += test-recv
+check_PROGRAMS += test-recv
+test_recv_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-recv.c signature.h macros.h
+
+## end   gnulib module recv-tests
+
+## begin gnulib module recvfrom-tests
+
+TESTS += test-recvfrom
+check_PROGRAMS += test-recvfrom
+test_recvfrom_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-recvfrom.c signature.h macros.h
+
+## end   gnulib module recvfrom-tests
+
 ## begin gnulib module same-inode
 
 
@@ -624,6 +825,36 @@ EXTRA_DIST += same-inode.h
 
 ## end   gnulib module same-inode
 
+## begin gnulib module select-tests
+
+TESTS += test-select test-select-in.sh test-select-out.sh
+# test-select-stdin has to be run by hand.
+check_PROGRAMS += test-select test-select-fd test-select-stdin
+test_select_LDADD = $(LDADD) @LIB_SELECT@ @LIBSOCKET@ $(INET_PTON_LIB)
+test_select_fd_LDADD = $(LDADD) @LIB_SELECT@
+test_select_stdin_LDADD = $(LDADD) @LIB_SELECT@
+EXTRA_DIST += macros.h signature.h test-select.c test-select.h 
test-select-fd.c test-select-in.sh test-select-out.sh test-select-stdin.c
+
+## end   gnulib module select-tests
+
+## begin gnulib module send-tests
+
+TESTS += test-send
+check_PROGRAMS += test-send
+test_send_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-send.c signature.h macros.h
+
+## end   gnulib module send-tests
+
+## begin gnulib module sendto-tests
+
+TESTS += test-sendto
+check_PROGRAMS += test-sendto
+test_sendto_LDADD = $(LDADD) @LIBSOCKET@ $(INET_PTON_LIB)
+EXTRA_DIST += test-sendto.c signature.h macros.h
+
+## end   gnulib module sendto-tests
+
 ## begin gnulib module setenv
 
 
@@ -641,6 +872,32 @@ EXTRA_DIST += test-setenv.c signature.h macros.h
 
 ## end   gnulib module setenv-tests
 
+## begin gnulib module setsockopt-tests
+
+TESTS += test-setsockopt
+check_PROGRAMS += test-setsockopt
+test_setsockopt_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-setsockopt.c signature.h macros.h
+
+## end   gnulib module setsockopt-tests
+
+## begin gnulib module shutdown-tests
+
+TESTS += test-shutdown
+check_PROGRAMS += test-shutdown
+test_shutdown_LDADD = $(LDADD) @LIBSOCKET@
+EXTRA_DIST += test-shutdown.c signature.h macros.h
+
+## end   gnulib module shutdown-tests
+
+## begin gnulib module signal-h-tests
+
+TESTS += test-signal-h
+check_PROGRAMS += test-signal-h
+EXTRA_DIST += test-signal-h.c
+
+## end   gnulib module signal-h-tests
+
 ## begin gnulib module signbit-tests
 
 TESTS += test-signbit
@@ -770,10 +1027,19 @@ EXTRA_libtests_a_SOURCES += stat.c
 
 TESTS += test-stat
 check_PROGRAMS += test-stat
+test_stat_LDADD = $(LDADD) $(LIBINTL)
 EXTRA_DIST += test-stat.h test-stat.c signature.h macros.h
 
 ## end   gnulib module stat-tests
 
+## begin gnulib module stdalign-tests
+
+TESTS += test-stdalign
+check_PROGRAMS += test-stdalign
+EXTRA_DIST += test-stdalign.c macros.h
+
+## end   gnulib module stdalign-tests
+
 ## begin gnulib module stdbool-tests
 
 TESTS += test-stdbool
@@ -830,6 +1096,23 @@ EXTRA_DIST += test-strerror.c signature.h macros.h
 
 ## end   gnulib module strerror-tests
 
+## begin gnulib module strerror_r-posix
+
+
+EXTRA_DIST += strerror_r.c
+
+EXTRA_libtests_a_SOURCES += strerror_r.c
+
+## end   gnulib module strerror_r-posix
+
+## begin gnulib module strerror_r-posix-tests
+
+TESTS += test-strerror_r
+check_PROGRAMS += test-strerror_r
+EXTRA_DIST += test-strerror_r.c signature.h macros.h
+
+## end   gnulib module strerror_r-posix-tests
+
 ## begin gnulib module string-tests
 
 TESTS += test-string
@@ -879,6 +1162,54 @@ EXTRA_DIST += test-symlink.h test-symlink.c signature.h 
macros.h
 
 ## end   gnulib module symlink-tests
 
+## begin gnulib module sys_ioctl
+
+BUILT_SOURCES += sys/ioctl.h
+
+# We need the following in order to create <sys/ioctl.h> when the system
+# does not have a complete one.
+sys/ioctl.h: sys_ioctl.in.h $(top_builddir)/config.status $(CXXDEFS_H) 
$(WARN_ON_USE_H)
+       $(AM_V_at)$(MKDIR_P) sys
+       $(AM_V_GEN)rm -f address@hidden $@ && \
+       { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+         sed -e 's|@''GUARD_PREFIX''@|GL|g' \
+             -e 's|@''HAVE_SYS_IOCTL_H''@|$(HAVE_SYS_IOCTL_H)|g' \
+             -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+             -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+             -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
+             -e 's|@''NEXT_SYS_IOCTL_H''@|$(NEXT_SYS_IOCTL_H)|g' \
+             -e 's/@''GNULIB_IOCTL''@/$(GNULIB_IOCTL)/g' \
+             -e 
's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H)|g' \
+             -e 
's|@''SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g'
 \
+             -e 's|@''REPLACE_IOCTL''@|$(REPLACE_IOCTL)|g' \
+             -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
+             -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
+             < $(srcdir)/sys_ioctl.in.h; \
+       } > address@hidden && \
+       mv address@hidden $@
+MOSTLYCLEANFILES += sys/ioctl.h sys/ioctl.h-t
+MOSTLYCLEANDIRS += sys
+
+EXTRA_DIST += sys_ioctl.in.h
+
+## end   gnulib module sys_ioctl
+
+## begin gnulib module sys_ioctl-tests
+
+TESTS += test-sys_ioctl
+check_PROGRAMS += test-sys_ioctl
+EXTRA_DIST += test-sys_ioctl.c
+
+## end   gnulib module sys_ioctl-tests
+
+## begin gnulib module sys_select-tests
+
+TESTS += test-sys_select
+check_PROGRAMS += test-sys_select
+EXTRA_DIST += test-sys_select.c signature.h
+
+## end   gnulib module sys_select-tests
+
 ## begin gnulib module sys_socket-tests
 
 TESTS += test-sys_socket
@@ -927,6 +1258,30 @@ EXTRA_DIST += test-sysexits.c
 
 ## end   gnulib module sysexits-tests
 
+## begin gnulib module thread
+
+libtests_a_SOURCES += glthread/thread.h glthread/thread.c
+
+## end   gnulib module thread
+
+## begin gnulib module thread-tests
+
+TESTS += test-thread_self test-thread_create
+check_PROGRAMS += test-thread_self test-thread_create
+test_thread_self_LDADD = $(LDADD) @LIBTHREAD@
+test_thread_create_LDADD = $(LDADD) @LIBMULTITHREAD@
+EXTRA_DIST += test-thread_self.c test-thread_create.c macros.h
+
+## end   gnulib module thread-tests
+
+## begin gnulib module threadlib
+
+libtests_a_SOURCES += glthread/threadlib.c
+
+EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath
+
+## end   gnulib module threadlib
+
 ## begin gnulib module time-tests
 
 TESTS += test-time
@@ -1046,6 +1401,12 @@ EXTRA_DIST += test-wchar.c
 
 ## end   gnulib module wchar-tests
 
+## begin gnulib module yield
+
+libtests_a_SOURCES += glthread/yield.h
+
+## end   gnulib module yield
+
 # Clean up after Solaris cc.
 clean-local:
        rm -rf SunWS_cache
diff --git a/gl/tests/dup2.c b/gl/tests/dup2.c
index 234bdfe..790c98a 100644
--- a/gl/tests/dup2.c
+++ b/gl/tests/dup2.c
@@ -25,47 +25,39 @@
 #include <errno.h>
 #include <fcntl.h>
 
-#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
-/* Get declarations of the Win32 API functions.  */
-# define WIN32_LEAN_AND_MEAN
-# include <windows.h>
-#endif
-
-#include "msvc-inval.h"
-
 #if HAVE_DUP2
 
 # undef dup2
 
-int
-rpl_dup2 (int fd, int desired_fd)
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+/* Get declarations of the Win32 API functions.  */
+#  define WIN32_LEAN_AND_MEAN
+#  include <windows.h>
+
+#  include "msvc-inval.h"
+
+/* Get _get_osfhandle.  */
+#  include "msvc-nothrow.h"
+
+static int
+ms_windows_dup2 (int fd, int desired_fd)
 {
   int result;
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
   /* If fd is closed, mingw hangs on dup2 (fd, fd).  If fd is open,
      dup2 (fd, fd) returns 0, but all further attempts to use fd in
      future dup2 calls will hang.  */
   if (fd == desired_fd)
     {
-      HANDLE handle;
-
-      TRY_MSVC_INVAL
-        {
-          handle = (HANDLE) _get_osfhandle (fd);
-        }
-      CATCH_MSVC_INVAL
-        {
-          handle = INVALID_HANDLE_VALUE;
-        }
-      DONE_MSVC_INVAL;
-
-      if (handle == INVALID_HANDLE_VALUE)
+      if ((HANDLE) _get_osfhandle (fd) == INVALID_HANDLE_VALUE)
         {
           errno = EBADF;
           return -1;
         }
       return fd;
     }
+
   /* Wine 1.0.1 return 0 when desired_fd is negative but not -1:
      http://bugs.winehq.org/show_bug.cgi?id=21289 */
   if (desired_fd < 0)
@@ -73,11 +65,6 @@ rpl_dup2 (int fd, int desired_fd)
       errno = EBADF;
       return -1;
     }
-# elif !defined __linux__
-  /* On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC.  */
-  if (fd == desired_fd)
-    return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
-# endif
 
   TRY_MSVC_INVAL
     {
@@ -85,25 +72,38 @@ rpl_dup2 (int fd, int desired_fd)
     }
   CATCH_MSVC_INVAL
     {
-      result = -1;
       errno = EBADF;
+      result = -1;
     }
   DONE_MSVC_INVAL;
 
-# ifdef __linux__
-  /* Correct a Linux return value.
-     
<http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6.30.y.git;a=commitdiff;h=2b79bc4f7ebbd5af3c8b867968f9f15602d5f802>
-   */
-  if (fd == desired_fd && result == (unsigned int) -EBADF)
-    {
-      errno = EBADF;
-      result = -1;
-    }
-# endif
   if (result == 0)
     result = desired_fd;
-  /* Correct a cygwin 1.5.x errno value.  */
-  else if (result == -1 && errno == EMFILE)
+
+  return result;
+}
+
+#  define dup2 ms_windows_dup2
+
+# endif
+
+int
+rpl_dup2 (int fd, int desired_fd)
+{
+  int result;
+
+# ifdef F_GETFL
+  /* On Linux kernels 2.6.26-2.6.29, dup2 (fd, fd) returns -EBADF.
+     On Cygwin 1.5.x, dup2 (1, 1) returns 0.
+     On Haiku, dup2 (fd, fd) mistakenly clears FD_CLOEXEC.  */
+  if (fd == desired_fd)
+    return fcntl (fd, F_GETFL) == -1 ? -1 : fd;
+# endif
+
+  result = dup2 (fd, desired_fd);
+
+  /* Correct an errno value on FreeBSD 6.1 and Cygwin 1.5.x.  */
+  if (result == -1 && errno == EMFILE)
     errno = EBADF;
 # if REPLACE_FCHDIR
   if (fd != desired_fd && result != -1)
diff --git a/gl/tests/fdopen.c b/gl/tests/fdopen.c
new file mode 100644
index 0000000..50c889b
--- /dev/null
+++ b/gl/tests/fdopen.c
@@ -0,0 +1,69 @@
+/* Open a stream with a given file descriptor.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+#include <errno.h>
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+# include "msvc-inval.h"
+#endif
+
+#undef fdopen
+
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+static FILE *
+fdopen_nothrow (int fd, const char *mode)
+{
+  FILE *result;
+
+  TRY_MSVC_INVAL
+    {
+      result = fdopen (fd, mode);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = NULL;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#else
+# define fdopen_nothrow fdopen
+#endif
+
+FILE *
+rpl_fdopen (int fd, const char *mode)
+{
+  int saved_errno = errno;
+  FILE *fp;
+
+  errno = 0;
+  fp = fdopen_nothrow (fd, mode);
+  if (fp == NULL)
+    {
+      if (errno == 0)
+        errno = EBADF;
+    }
+  else
+    errno = saved_errno;
+
+  return fp;
+}
diff --git a/gl/tests/ftruncate.c b/gl/tests/ftruncate.c
new file mode 100644
index 0000000..ae1e858
--- /dev/null
+++ b/gl/tests/ftruncate.c
@@ -0,0 +1,43 @@
+/* ftruncate emulations for native Windows.
+   This file is in the public domain.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <unistd.h>
+
+#if HAVE_CHSIZE
+
+# include <errno.h>
+# include <io.h>
+
+# if HAVE_MSVC_INVALID_PARAMETER_HANDLER
+#  include "msvc-inval.h"
+static inline int
+chsize_nothrow (int fd, long length)
+{
+  int result;
+
+  TRY_MSVC_INVAL
+    {
+      result = chsize (fd, length);
+    }
+  CATCH_MSVC_INVAL
+    {
+      result = -1;
+      errno = EBADF;
+    }
+  DONE_MSVC_INVAL;
+
+  return result;
+}
+#  define chsize chsize_nothrow
+# endif
+
+int
+ftruncate (int fd, off_t length)
+{
+  return chsize (fd, length);
+}
+
+#endif
diff --git a/gl/tests/glthread/lock.c b/gl/tests/glthread/lock.c
new file mode 100644
index 0000000..64dbd3f
--- /dev/null
+++ b/gl/tests/glthread/lock.c
@@ -0,0 +1,1058 @@
+/* Locking in multithreaded situations.
+   Copyright (C) 2005-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* Written by Bruno Haible <address@hidden>, 2005.
+   Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
+   gthr-win32.h.  */
+
+#include <config.h>
+
+#include "glthread/lock.h"
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+# if HAVE_PTHREAD_RWLOCK
+
+#  if !defined PTHREAD_RWLOCK_INITIALIZER
+
+int
+glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  err = pthread_rwlock_init (&lock->rwlock, NULL);
+  if (err != 0)
+    return err;
+  lock->initialized = 1;
+  return 0;
+}
+
+int
+glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
+{
+  if (!lock->initialized)
+    {
+      int err;
+
+      err = pthread_mutex_lock (&lock->guard);
+      if (err != 0)
+        return err;
+      if (!lock->initialized)
+        {
+          err = glthread_rwlock_init_multithreaded (lock);
+          if (err != 0)
+            {
+              pthread_mutex_unlock (&lock->guard);
+              return err;
+            }
+        }
+      err = pthread_mutex_unlock (&lock->guard);
+      if (err != 0)
+        return err;
+    }
+  return pthread_rwlock_rdlock (&lock->rwlock);
+}
+
+int
+glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
+{
+  if (!lock->initialized)
+    {
+      int err;
+
+      err = pthread_mutex_lock (&lock->guard);
+      if (err != 0)
+        return err;
+      if (!lock->initialized)
+        {
+          err = glthread_rwlock_init_multithreaded (lock);
+          if (err != 0)
+            {
+              pthread_mutex_unlock (&lock->guard);
+              return err;
+            }
+        }
+      err = pthread_mutex_unlock (&lock->guard);
+      if (err != 0)
+        return err;
+    }
+  return pthread_rwlock_wrlock (&lock->rwlock);
+}
+
+int
+glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
+{
+  if (!lock->initialized)
+    return EINVAL;
+  return pthread_rwlock_unlock (&lock->rwlock);
+}
+
+int
+glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  if (!lock->initialized)
+    return EINVAL;
+  err = pthread_rwlock_destroy (&lock->rwlock);
+  if (err != 0)
+    return err;
+  lock->initialized = 0;
+  return 0;
+}
+
+#  endif
+
+# else
+
+int
+glthread_rwlock_init_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  err = pthread_mutex_init (&lock->lock, NULL);
+  if (err != 0)
+    return err;
+  err = pthread_cond_init (&lock->waiting_readers, NULL);
+  if (err != 0)
+    return err;
+  err = pthread_cond_init (&lock->waiting_writers, NULL);
+  if (err != 0)
+    return err;
+  lock->waiting_writers_count = 0;
+  lock->runcount = 0;
+  return 0;
+}
+
+int
+glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  err = pthread_mutex_lock (&lock->lock);
+  if (err != 0)
+    return err;
+  /* Test whether only readers are currently running, and whether the runcount
+     field will not overflow.  */
+  /* POSIX says: "It is implementation-defined whether the calling thread
+     acquires the lock when a writer does not hold the lock and there are
+     writers blocked on the lock."  Let's say, no: give the writers a higher
+     priority.  */
+  while (!(lock->runcount + 1 > 0 && lock->waiting_writers_count == 0))
+    {
+      /* This thread has to wait for a while.  Enqueue it among the
+         waiting_readers.  */
+      err = pthread_cond_wait (&lock->waiting_readers, &lock->lock);
+      if (err != 0)
+        {
+          pthread_mutex_unlock (&lock->lock);
+          return err;
+        }
+    }
+  lock->runcount++;
+  return pthread_mutex_unlock (&lock->lock);
+}
+
+int
+glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  err = pthread_mutex_lock (&lock->lock);
+  if (err != 0)
+    return err;
+  /* Test whether no readers or writers are currently running.  */
+  while (!(lock->runcount == 0))
+    {
+      /* This thread has to wait for a while.  Enqueue it among the
+         waiting_writers.  */
+      lock->waiting_writers_count++;
+      err = pthread_cond_wait (&lock->waiting_writers, &lock->lock);
+      if (err != 0)
+        {
+          lock->waiting_writers_count--;
+          pthread_mutex_unlock (&lock->lock);
+          return err;
+        }
+      lock->waiting_writers_count--;
+    }
+  lock->runcount--; /* runcount becomes -1 */
+  return pthread_mutex_unlock (&lock->lock);
+}
+
+int
+glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  err = pthread_mutex_lock (&lock->lock);
+  if (err != 0)
+    return err;
+  if (lock->runcount < 0)
+    {
+      /* Drop a writer lock.  */
+      if (!(lock->runcount == -1))
+        {
+          pthread_mutex_unlock (&lock->lock);
+          return EINVAL;
+        }
+      lock->runcount = 0;
+    }
+  else
+    {
+      /* Drop a reader lock.  */
+      if (!(lock->runcount > 0))
+        {
+          pthread_mutex_unlock (&lock->lock);
+          return EINVAL;
+        }
+      lock->runcount--;
+    }
+  if (lock->runcount == 0)
+    {
+      /* POSIX recommends that "write locks shall take precedence over read
+         locks", to avoid "writer starvation".  */
+      if (lock->waiting_writers_count > 0)
+        {
+          /* Wake up one of the waiting writers.  */
+          err = pthread_cond_signal (&lock->waiting_writers);
+          if (err != 0)
+            {
+              pthread_mutex_unlock (&lock->lock);
+              return err;
+            }
+        }
+      else
+        {
+          /* Wake up all waiting readers.  */
+          err = pthread_cond_broadcast (&lock->waiting_readers);
+          if (err != 0)
+            {
+              pthread_mutex_unlock (&lock->lock);
+              return err;
+            }
+        }
+    }
+  return pthread_mutex_unlock (&lock->lock);
+}
+
+int
+glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock)
+{
+  int err;
+
+  err = pthread_mutex_destroy (&lock->lock);
+  if (err != 0)
+    return err;
+  err = pthread_cond_destroy (&lock->waiting_readers);
+  if (err != 0)
+    return err;
+  err = pthread_cond_destroy (&lock->waiting_writers);
+  if (err != 0)
+    return err;
+  return 0;
+}
+
+# endif
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+# if HAVE_PTHREAD_MUTEX_RECURSIVE
+
+#  if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined 
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+
+int
+glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
+{
+  pthread_mutexattr_t attributes;
+  int err;
+
+  err = pthread_mutexattr_init (&attributes);
+  if (err != 0)
+    return err;
+  err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
+  if (err != 0)
+    {
+      pthread_mutexattr_destroy (&attributes);
+      return err;
+    }
+  err = pthread_mutex_init (lock, &attributes);
+  if (err != 0)
+    {
+      pthread_mutexattr_destroy (&attributes);
+      return err;
+    }
+  err = pthread_mutexattr_destroy (&attributes);
+  if (err != 0)
+    return err;
+  return 0;
+}
+
+#  else
+
+int
+glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
+{
+  pthread_mutexattr_t attributes;
+  int err;
+
+  err = pthread_mutexattr_init (&attributes);
+  if (err != 0)
+    return err;
+  err = pthread_mutexattr_settype (&attributes, PTHREAD_MUTEX_RECURSIVE);
+  if (err != 0)
+    {
+      pthread_mutexattr_destroy (&attributes);
+      return err;
+    }
+  err = pthread_mutex_init (&lock->recmutex, &attributes);
+  if (err != 0)
+    {
+      pthread_mutexattr_destroy (&attributes);
+      return err;
+    }
+  err = pthread_mutexattr_destroy (&attributes);
+  if (err != 0)
+    return err;
+  lock->initialized = 1;
+  return 0;
+}
+
+int
+glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
+{
+  if (!lock->initialized)
+    {
+      int err;
+
+      err = pthread_mutex_lock (&lock->guard);
+      if (err != 0)
+        return err;
+      if (!lock->initialized)
+        {
+          err = glthread_recursive_lock_init_multithreaded (lock);
+          if (err != 0)
+            {
+              pthread_mutex_unlock (&lock->guard);
+              return err;
+            }
+        }
+      err = pthread_mutex_unlock (&lock->guard);
+      if (err != 0)
+        return err;
+    }
+  return pthread_mutex_lock (&lock->recmutex);
+}
+
+int
+glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
+{
+  if (!lock->initialized)
+    return EINVAL;
+  return pthread_mutex_unlock (&lock->recmutex);
+}
+
+int
+glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
+{
+  int err;
+
+  if (!lock->initialized)
+    return EINVAL;
+  err = pthread_mutex_destroy (&lock->recmutex);
+  if (err != 0)
+    return err;
+  lock->initialized = 0;
+  return 0;
+}
+
+#  endif
+
+# else
+
+int
+glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
+{
+  int err;
+
+  err = pthread_mutex_init (&lock->mutex, NULL);
+  if (err != 0)
+    return err;
+  lock->owner = (pthread_t) 0;
+  lock->depth = 0;
+  return 0;
+}
+
+int
+glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
+{
+  pthread_t self = pthread_self ();
+  if (lock->owner != self)
+    {
+      int err;
+
+      err = pthread_mutex_lock (&lock->mutex);
+      if (err != 0)
+        return err;
+      lock->owner = self;
+    }
+  if (++(lock->depth) == 0) /* wraparound? */
+    {
+      lock->depth--;
+      return EAGAIN;
+    }
+  return 0;
+}
+
+int
+glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
+{
+  if (lock->owner != pthread_self ())
+    return EPERM;
+  if (lock->depth == 0)
+    return EINVAL;
+  if (--(lock->depth) == 0)
+    {
+      lock->owner = (pthread_t) 0;
+      return pthread_mutex_unlock (&lock->mutex);
+    }
+  else
+    return 0;
+}
+
+int
+glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
+{
+  if (lock->owner != (pthread_t) 0)
+    return EBUSY;
+  return pthread_mutex_destroy (&lock->mutex);
+}
+
+# endif
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+static const pthread_once_t fresh_once = PTHREAD_ONCE_INIT;
+
+int
+glthread_once_singlethreaded (pthread_once_t *once_control)
+{
+  /* We don't know whether pthread_once_t is an integer type, a floating-point
+     type, a pointer type, or a structure type.  */
+  char *firstbyte = (char *)once_control;
+  if (*firstbyte == *(const char *)&fresh_once)
+    {
+      /* First time use of once_control.  Invert the first byte.  */
+      *firstbyte = ~ *(const char *)&fresh_once;
+      return 1;
+    }
+  else
+    return 0;
+}
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+/* Use the GNU Pth threads library.  */
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+static void
+glthread_once_call (void *arg)
+{
+  void (**gl_once_temp_addr) (void) = (void (**) (void)) arg;
+  void (*initfunction) (void) = *gl_once_temp_addr;
+  initfunction ();
+}
+
+int
+glthread_once_multithreaded (pth_once_t *once_control, void (*initfunction) 
(void))
+{
+  void (*temp) (void) = initfunction;
+  return (!pth_once (once_control, glthread_once_call, &temp) ? errno : 0);
+}
+
+int
+glthread_once_singlethreaded (pth_once_t *once_control)
+{
+  /* We know that pth_once_t is an integer type.  */
+  if (*once_control == PTH_ONCE_INIT)
+    {
+      /* First time use of once_control.  Invert the marker.  */
+      *once_control = ~ PTH_ONCE_INIT;
+      return 1;
+    }
+  else
+    return 0;
+}
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library.  */
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+int
+glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t *lock)
+{
+  int err;
+
+  err = mutex_init (&lock->mutex, USYNC_THREAD, NULL);
+  if (err != 0)
+    return err;
+  lock->owner = (thread_t) 0;
+  lock->depth = 0;
+  return 0;
+}
+
+int
+glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t *lock)
+{
+  thread_t self = thr_self ();
+  if (lock->owner != self)
+    {
+      int err;
+
+      err = mutex_lock (&lock->mutex);
+      if (err != 0)
+        return err;
+      lock->owner = self;
+    }
+  if (++(lock->depth) == 0) /* wraparound? */
+    {
+      lock->depth--;
+      return EAGAIN;
+    }
+  return 0;
+}
+
+int
+glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t *lock)
+{
+  if (lock->owner != thr_self ())
+    return EPERM;
+  if (lock->depth == 0)
+    return EINVAL;
+  if (--(lock->depth) == 0)
+    {
+      lock->owner = (thread_t) 0;
+      return mutex_unlock (&lock->mutex);
+    }
+  else
+    return 0;
+}
+
+int
+glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t *lock)
+{
+  if (lock->owner != (thread_t) 0)
+    return EBUSY;
+  return mutex_destroy (&lock->mutex);
+}
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+int
+glthread_once_multithreaded (gl_once_t *once_control, void (*initfunction) 
(void))
+{
+  if (!once_control->inited)
+    {
+      int err;
+
+      /* Use the mutex to guarantee that if another thread is already calling
+         the initfunction, this thread waits until it's finished.  */
+      err = mutex_lock (&once_control->mutex);
+      if (err != 0)
+        return err;
+      if (!once_control->inited)
+        {
+          once_control->inited = 1;
+          initfunction ();
+        }
+      return mutex_unlock (&once_control->mutex);
+    }
+  else
+    return 0;
+}
+
+int
+glthread_once_singlethreaded (gl_once_t *once_control)
+{
+  /* We know that gl_once_t contains an integer type.  */
+  if (!once_control->inited)
+    {
+      /* First time use of once_control.  Invert the marker.  */
+      once_control->inited = ~ 0;
+      return 1;
+    }
+  else
+    return 0;
+}
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WIN32_THREADS
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+void
+glthread_lock_init_func (gl_lock_t *lock)
+{
+  InitializeCriticalSection (&lock->lock);
+  lock->guard.done = 1;
+}
+
+int
+glthread_lock_lock_func (gl_lock_t *lock)
+{
+  if (!lock->guard.done)
+    {
+      if (InterlockedIncrement (&lock->guard.started) == 0)
+        /* This thread is the first one to need this lock.  Initialize it.  */
+        glthread_lock_init (lock);
+      else
+        /* Yield the CPU while waiting for another thread to finish
+           initializing this lock.  */
+        while (!lock->guard.done)
+          Sleep (0);
+    }
+  EnterCriticalSection (&lock->lock);
+  return 0;
+}
+
+int
+glthread_lock_unlock_func (gl_lock_t *lock)
+{
+  if (!lock->guard.done)
+    return EINVAL;
+  LeaveCriticalSection (&lock->lock);
+  return 0;
+}
+
+int
+glthread_lock_destroy_func (gl_lock_t *lock)
+{
+  if (!lock->guard.done)
+    return EINVAL;
+  DeleteCriticalSection (&lock->lock);
+  lock->guard.done = 0;
+  return 0;
+}
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+/* In this file, the waitqueues are implemented as circular arrays.  */
+#define gl_waitqueue_t gl_carray_waitqueue_t
+
+static inline void
+gl_waitqueue_init (gl_waitqueue_t *wq)
+{
+  wq->array = NULL;
+  wq->count = 0;
+  wq->alloc = 0;
+  wq->offset = 0;
+}
+
+/* Enqueues the current thread, represented by an event, in a wait queue.
+   Returns INVALID_HANDLE_VALUE if an allocation failure occurs.  */
+static HANDLE
+gl_waitqueue_add (gl_waitqueue_t *wq)
+{
+  HANDLE event;
+  unsigned int index;
+
+  if (wq->count == wq->alloc)
+    {
+      unsigned int new_alloc = 2 * wq->alloc + 1;
+      HANDLE *new_array =
+        (HANDLE *) realloc (wq->array, new_alloc * sizeof (HANDLE));
+      if (new_array == NULL)
+        /* No more memory.  */
+        return INVALID_HANDLE_VALUE;
+      /* Now is a good opportunity to rotate the array so that its contents
+         starts at offset 0.  */
+      if (wq->offset > 0)
+        {
+          unsigned int old_count = wq->count;
+          unsigned int old_alloc = wq->alloc;
+          unsigned int old_offset = wq->offset;
+          unsigned int i;
+          if (old_offset + old_count > old_alloc)
+            {
+              unsigned int limit = old_offset + old_count - old_alloc;
+              for (i = 0; i < limit; i++)
+                new_array[old_alloc + i] = new_array[i];
+            }
+          for (i = 0; i < old_count; i++)
+            new_array[i] = new_array[old_offset + i];
+          wq->offset = 0;
+        }
+      wq->array = new_array;
+      wq->alloc = new_alloc;
+    }
+  /* Whether the created event is a manual-reset one or an auto-reset one,
+     does not matter, since we will wait on it only once.  */
+  event = CreateEvent (NULL, TRUE, FALSE, NULL);
+  if (event == INVALID_HANDLE_VALUE)
+    /* No way to allocate an event.  */
+    return INVALID_HANDLE_VALUE;
+  index = wq->offset + wq->count;
+  if (index >= wq->alloc)
+    index -= wq->alloc;
+  wq->array[index] = event;
+  wq->count++;
+  return event;
+}
+
+/* Notifies the first thread from a wait queue and dequeues it.  */
+static inline void
+gl_waitqueue_notify_first (gl_waitqueue_t *wq)
+{
+  SetEvent (wq->array[wq->offset + 0]);
+  wq->offset++;
+  wq->count--;
+  if (wq->count == 0 || wq->offset == wq->alloc)
+    wq->offset = 0;
+}
+
+/* Notifies all threads from a wait queue and dequeues them all.  */
+static inline void
+gl_waitqueue_notify_all (gl_waitqueue_t *wq)
+{
+  unsigned int i;
+
+  for (i = 0; i < wq->count; i++)
+    {
+      unsigned int index = wq->offset + i;
+      if (index >= wq->alloc)
+        index -= wq->alloc;
+      SetEvent (wq->array[index]);
+    }
+  wq->count = 0;
+  wq->offset = 0;
+}
+
+void
+glthread_rwlock_init_func (gl_rwlock_t *lock)
+{
+  InitializeCriticalSection (&lock->lock);
+  gl_waitqueue_init (&lock->waiting_readers);
+  gl_waitqueue_init (&lock->waiting_writers);
+  lock->runcount = 0;
+  lock->guard.done = 1;
+}
+
+int
+glthread_rwlock_rdlock_func (gl_rwlock_t *lock)
+{
+  if (!lock->guard.done)
+    {
+      if (InterlockedIncrement (&lock->guard.started) == 0)
+        /* This thread is the first one to need this lock.  Initialize it.  */
+        glthread_rwlock_init (lock);
+      else
+        /* Yield the CPU while waiting for another thread to finish
+           initializing this lock.  */
+        while (!lock->guard.done)
+          Sleep (0);
+    }
+  EnterCriticalSection (&lock->lock);
+  /* Test whether only readers are currently running, and whether the runcount
+     field will not overflow.  */
+  if (!(lock->runcount + 1 > 0))
+    {
+      /* This thread has to wait for a while.  Enqueue it among the
+         waiting_readers.  */
+      HANDLE event = gl_waitqueue_add (&lock->waiting_readers);
+      if (event != INVALID_HANDLE_VALUE)
+        {
+          DWORD result;
+          LeaveCriticalSection (&lock->lock);
+          /* Wait until another thread signals this event.  */
+          result = WaitForSingleObject (event, INFINITE);
+          if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
+            abort ();
+          CloseHandle (event);
+          /* The thread which signalled the event already did the bookkeeping:
+             removed us from the waiting_readers, incremented lock->runcount.  
*/
+          if (!(lock->runcount > 0))
+            abort ();
+          return 0;
+        }
+      else
+        {
+          /* Allocation failure.  Weird.  */
+          do
+            {
+              LeaveCriticalSection (&lock->lock);
+              Sleep (1);
+              EnterCriticalSection (&lock->lock);
+            }
+          while (!(lock->runcount + 1 > 0));
+        }
+    }
+  lock->runcount++;
+  LeaveCriticalSection (&lock->lock);
+  return 0;
+}
+
+int
+glthread_rwlock_wrlock_func (gl_rwlock_t *lock)
+{
+  if (!lock->guard.done)
+    {
+      if (InterlockedIncrement (&lock->guard.started) == 0)
+        /* This thread is the first one to need this lock.  Initialize it.  */
+        glthread_rwlock_init (lock);
+      else
+        /* Yield the CPU while waiting for another thread to finish
+           initializing this lock.  */
+        while (!lock->guard.done)
+          Sleep (0);
+    }
+  EnterCriticalSection (&lock->lock);
+  /* Test whether no readers or writers are currently running.  */
+  if (!(lock->runcount == 0))
+    {
+      /* This thread has to wait for a while.  Enqueue it among the
+         waiting_writers.  */
+      HANDLE event = gl_waitqueue_add (&lock->waiting_writers);
+      if (event != INVALID_HANDLE_VALUE)
+        {
+          DWORD result;
+          LeaveCriticalSection (&lock->lock);
+          /* Wait until another thread signals this event.  */
+          result = WaitForSingleObject (event, INFINITE);
+          if (result == WAIT_FAILED || result == WAIT_TIMEOUT)
+            abort ();
+          CloseHandle (event);
+          /* The thread which signalled the event already did the bookkeeping:
+             removed us from the waiting_writers, set lock->runcount = -1.  */
+          if (!(lock->runcount == -1))
+            abort ();
+          return 0;
+        }
+      else
+        {
+          /* Allocation failure.  Weird.  */
+          do
+            {
+              LeaveCriticalSection (&lock->lock);
+              Sleep (1);
+              EnterCriticalSection (&lock->lock);
+            }
+          while (!(lock->runcount == 0));
+        }
+    }
+  lock->runcount--; /* runcount becomes -1 */
+  LeaveCriticalSection (&lock->lock);
+  return 0;
+}
+
+int
+glthread_rwlock_unlock_func (gl_rwlock_t *lock)
+{
+  if (!lock->guard.done)
+    return EINVAL;
+  EnterCriticalSection (&lock->lock);
+  if (lock->runcount < 0)
+    {
+      /* Drop a writer lock.  */
+      if (!(lock->runcount == -1))
+        abort ();
+      lock->runcount = 0;
+    }
+  else
+    {
+      /* Drop a reader lock.  */
+      if (!(lock->runcount > 0))
+        {
+          LeaveCriticalSection (&lock->lock);
+          return EPERM;
+        }
+      lock->runcount--;
+    }
+  if (lock->runcount == 0)
+    {
+      /* POSIX recommends that "write locks shall take precedence over read
+         locks", to avoid "writer starvation".  */
+      if (lock->waiting_writers.count > 0)
+        {
+          /* Wake up one of the waiting writers.  */
+          lock->runcount--;
+          gl_waitqueue_notify_first (&lock->waiting_writers);
+        }
+      else
+        {
+          /* Wake up all waiting readers.  */
+          lock->runcount += lock->waiting_readers.count;
+          gl_waitqueue_notify_all (&lock->waiting_readers);
+        }
+    }
+  LeaveCriticalSection (&lock->lock);
+  return 0;
+}
+
+int
+glthread_rwlock_destroy_func (gl_rwlock_t *lock)
+{
+  if (!lock->guard.done)
+    return EINVAL;
+  if (lock->runcount != 0)
+    return EBUSY;
+  DeleteCriticalSection (&lock->lock);
+  if (lock->waiting_readers.array != NULL)
+    free (lock->waiting_readers.array);
+  if (lock->waiting_writers.array != NULL)
+    free (lock->waiting_writers.array);
+  lock->guard.done = 0;
+  return 0;
+}
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+void
+glthread_recursive_lock_init_func (gl_recursive_lock_t *lock)
+{
+  lock->owner = 0;
+  lock->depth = 0;
+  InitializeCriticalSection (&lock->lock);
+  lock->guard.done = 1;
+}
+
+int
+glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock)
+{
+  if (!lock->guard.done)
+    {
+      if (InterlockedIncrement (&lock->guard.started) == 0)
+        /* This thread is the first one to need this lock.  Initialize it.  */
+        glthread_recursive_lock_init (lock);
+      else
+        /* Yield the CPU while waiting for another thread to finish
+           initializing this lock.  */
+        while (!lock->guard.done)
+          Sleep (0);
+    }
+  {
+    DWORD self = GetCurrentThreadId ();
+    if (lock->owner != self)
+      {
+        EnterCriticalSection (&lock->lock);
+        lock->owner = self;
+      }
+    if (++(lock->depth) == 0) /* wraparound? */
+      {
+        lock->depth--;
+        return EAGAIN;
+      }
+  }
+  return 0;
+}
+
+int
+glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock)
+{
+  if (lock->owner != GetCurrentThreadId ())
+    return EPERM;
+  if (lock->depth == 0)
+    return EINVAL;
+  if (--(lock->depth) == 0)
+    {
+      lock->owner = 0;
+      LeaveCriticalSection (&lock->lock);
+    }
+  return 0;
+}
+
+int
+glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock)
+{
+  if (lock->owner != 0)
+    return EBUSY;
+  DeleteCriticalSection (&lock->lock);
+  lock->guard.done = 0;
+  return 0;
+}
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+void
+glthread_once_func (gl_once_t *once_control, void (*initfunction) (void))
+{
+  if (once_control->inited <= 0)
+    {
+      if (InterlockedIncrement (&once_control->started) == 0)
+        {
+          /* This thread is the first one to come to this once_control.  */
+          InitializeCriticalSection (&once_control->lock);
+          EnterCriticalSection (&once_control->lock);
+          once_control->inited = 0;
+          initfunction ();
+          once_control->inited = 1;
+          LeaveCriticalSection (&once_control->lock);
+        }
+      else
+        {
+          /* Undo last operation.  */
+          InterlockedDecrement (&once_control->started);
+          /* Some other thread has already started the initialization.
+             Yield the CPU while waiting for the other thread to finish
+             initializing and taking the lock.  */
+          while (once_control->inited < 0)
+            Sleep (0);
+          if (once_control->inited <= 0)
+            {
+              /* Take the lock.  This blocks until the other thread has
+                 finished calling the initfunction.  */
+              EnterCriticalSection (&once_control->lock);
+              LeaveCriticalSection (&once_control->lock);
+              if (!(once_control->inited > 0))
+                abort ();
+            }
+        }
+    }
+}
+
+#endif
+
+/* ========================================================================= */
diff --git a/gl/tests/glthread/lock.h b/gl/tests/glthread/lock.h
new file mode 100644
index 0000000..028d881
--- /dev/null
+++ b/gl/tests/glthread/lock.h
@@ -0,0 +1,928 @@
+/* Locking in multithreaded situations.
+   Copyright (C) 2005-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* Written by Bruno Haible <address@hidden>, 2005.
+   Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
+   gthr-win32.h.  */
+
+/* This file contains locking primitives for use with a given thread library.
+   It does not contain primitives for creating threads or for other
+   synchronization primitives.
+
+   Normal (non-recursive) locks:
+     Type:                gl_lock_t
+     Declaration:         gl_lock_define(extern, name)
+     Initializer:         gl_lock_define_initialized(, name)
+     Initialization:      gl_lock_init (name);
+     Taking the lock:     gl_lock_lock (name);
+     Releasing the lock:  gl_lock_unlock (name);
+     De-initialization:   gl_lock_destroy (name);
+   Equivalent functions with control of error handling:
+     Initialization:      err = glthread_lock_init (&name);
+     Taking the lock:     err = glthread_lock_lock (&name);
+     Releasing the lock:  err = glthread_lock_unlock (&name);
+     De-initialization:   err = glthread_lock_destroy (&name);
+
+   Read-Write (non-recursive) locks:
+     Type:                gl_rwlock_t
+     Declaration:         gl_rwlock_define(extern, name)
+     Initializer:         gl_rwlock_define_initialized(, name)
+     Initialization:      gl_rwlock_init (name);
+     Taking the lock:     gl_rwlock_rdlock (name);
+                          gl_rwlock_wrlock (name);
+     Releasing the lock:  gl_rwlock_unlock (name);
+     De-initialization:   gl_rwlock_destroy (name);
+   Equivalent functions with control of error handling:
+     Initialization:      err = glthread_rwlock_init (&name);
+     Taking the lock:     err = glthread_rwlock_rdlock (&name);
+                          err = glthread_rwlock_wrlock (&name);
+     Releasing the lock:  err = glthread_rwlock_unlock (&name);
+     De-initialization:   err = glthread_rwlock_destroy (&name);
+
+   Recursive locks:
+     Type:                gl_recursive_lock_t
+     Declaration:         gl_recursive_lock_define(extern, name)
+     Initializer:         gl_recursive_lock_define_initialized(, name)
+     Initialization:      gl_recursive_lock_init (name);
+     Taking the lock:     gl_recursive_lock_lock (name);
+     Releasing the lock:  gl_recursive_lock_unlock (name);
+     De-initialization:   gl_recursive_lock_destroy (name);
+   Equivalent functions with control of error handling:
+     Initialization:      err = glthread_recursive_lock_init (&name);
+     Taking the lock:     err = glthread_recursive_lock_lock (&name);
+     Releasing the lock:  err = glthread_recursive_lock_unlock (&name);
+     De-initialization:   err = glthread_recursive_lock_destroy (&name);
+
+  Once-only execution:
+     Type:                gl_once_t
+     Initializer:         gl_once_define(extern, name)
+     Execution:           gl_once (name, initfunction);
+   Equivalent functions with control of error handling:
+     Execution:           err = glthread_once (&name, initfunction);
+*/
+
+
+#ifndef _LOCK_H
+#define _LOCK_H
+
+#include <errno.h>
+#include <stdlib.h>
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* Use the POSIX threads library.  */
+
+# include <pthread.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if PTHREAD_IN_USE_DETECTION_HARD
+
+/* The pthread_in_use() detection needs to be done at runtime.  */
+#  define pthread_in_use() \
+     glthread_in_use ()
+extern int glthread_in_use (void);
+
+# endif
+
+# if USE_POSIX_THREADS_WEAK
+
+/* Use weak references to the POSIX threads library.  */
+
+/* Weak references avoid dragging in external libraries if the other parts
+   of the program don't use them.  Here we use them, because we don't want
+   every program that uses libintl to depend on libpthread.  This assumes
+   that libpthread would not be loaded after libintl; i.e. if libintl is
+   loaded first, by an executable that does not depend on libpthread, and
+   then a module is dynamically loaded that depends on libpthread, libintl
+   will not be multithread-safe.  */
+
+/* The way to test at runtime whether libpthread is present is to test
+   whether a function pointer's value, such as &pthread_mutex_init, is
+   non-NULL.  However, some versions of GCC have a bug through which, in
+   PIC mode, &foo != NULL always evaluates to true if there is a direct
+   call to foo(...) in the same function.  To avoid this, we test the
+   address of a function in libpthread that we don't use.  */
+
+#  pragma weak pthread_mutex_init
+#  pragma weak pthread_mutex_lock
+#  pragma weak pthread_mutex_unlock
+#  pragma weak pthread_mutex_destroy
+#  pragma weak pthread_rwlock_init
+#  pragma weak pthread_rwlock_rdlock
+#  pragma weak pthread_rwlock_wrlock
+#  pragma weak pthread_rwlock_unlock
+#  pragma weak pthread_rwlock_destroy
+#  pragma weak pthread_once
+#  pragma weak pthread_cond_init
+#  pragma weak pthread_cond_wait
+#  pragma weak pthread_cond_signal
+#  pragma weak pthread_cond_broadcast
+#  pragma weak pthread_cond_destroy
+#  pragma weak pthread_mutexattr_init
+#  pragma weak pthread_mutexattr_settype
+#  pragma weak pthread_mutexattr_destroy
+#  ifndef pthread_self
+#   pragma weak pthread_self
+#  endif
+
+#  if !PTHREAD_IN_USE_DETECTION_HARD
+#   pragma weak pthread_cancel
+#   define pthread_in_use() (pthread_cancel != NULL)
+#  endif
+
+# else
+
+#  if !PTHREAD_IN_USE_DETECTION_HARD
+#   define pthread_in_use() 1
+#  endif
+
+# endif
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef pthread_mutex_t gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME) \
+    STORAGECLASS pthread_mutex_t NAME;
+# define gl_lock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS pthread_mutex_t NAME = gl_lock_initializer;
+# define gl_lock_initializer \
+    PTHREAD_MUTEX_INITIALIZER
+# define glthread_lock_init(LOCK) \
+    (pthread_in_use () ? pthread_mutex_init (LOCK, NULL) : 0)
+# define glthread_lock_lock(LOCK) \
+    (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0)
+# define glthread_lock_unlock(LOCK) \
+    (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0)
+# define glthread_lock_destroy(LOCK) \
+    (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0)
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+# if HAVE_PTHREAD_RWLOCK
+
+#  ifdef PTHREAD_RWLOCK_INITIALIZER
+
+typedef pthread_rwlock_t gl_rwlock_t;
+#   define gl_rwlock_define(STORAGECLASS, NAME) \
+      STORAGECLASS pthread_rwlock_t NAME;
+#   define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+      STORAGECLASS pthread_rwlock_t NAME = gl_rwlock_initializer;
+#   define gl_rwlock_initializer \
+      PTHREAD_RWLOCK_INITIALIZER
+#   define glthread_rwlock_init(LOCK) \
+      (pthread_in_use () ? pthread_rwlock_init (LOCK, NULL) : 0)
+#   define glthread_rwlock_rdlock(LOCK) \
+      (pthread_in_use () ? pthread_rwlock_rdlock (LOCK) : 0)
+#   define glthread_rwlock_wrlock(LOCK) \
+      (pthread_in_use () ? pthread_rwlock_wrlock (LOCK) : 0)
+#   define glthread_rwlock_unlock(LOCK) \
+      (pthread_in_use () ? pthread_rwlock_unlock (LOCK) : 0)
+#   define glthread_rwlock_destroy(LOCK) \
+      (pthread_in_use () ? pthread_rwlock_destroy (LOCK) : 0)
+
+#  else
+
+typedef struct
+        {
+          int initialized;
+          pthread_mutex_t guard;   /* protects the initialization */
+          pthread_rwlock_t rwlock; /* read-write lock */
+        }
+        gl_rwlock_t;
+#   define gl_rwlock_define(STORAGECLASS, NAME) \
+      STORAGECLASS gl_rwlock_t NAME;
+#   define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+      STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
+#   define gl_rwlock_initializer \
+      { 0, PTHREAD_MUTEX_INITIALIZER }
+#   define glthread_rwlock_init(LOCK) \
+      (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0)
+#   define glthread_rwlock_rdlock(LOCK) \
+      (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0)
+#   define glthread_rwlock_wrlock(LOCK) \
+      (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0)
+#   define glthread_rwlock_unlock(LOCK) \
+      (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0)
+#   define glthread_rwlock_destroy(LOCK) \
+      (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0)
+extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock);
+
+#  endif
+
+# else
+
+typedef struct
+        {
+          pthread_mutex_t lock; /* protects the remaining fields */
+          pthread_cond_t waiting_readers; /* waiting readers */
+          pthread_cond_t waiting_writers; /* waiting writers */
+          unsigned int waiting_writers_count; /* number of waiting writers */
+          int runcount; /* number of readers running, or -1 when a writer runs 
*/
+        }
+        gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_rwlock_t NAME;
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
+# define gl_rwlock_initializer \
+    { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 
PTHREAD_COND_INITIALIZER, 0, 0 }
+# define glthread_rwlock_init(LOCK) \
+    (pthread_in_use () ? glthread_rwlock_init_multithreaded (LOCK) : 0)
+# define glthread_rwlock_rdlock(LOCK) \
+    (pthread_in_use () ? glthread_rwlock_rdlock_multithreaded (LOCK) : 0)
+# define glthread_rwlock_wrlock(LOCK) \
+    (pthread_in_use () ? glthread_rwlock_wrlock_multithreaded (LOCK) : 0)
+# define glthread_rwlock_unlock(LOCK) \
+    (pthread_in_use () ? glthread_rwlock_unlock_multithreaded (LOCK) : 0)
+# define glthread_rwlock_destroy(LOCK) \
+    (pthread_in_use () ? glthread_rwlock_destroy_multithreaded (LOCK) : 0)
+extern int glthread_rwlock_init_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_rdlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_wrlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_unlock_multithreaded (gl_rwlock_t *lock);
+extern int glthread_rwlock_destroy_multithreaded (gl_rwlock_t *lock);
+
+# endif
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+# if HAVE_PTHREAD_MUTEX_RECURSIVE
+
+#  if defined PTHREAD_RECURSIVE_MUTEX_INITIALIZER || defined 
PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+
+typedef pthread_mutex_t gl_recursive_lock_t;
+#   define gl_recursive_lock_define(STORAGECLASS, NAME) \
+      STORAGECLASS pthread_mutex_t NAME;
+#   define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+      STORAGECLASS pthread_mutex_t NAME = gl_recursive_lock_initializer;
+#   ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER
+#    define gl_recursive_lock_initializer \
+       PTHREAD_RECURSIVE_MUTEX_INITIALIZER
+#   else
+#    define gl_recursive_lock_initializer \
+       PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
+#   endif
+#   define glthread_recursive_lock_init(LOCK) \
+      (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 
0)
+#   define glthread_recursive_lock_lock(LOCK) \
+      (pthread_in_use () ? pthread_mutex_lock (LOCK) : 0)
+#   define glthread_recursive_lock_unlock(LOCK) \
+      (pthread_in_use () ? pthread_mutex_unlock (LOCK) : 0)
+#   define glthread_recursive_lock_destroy(LOCK) \
+      (pthread_in_use () ? pthread_mutex_destroy (LOCK) : 0)
+extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t 
*lock);
+
+#  else
+
+typedef struct
+        {
+          pthread_mutex_t recmutex; /* recursive mutex */
+          pthread_mutex_t guard;    /* protects the initialization */
+          int initialized;
+        }
+        gl_recursive_lock_t;
+#   define gl_recursive_lock_define(STORAGECLASS, NAME) \
+      STORAGECLASS gl_recursive_lock_t NAME;
+#   define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+      STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
+#   define gl_recursive_lock_initializer \
+      { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER, 0 }
+#   define glthread_recursive_lock_init(LOCK) \
+      (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 
0)
+#   define glthread_recursive_lock_lock(LOCK) \
+      (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 
0)
+#   define glthread_recursive_lock_unlock(LOCK) \
+      (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) 
: 0)
+#   define glthread_recursive_lock_destroy(LOCK) \
+      (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded 
(LOCK) : 0)
+extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t 
*lock);
+
+#  endif
+
+# else
+
+/* Old versions of POSIX threads on Solaris did not have recursive locks.
+   We have to implement them ourselves.  */
+
+typedef struct
+        {
+          pthread_mutex_t mutex;
+          pthread_t owner;
+          unsigned long depth;
+        }
+        gl_recursive_lock_t;
+#  define gl_recursive_lock_define(STORAGECLASS, NAME) \
+     STORAGECLASS gl_recursive_lock_t NAME;
+#  define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+     STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
+#  define gl_recursive_lock_initializer \
+     { PTHREAD_MUTEX_INITIALIZER, (pthread_t) 0, 0 }
+#  define glthread_recursive_lock_init(LOCK) \
+     (pthread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 
0)
+#  define glthread_recursive_lock_lock(LOCK) \
+     (pthread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 
0)
+#  define glthread_recursive_lock_unlock(LOCK) \
+     (pthread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) 
: 0)
+#  define glthread_recursive_lock_destroy(LOCK) \
+     (pthread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) 
: 0)
+extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t 
*lock);
+
+# endif
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef pthread_once_t gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+    STORAGECLASS pthread_once_t NAME = PTHREAD_ONCE_INIT;
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+    (pthread_in_use ()                                                         
\
+     ? pthread_once (ONCE_CONTROL, INITFUNCTION)                               
\
+     : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 
0))
+extern int glthread_once_singlethreaded (pthread_once_t *once_control);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+/* Use the GNU Pth threads library.  */
+
+# include <pth.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if USE_PTH_THREADS_WEAK
+
+/* Use weak references to the GNU Pth threads library.  */
+
+#  pragma weak pth_mutex_init
+#  pragma weak pth_mutex_acquire
+#  pragma weak pth_mutex_release
+#  pragma weak pth_rwlock_init
+#  pragma weak pth_rwlock_acquire
+#  pragma weak pth_rwlock_release
+#  pragma weak pth_once
+
+#  pragma weak pth_cancel
+#  define pth_in_use() (pth_cancel != NULL)
+
+# else
+
+#  define pth_in_use() 1
+
+# endif
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef pth_mutex_t gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME) \
+    STORAGECLASS pth_mutex_t NAME;
+# define gl_lock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS pth_mutex_t NAME = gl_lock_initializer;
+# define gl_lock_initializer \
+    PTH_MUTEX_INIT
+# define glthread_lock_init(LOCK) \
+    (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0)
+# define glthread_lock_lock(LOCK) \
+    (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0)
+# define glthread_lock_unlock(LOCK) \
+    (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0)
+# define glthread_lock_destroy(LOCK) \
+    ((void)(LOCK), 0)
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+typedef pth_rwlock_t gl_rwlock_t;
+#  define gl_rwlock_define(STORAGECLASS, NAME) \
+     STORAGECLASS pth_rwlock_t NAME;
+#  define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+     STORAGECLASS pth_rwlock_t NAME = gl_rwlock_initializer;
+#  define gl_rwlock_initializer \
+     PTH_RWLOCK_INIT
+#  define glthread_rwlock_init(LOCK) \
+     (pth_in_use () && !pth_rwlock_init (LOCK) ? errno : 0)
+#  define glthread_rwlock_rdlock(LOCK) \
+     (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RD, 0, NULL) ? 
errno : 0)
+#  define glthread_rwlock_wrlock(LOCK) \
+     (pth_in_use () && !pth_rwlock_acquire (LOCK, PTH_RWLOCK_RW, 0, NULL) ? 
errno : 0)
+#  define glthread_rwlock_unlock(LOCK) \
+     (pth_in_use () && !pth_rwlock_release (LOCK) ? errno : 0)
+#  define glthread_rwlock_destroy(LOCK) \
+     ((void)(LOCK), 0)
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+/* In Pth, mutexes are recursive by default.  */
+typedef pth_mutex_t gl_recursive_lock_t;
+#  define gl_recursive_lock_define(STORAGECLASS, NAME) \
+     STORAGECLASS pth_mutex_t NAME;
+#  define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+     STORAGECLASS pth_mutex_t NAME = gl_recursive_lock_initializer;
+#  define gl_recursive_lock_initializer \
+     PTH_MUTEX_INIT
+#  define glthread_recursive_lock_init(LOCK) \
+     (pth_in_use () && !pth_mutex_init (LOCK) ? errno : 0)
+#  define glthread_recursive_lock_lock(LOCK) \
+     (pth_in_use () && !pth_mutex_acquire (LOCK, 0, NULL) ? errno : 0)
+#  define glthread_recursive_lock_unlock(LOCK) \
+     (pth_in_use () && !pth_mutex_release (LOCK) ? errno : 0)
+#  define glthread_recursive_lock_destroy(LOCK) \
+     ((void)(LOCK), 0)
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef pth_once_t gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+    STORAGECLASS pth_once_t NAME = PTH_ONCE_INIT;
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+    (pth_in_use ()                                                             
\
+     ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION)                
\
+     : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 
0))
+extern int glthread_once_multithreaded (pth_once_t *once_control, void 
(*initfunction) (void));
+extern int glthread_once_singlethreaded (pth_once_t *once_control);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library.  */
+
+# include <thread.h>
+# include <synch.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if USE_SOLARIS_THREADS_WEAK
+
+/* Use weak references to the old Solaris threads library.  */
+
+#  pragma weak mutex_init
+#  pragma weak mutex_lock
+#  pragma weak mutex_unlock
+#  pragma weak mutex_destroy
+#  pragma weak rwlock_init
+#  pragma weak rw_rdlock
+#  pragma weak rw_wrlock
+#  pragma weak rw_unlock
+#  pragma weak rwlock_destroy
+#  pragma weak thr_self
+
+#  pragma weak thr_suspend
+#  define thread_in_use() (thr_suspend != NULL)
+
+# else
+
+#  define thread_in_use() 1
+
+# endif
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef mutex_t gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME) \
+    STORAGECLASS mutex_t NAME;
+# define gl_lock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS mutex_t NAME = gl_lock_initializer;
+# define gl_lock_initializer \
+    DEFAULTMUTEX
+# define glthread_lock_init(LOCK) \
+    (thread_in_use () ? mutex_init (LOCK, USYNC_THREAD, NULL) : 0)
+# define glthread_lock_lock(LOCK) \
+    (thread_in_use () ? mutex_lock (LOCK) : 0)
+# define glthread_lock_unlock(LOCK) \
+    (thread_in_use () ? mutex_unlock (LOCK) : 0)
+# define glthread_lock_destroy(LOCK) \
+    (thread_in_use () ? mutex_destroy (LOCK) : 0)
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+typedef rwlock_t gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME) \
+    STORAGECLASS rwlock_t NAME;
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS rwlock_t NAME = gl_rwlock_initializer;
+# define gl_rwlock_initializer \
+    DEFAULTRWLOCK
+# define glthread_rwlock_init(LOCK) \
+    (thread_in_use () ? rwlock_init (LOCK, USYNC_THREAD, NULL) : 0)
+# define glthread_rwlock_rdlock(LOCK) \
+    (thread_in_use () ? rw_rdlock (LOCK) : 0)
+# define glthread_rwlock_wrlock(LOCK) \
+    (thread_in_use () ? rw_wrlock (LOCK) : 0)
+# define glthread_rwlock_unlock(LOCK) \
+    (thread_in_use () ? rw_unlock (LOCK) : 0)
+# define glthread_rwlock_destroy(LOCK) \
+    (thread_in_use () ? rwlock_destroy (LOCK) : 0)
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+/* Old Solaris threads did not have recursive locks.
+   We have to implement them ourselves.  */
+
+typedef struct
+        {
+          mutex_t mutex;
+          thread_t owner;
+          unsigned long depth;
+        }
+        gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_recursive_lock_t NAME;
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
+# define gl_recursive_lock_initializer \
+    { DEFAULTMUTEX, (thread_t) 0, 0 }
+# define glthread_recursive_lock_init(LOCK) \
+    (thread_in_use () ? glthread_recursive_lock_init_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_lock(LOCK) \
+    (thread_in_use () ? glthread_recursive_lock_lock_multithreaded (LOCK) : 0)
+# define glthread_recursive_lock_unlock(LOCK) \
+    (thread_in_use () ? glthread_recursive_lock_unlock_multithreaded (LOCK) : 
0)
+# define glthread_recursive_lock_destroy(LOCK) \
+    (thread_in_use () ? glthread_recursive_lock_destroy_multithreaded (LOCK) : 
0)
+extern int glthread_recursive_lock_init_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_lock_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_unlock_multithreaded (gl_recursive_lock_t 
*lock);
+extern int glthread_recursive_lock_destroy_multithreaded (gl_recursive_lock_t 
*lock);
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef struct
+        {
+          volatile int inited;
+          mutex_t mutex;
+        }
+        gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_once_t NAME = { 0, DEFAULTMUTEX };
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+    (thread_in_use ()                                                          
\
+     ? glthread_once_multithreaded (ONCE_CONTROL, INITFUNCTION)                
\
+     : (glthread_once_singlethreaded (ONCE_CONTROL) ? (INITFUNCTION (), 0) : 
0))
+extern int glthread_once_multithreaded (gl_once_t *once_control, void 
(*initfunction) (void));
+extern int glthread_once_singlethreaded (gl_once_t *once_control);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WIN32_THREADS
+
+# define WIN32_LEAN_AND_MEAN  /* avoid including junk */
+# include <windows.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+/* We can use CRITICAL_SECTION directly, rather than the Win32 Event, Mutex,
+   Semaphore types, because
+     - we need only to synchronize inside a single process (address space),
+       not inter-process locking,
+     - we don't need to support trylock operations.  (TryEnterCriticalSection
+       does not work on Windows 95/98/ME.  Packages that need trylock usually
+       define their own mutex type.)  */
+
+/* There is no way to statically initialize a CRITICAL_SECTION.  It needs
+   to be done lazily, once only.  For this we need spinlocks.  */
+
+typedef struct { volatile int done; volatile long started; } gl_spinlock_t;
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef struct
+        {
+          gl_spinlock_t guard; /* protects the initialization */
+          CRITICAL_SECTION lock;
+        }
+        gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_lock_t NAME;
+# define gl_lock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS gl_lock_t NAME = gl_lock_initializer;
+# define gl_lock_initializer \
+    { { 0, -1 } }
+# define glthread_lock_init(LOCK) \
+    (glthread_lock_init_func (LOCK), 0)
+# define glthread_lock_lock(LOCK) \
+    glthread_lock_lock_func (LOCK)
+# define glthread_lock_unlock(LOCK) \
+    glthread_lock_unlock_func (LOCK)
+# define glthread_lock_destroy(LOCK) \
+    glthread_lock_destroy_func (LOCK)
+extern void glthread_lock_init_func (gl_lock_t *lock);
+extern int glthread_lock_lock_func (gl_lock_t *lock);
+extern int glthread_lock_unlock_func (gl_lock_t *lock);
+extern int glthread_lock_destroy_func (gl_lock_t *lock);
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+/* It is impossible to implement read-write locks using plain locks, without
+   introducing an extra thread dedicated to managing read-write locks.
+   Therefore here we need to use the low-level Event type.  */
+
+typedef struct
+        {
+          HANDLE *array; /* array of waiting threads, each represented by an 
event */
+          unsigned int count; /* number of waiting threads */
+          unsigned int alloc; /* length of allocated array */
+          unsigned int offset; /* index of first waiting thread in array */
+        }
+        gl_carray_waitqueue_t;
+typedef struct
+        {
+          gl_spinlock_t guard; /* protects the initialization */
+          CRITICAL_SECTION lock; /* protects the remaining fields */
+          gl_carray_waitqueue_t waiting_readers; /* waiting readers */
+          gl_carray_waitqueue_t waiting_writers; /* waiting writers */
+          int runcount; /* number of readers running, or -1 when a writer runs 
*/
+        }
+        gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_rwlock_t NAME;
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS gl_rwlock_t NAME = gl_rwlock_initializer;
+# define gl_rwlock_initializer \
+    { { 0, -1 } }
+# define glthread_rwlock_init(LOCK) \
+    (glthread_rwlock_init_func (LOCK), 0)
+# define glthread_rwlock_rdlock(LOCK) \
+    glthread_rwlock_rdlock_func (LOCK)
+# define glthread_rwlock_wrlock(LOCK) \
+    glthread_rwlock_wrlock_func (LOCK)
+# define glthread_rwlock_unlock(LOCK) \
+    glthread_rwlock_unlock_func (LOCK)
+# define glthread_rwlock_destroy(LOCK) \
+    glthread_rwlock_destroy_func (LOCK)
+extern void glthread_rwlock_init_func (gl_rwlock_t *lock);
+extern int glthread_rwlock_rdlock_func (gl_rwlock_t *lock);
+extern int glthread_rwlock_wrlock_func (gl_rwlock_t *lock);
+extern int glthread_rwlock_unlock_func (gl_rwlock_t *lock);
+extern int glthread_rwlock_destroy_func (gl_rwlock_t *lock);
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+/* The Win32 documentation says that CRITICAL_SECTION already implements a
+   recursive lock.  But we need not rely on it: It's easy to implement a
+   recursive lock without this assumption.  */
+
+typedef struct
+        {
+          gl_spinlock_t guard; /* protects the initialization */
+          DWORD owner;
+          unsigned long depth;
+          CRITICAL_SECTION lock;
+        }
+        gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_recursive_lock_t NAME;
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME) \
+    STORAGECLASS gl_recursive_lock_t NAME = gl_recursive_lock_initializer;
+# define gl_recursive_lock_initializer \
+    { { 0, -1 }, 0, 0 }
+# define glthread_recursive_lock_init(LOCK) \
+    (glthread_recursive_lock_init_func (LOCK), 0)
+# define glthread_recursive_lock_lock(LOCK) \
+    glthread_recursive_lock_lock_func (LOCK)
+# define glthread_recursive_lock_unlock(LOCK) \
+    glthread_recursive_lock_unlock_func (LOCK)
+# define glthread_recursive_lock_destroy(LOCK) \
+    glthread_recursive_lock_destroy_func (LOCK)
+extern void glthread_recursive_lock_init_func (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_lock_func (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_unlock_func (gl_recursive_lock_t *lock);
+extern int glthread_recursive_lock_destroy_func (gl_recursive_lock_t *lock);
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef struct
+        {
+          volatile int inited;
+          volatile long started;
+          CRITICAL_SECTION lock;
+        }
+        gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_once_t NAME = { -1, -1 };
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+    (glthread_once_func (ONCE_CONTROL, INITFUNCTION), 0)
+extern void glthread_once_func (gl_once_t *once_control, void (*initfunction) 
(void));
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || 
USE_WIN32_THREADS)
+
+/* Provide dummy implementation if threads are not supported.  */
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+typedef int gl_lock_t;
+# define gl_lock_define(STORAGECLASS, NAME)
+# define gl_lock_define_initialized(STORAGECLASS, NAME)
+# define glthread_lock_init(NAME) 0
+# define glthread_lock_lock(NAME) 0
+# define glthread_lock_unlock(NAME) 0
+# define glthread_lock_destroy(NAME) 0
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+typedef int gl_rwlock_t;
+# define gl_rwlock_define(STORAGECLASS, NAME)
+# define gl_rwlock_define_initialized(STORAGECLASS, NAME)
+# define glthread_rwlock_init(NAME) 0
+# define glthread_rwlock_rdlock(NAME) 0
+# define glthread_rwlock_wrlock(NAME) 0
+# define glthread_rwlock_unlock(NAME) 0
+# define glthread_rwlock_destroy(NAME) 0
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+typedef int gl_recursive_lock_t;
+# define gl_recursive_lock_define(STORAGECLASS, NAME)
+# define gl_recursive_lock_define_initialized(STORAGECLASS, NAME)
+# define glthread_recursive_lock_init(NAME) 0
+# define glthread_recursive_lock_lock(NAME) 0
+# define glthread_recursive_lock_unlock(NAME) 0
+# define glthread_recursive_lock_destroy(NAME) 0
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+typedef int gl_once_t;
+# define gl_once_define(STORAGECLASS, NAME) \
+    STORAGECLASS gl_once_t NAME = 0;
+# define glthread_once(ONCE_CONTROL, INITFUNCTION) \
+    (*(ONCE_CONTROL) == 0 ? (*(ONCE_CONTROL) = ~ 0, INITFUNCTION (), 0) : 0)
+
+#endif
+
+/* ========================================================================= */
+
+/* Macros with built-in error handling.  */
+
+/* -------------------------- gl_lock_t datatype -------------------------- */
+
+#define gl_lock_init(NAME) \
+   do                                  \
+     {                                 \
+       if (glthread_lock_init (&NAME)) \
+         abort ();                     \
+     }                                 \
+   while (0)
+#define gl_lock_lock(NAME) \
+   do                                  \
+     {                                 \
+       if (glthread_lock_lock (&NAME)) \
+         abort ();                     \
+     }                                 \
+   while (0)
+#define gl_lock_unlock(NAME) \
+   do                                    \
+     {                                   \
+       if (glthread_lock_unlock (&NAME)) \
+         abort ();                       \
+     }                                   \
+   while (0)
+#define gl_lock_destroy(NAME) \
+   do                                     \
+     {                                    \
+       if (glthread_lock_destroy (&NAME)) \
+         abort ();                        \
+     }                                    \
+   while (0)
+
+/* ------------------------- gl_rwlock_t datatype ------------------------- */
+
+#define gl_rwlock_init(NAME) \
+   do                                    \
+     {                                   \
+       if (glthread_rwlock_init (&NAME)) \
+         abort ();                       \
+     }                                   \
+   while (0)
+#define gl_rwlock_rdlock(NAME) \
+   do                                      \
+     {                                     \
+       if (glthread_rwlock_rdlock (&NAME)) \
+         abort ();                         \
+     }                                     \
+   while (0)
+#define gl_rwlock_wrlock(NAME) \
+   do                                      \
+     {                                     \
+       if (glthread_rwlock_wrlock (&NAME)) \
+         abort ();                         \
+     }                                     \
+   while (0)
+#define gl_rwlock_unlock(NAME) \
+   do                                      \
+     {                                     \
+       if (glthread_rwlock_unlock (&NAME)) \
+         abort ();                         \
+     }                                     \
+   while (0)
+#define gl_rwlock_destroy(NAME) \
+   do                                       \
+     {                                      \
+       if (glthread_rwlock_destroy (&NAME)) \
+         abort ();                          \
+     }                                      \
+   while (0)
+
+/* --------------------- gl_recursive_lock_t datatype --------------------- */
+
+#define gl_recursive_lock_init(NAME) \
+   do                                            \
+     {                                           \
+       if (glthread_recursive_lock_init (&NAME)) \
+         abort ();                               \
+     }                                           \
+   while (0)
+#define gl_recursive_lock_lock(NAME) \
+   do                                            \
+     {                                           \
+       if (glthread_recursive_lock_lock (&NAME)) \
+         abort ();                               \
+     }                                           \
+   while (0)
+#define gl_recursive_lock_unlock(NAME) \
+   do                                              \
+     {                                             \
+       if (glthread_recursive_lock_unlock (&NAME)) \
+         abort ();                                 \
+     }                                             \
+   while (0)
+#define gl_recursive_lock_destroy(NAME) \
+   do                                               \
+     {                                              \
+       if (glthread_recursive_lock_destroy (&NAME)) \
+         abort ();                                  \
+     }                                              \
+   while (0)
+
+/* -------------------------- gl_once_t datatype -------------------------- */
+
+#define gl_once(NAME, INITFUNCTION) \
+   do                                           \
+     {                                          \
+       if (glthread_once (&NAME, INITFUNCTION)) \
+         abort ();                              \
+     }                                          \
+   while (0)
+
+/* ========================================================================= */
+
+#endif /* _LOCK_H */
diff --git a/gl/tests/glthread/thread.c b/gl/tests/glthread/thread.c
new file mode 100644
index 0000000..83b8c57
--- /dev/null
+++ b/gl/tests/glthread/thread.c
@@ -0,0 +1,232 @@
+/* Creating and controlling threads.
+   Copyright (C) 2005-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* Written by Bruno Haible <address@hidden>, 2005.
+   Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
+   gthr-win32.h.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "glthread/thread.h"
+
+#include <stdlib.h>
+#include "glthread/lock.h"
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+#include <pthread.h>
+
+#ifdef PTW32_VERSION
+
+const gl_thread_t gl_null_thread /* = { .p = NULL } */;
+
+#endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WIN32_THREADS
+
+#include <process.h>
+
+/* -------------------------- gl_thread_t datatype -------------------------- 
*/
+
+/* The Thread-Local Storage (TLS) key that allows to access each thread's
+   'struct gl_thread_struct *' pointer.  */
+static DWORD self_key = (DWORD)-1;
+
+/* Initializes self_key.  This function must only be called once.  */
+static void
+do_init_self_key (void)
+{
+  self_key = TlsAlloc ();
+  /* If this fails, we're hosed.  */
+  if (self_key == (DWORD)-1)
+    abort ();
+}
+
+/* Initializes self_key.  */
+static void
+init_self_key (void)
+{
+  gl_once_define(static, once)
+  gl_once (once, do_init_self_key);
+}
+
+/* This structure contains information about a thread.
+   It is stored in TLS under key self_key.  */
+struct gl_thread_struct
+{
+  /* Fields for managing the handle.  */
+  HANDLE volatile handle;
+  CRITICAL_SECTION handle_lock;
+  /* Fields for managing the exit value.  */
+  void * volatile result;
+  /* Fields for managing the thread start.  */
+  void * (*func) (void *);
+  void *arg;
+};
+
+/* Return a real HANDLE object for the current thread.  */
+static inline HANDLE
+get_current_thread_handle (void)
+{
+  HANDLE this_handle;
+
+  /* GetCurrentThread() returns a pseudo-handle, i.e. only a symbolic
+     identifier, not a real handle.  */
+  if (!DuplicateHandle (GetCurrentProcess (), GetCurrentThread (),
+                        GetCurrentProcess (), &this_handle,
+                        0, FALSE, DUPLICATE_SAME_ACCESS))
+    abort ();
+  return this_handle;
+}
+
+gl_thread_t
+gl_thread_self_func (void)
+{
+  gl_thread_t thread;
+
+  if (self_key == (DWORD)-1)
+    init_self_key ();
+  thread = TlsGetValue (self_key);
+  if (thread == NULL)
+    {
+      /* This happens only in threads that have not been created through
+         glthread_create(), such as the main thread.  */
+      for (;;)
+        {
+          thread =
+            (struct gl_thread_struct *)
+            malloc (sizeof (struct gl_thread_struct));
+          if (thread != NULL)
+            break;
+          /* Memory allocation failed.  There is not much we can do.  Have to
+             busy-loop, waiting for the availability of memory.  */
+          Sleep (1);
+        }
+
+      thread->handle = get_current_thread_handle ();
+      InitializeCriticalSection (&thread->handle_lock);
+      thread->result = NULL; /* just to be deterministic */
+      TlsSetValue (self_key, thread);
+    }
+  return thread;
+}
+
+/* The main function of a freshly creating thread.  It's a wrapper around
+   the FUNC and ARG arguments passed to glthread_create_func.  */
+static unsigned int WINAPI
+wrapper_func (void *varg)
+{
+  struct gl_thread_struct *thread = (struct gl_thread_struct *)varg;
+
+  EnterCriticalSection (&thread->handle_lock);
+  /* Create a new handle for the thread only if the parent thread did not yet
+     fill in the handle.  */
+  if (thread->handle == NULL)
+    thread->handle = get_current_thread_handle ();
+  LeaveCriticalSection (&thread->handle_lock);
+
+  if (self_key == (DWORD)-1)
+    init_self_key ();
+  TlsSetValue (self_key, thread);
+
+  /* Run the thread.  Store the exit value if the thread was not terminated
+     otherwise.  */
+  thread->result = thread->func (thread->arg);
+  return 0;
+}
+
+int
+glthread_create_func (gl_thread_t *threadp, void * (*func) (void *), void *arg)
+{
+  struct gl_thread_struct *thread =
+    (struct gl_thread_struct *) malloc (sizeof (struct gl_thread_struct));
+  if (thread == NULL)
+    return ENOMEM;
+  thread->handle = NULL;
+  InitializeCriticalSection (&thread->handle_lock);
+  thread->result = NULL; /* just to be deterministic */
+  thread->func = func;
+  thread->arg = arg;
+
+  {
+    unsigned int thread_id;
+    HANDLE thread_handle;
+
+    thread_handle = (HANDLE)
+      _beginthreadex (NULL, 100000, wrapper_func, thread, 0, &thread_id);
+      /* calls CreateThread with the same arguments */
+    if (thread_handle == NULL)
+      {
+        DeleteCriticalSection (&thread->handle_lock);
+        free (thread);
+        return EAGAIN;
+      }
+
+    EnterCriticalSection (&thread->handle_lock);
+    if (thread->handle == NULL)
+      thread->handle = thread_handle;
+    else
+      /* thread->handle was already set by the thread itself.  */
+      CloseHandle (thread_handle);
+    LeaveCriticalSection (&thread->handle_lock);
+
+    *threadp = thread;
+    return 0;
+  }
+}
+
+int
+glthread_join_func (gl_thread_t thread, void **retvalp)
+{
+  if (thread == NULL)
+    return EINVAL;
+
+  if (thread == gl_thread_self ())
+    return EDEADLK;
+
+  if (WaitForSingleObject (thread->handle, INFINITE) == WAIT_FAILED)
+    return EINVAL;
+
+  if (retvalp != NULL)
+    *retvalp = thread->result;
+
+  DeleteCriticalSection (&thread->handle_lock);
+  CloseHandle (thread->handle);
+  free (thread);
+
+  return 0;
+}
+
+int
+gl_thread_exit_func (void *retval)
+{
+  gl_thread_t thread = gl_thread_self ();
+  thread->result = retval;
+  _endthreadex (0); /* calls ExitThread (0) */
+  abort ();
+}
+
+#endif
+
+/* ========================================================================= */
diff --git a/gl/tests/glthread/thread.h b/gl/tests/glthread/thread.h
new file mode 100644
index 0000000..064d72f
--- /dev/null
+++ b/gl/tests/glthread/thread.h
@@ -0,0 +1,401 @@
+/* Creating and controlling threads.
+   Copyright (C) 2005-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* Written by Bruno Haible <address@hidden>, 2005.
+   Based on GCC's gthr-posix.h, gthr-posix95.h, gthr-solaris.h,
+   gthr-win32.h.  */
+
+/* This file contains primitives for creating and controlling threads.
+
+   Thread data type: gl_thread_t.
+
+   Creating a thread:
+       thread = gl_thread_create (func, arg);
+   Or with control of error handling:
+       err = glthread_create (&thread, func, arg);
+       extern int glthread_create (gl_thread_t *result,
+                                   void *(*func) (void *), void *arg);
+
+   Querying and changing the signal mask of a thread (not supported on all
+   platforms):
+       gl_thread_sigmask (how, newmask, oldmask);
+   Or with control of error handling:
+       err = glthread_sigmask (how, newmask, oldmask);
+       extern int glthread_sigmask (int how, const sigset_t *newmask, sigset_t 
*oldmask);
+
+   Waiting for termination of another thread:
+       gl_thread_join (thread, &return_value);
+   Or with control of error handling:
+       err = glthread_join (thread, &return_value);
+       extern int glthread_join (gl_thread_t thread, void **return_value_ptr);
+
+   Getting a reference to the current thread:
+       current = gl_thread_self ();
+       extern gl_thread_t gl_thread_self (void);
+
+   Getting a reference to the current thread as a pointer, for debugging:
+       ptr = gl_thread_self_pointer ();
+       extern void * gl_thread_self_pointer (void);
+
+   Terminating the current thread:
+       gl_thread_exit (return_value);
+       extern _Noreturn void gl_thread_exit (void *return_value);
+
+   Requesting custom code to be executed at fork() time(not supported on all
+   platforms):
+       gl_thread_atfork (prepare_func, parent_func, child_func);
+   Or with control of error handling:
+       err = glthread_atfork (prepare_func, parent_func, child_func);
+       extern int glthread_atfork (void (*prepare_func) (void),
+                                   void (*parent_func) (void),
+                                   void (*child_func) (void));
+   Note that even on platforms where this is supported, use of fork() and
+   threads together is problematic, see
+     <http://lists.gnu.org/archive/html/bug-gnulib/2008-08/msg00062.html>
+ */
+
+
+#ifndef _GLTHREAD_THREAD_H
+#define _GLTHREAD_THREAD_H
+
+#include <errno.h>
+#include <stdlib.h>
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* Use the POSIX threads library.  */
+
+# include <pthread.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if PTHREAD_IN_USE_DETECTION_HARD
+
+/* The pthread_in_use() detection needs to be done at runtime.  */
+#  define pthread_in_use() \
+     glthread_in_use ()
+extern int glthread_in_use (void);
+
+# endif
+
+# if USE_POSIX_THREADS_WEAK
+
+/* Use weak references to the POSIX threads library.  */
+
+/* Weak references avoid dragging in external libraries if the other parts
+   of the program don't use them.  Here we use them, because we don't want
+   every program that uses libintl to depend on libpthread.  This assumes
+   that libpthread would not be loaded after libintl; i.e. if libintl is
+   loaded first, by an executable that does not depend on libpthread, and
+   then a module is dynamically loaded that depends on libpthread, libintl
+   will not be multithread-safe.  */
+
+/* The way to test at runtime whether libpthread is present is to test
+   whether a function pointer's value, such as &pthread_mutex_init, is
+   non-NULL.  However, some versions of GCC have a bug through which, in
+   PIC mode, &foo != NULL always evaluates to true if there is a direct
+   call to foo(...) in the same function.  To avoid this, we test the
+   address of a function in libpthread that we don't use.  */
+
+#  pragma weak pthread_create
+#  pragma weak pthread_sigmask
+#  pragma weak pthread_join
+#  ifndef pthread_self
+#   pragma weak pthread_self
+#  endif
+#  pragma weak pthread_exit
+#  if HAVE_PTHREAD_ATFORK
+#   pragma weak pthread_atfork
+#  endif
+
+#  if !PTHREAD_IN_USE_DETECTION_HARD
+#   pragma weak pthread_cancel
+#   define pthread_in_use() (pthread_cancel != NULL)
+#  endif
+
+# else
+
+#  if !PTHREAD_IN_USE_DETECTION_HARD
+#   define pthread_in_use() 1
+#  endif
+
+# endif
+
+/* -------------------------- gl_thread_t datatype -------------------------- 
*/
+
+/* This choice of gl_thread_t assumes that
+     pthread_equal (a, b)  is equivalent to  ((a) == (b)).
+   This is the case on all platforms in use in 2008.  */
+typedef pthread_t gl_thread_t;
+# define glthread_create(THREADP, FUNC, ARG) \
+    (pthread_in_use () ? pthread_create (THREADP, NULL, FUNC, ARG) : ENOSYS)
+# define glthread_sigmask(HOW, SET, OSET) \
+    (pthread_in_use () ? pthread_sigmask (HOW, SET, OSET) : 0)
+# define glthread_join(THREAD, RETVALP) \
+    (pthread_in_use () ? pthread_join (THREAD, RETVALP) : 0)
+# ifdef PTW32_VERSION
+   /* In pthreads-win32, pthread_t is a struct with a pointer field 'p' and
+      other fields.  */
+#  define gl_thread_self() \
+     (pthread_in_use () ? pthread_self () : gl_null_thread)
+#  define gl_thread_self_pointer() \
+     (pthread_in_use () ? pthread_self ().p : NULL)
+extern const gl_thread_t gl_null_thread;
+# else
+#  define gl_thread_self() \
+     (pthread_in_use () ? pthread_self () : (pthread_t) NULL)
+#  define gl_thread_self_pointer() \
+     (pthread_in_use () ? (void *) pthread_self () : NULL)
+# endif
+# define gl_thread_exit(RETVAL) \
+    (pthread_in_use () ? pthread_exit (RETVAL) : 0)
+
+# if HAVE_PTHREAD_ATFORK
+#  define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) \
+     (pthread_in_use () ? pthread_atfork (PREPARE_FUNC, PARENT_FUNC, 
CHILD_FUNC) : 0)
+# else
+#  define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
+# endif
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+/* Use the GNU Pth threads library.  */
+
+# include <pth.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if USE_PTH_THREADS_WEAK
+
+/* Use weak references to the GNU Pth threads library.  */
+
+#  pragma weak pth_spawn
+#  pragma weak pth_sigmask
+#  pragma weak pth_join
+#  pragma weak pth_self
+#  pragma weak pth_exit
+
+#  pragma weak pth_cancel
+#  define pth_in_use() (pth_cancel != NULL)
+
+# else
+
+#  define pth_in_use() 1
+
+# endif
+/* -------------------------- gl_thread_t datatype -------------------------- 
*/
+
+typedef pth_t gl_thread_t;
+# define glthread_create(THREADP, FUNC, ARG) \
+    (pth_in_use () ? ((*(THREADP) = pth_spawn (NULL, FUNC, ARG)) ? 0 : errno) 
: 0)
+# define glthread_sigmask(HOW, SET, OSET) \
+    (pth_in_use () && !pth_sigmask (HOW, SET, OSET) ? errno : 0)
+# define glthread_join(THREAD, RETVALP) \
+    (pth_in_use () && !pth_join (THREAD, RETVALP) ? errno : 0)
+# define gl_thread_self() \
+    (pth_in_use () ? (void *) pth_self () : NULL)
+# define gl_thread_self_pointer() \
+    gl_thread_self ()
+# define gl_thread_exit(RETVAL) \
+    (pth_in_use () ? pth_exit (RETVAL) : 0)
+# define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library.  */
+
+# include <thread.h>
+# include <synch.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# if USE_SOLARIS_THREADS_WEAK
+
+/* Use weak references to the old Solaris threads library.  */
+
+#  pragma weak thr_create
+#  pragma weak thr_join
+#  pragma weak thr_self
+#  pragma weak thr_exit
+
+#  pragma weak thr_suspend
+#  define thread_in_use() (thr_suspend != NULL)
+
+# else
+
+#  define thread_in_use() 1
+
+# endif
+
+/* -------------------------- gl_thread_t datatype -------------------------- 
*/
+
+typedef thread_t gl_thread_t;
+# define glthread_create(THREADP, FUNC, ARG) \
+    (thread_in_use () ? thr_create (NULL, 0, FUNC, ARG, 0, THREADP) : 0)
+# define glthread_sigmask(HOW, SET, OSET) \
+    (thread_in_use () ? sigprocmask (HOW, SET, OSET) : 0)
+# define glthread_join(THREAD, RETVALP) \
+    (thread_in_use () ? thr_join (THREAD, NULL, RETVALP) : 0)
+# define gl_thread_self() \
+    (thread_in_use () ? (void *) thr_self () : NULL)
+# define gl_thread_self_pointer() \
+    gl_thread_self ()
+# define gl_thread_exit(RETVAL) \
+    (thread_in_use () ? thr_exit (RETVAL) : 0)
+# define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WIN32_THREADS
+
+# define WIN32_LEAN_AND_MEAN  /* avoid including junk */
+# include <windows.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+/* -------------------------- gl_thread_t datatype -------------------------- 
*/
+
+/* The gl_thread_t is a pointer to a structure in memory.
+   Why not the thread handle?  If it were the thread handle, it would be hard
+   to implement gl_thread_self() (since GetCurrentThread () returns a pseudo-
+   handle, DuplicateHandle (GetCurrentThread ()) returns a handle that must be
+   closed afterwards, and there is no function for quickly retrieving a thread
+   handle from its id).
+   Why not the thread id?  I tried it.  It did not work: Sometimes ids appeared
+   that did not belong to running threads, and glthread_join failed with ESRCH.
+ */
+typedef struct gl_thread_struct *gl_thread_t;
+# define glthread_create(THREADP, FUNC, ARG) \
+    glthread_create_func (THREADP, FUNC, ARG)
+# define glthread_sigmask(HOW, SET, OSET) \
+    /* unsupported */ 0
+# define glthread_join(THREAD, RETVALP) \
+    glthread_join_func (THREAD, RETVALP)
+# define gl_thread_self() \
+    gl_thread_self_func ()
+# define gl_thread_self_pointer() \
+    gl_thread_self ()
+# define gl_thread_exit(RETVAL) \
+    gl_thread_exit_func (RETVAL)
+# define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
+extern int glthread_create_func (gl_thread_t *threadp, void * (*func) (void 
*), void *arg);
+extern int glthread_join_func (gl_thread_t thread, void **retvalp);
+extern gl_thread_t gl_thread_self_func (void);
+extern int gl_thread_exit_func (void *retval);
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || 
USE_WIN32_THREADS)
+
+/* Provide dummy implementation if threads are not supported.  */
+
+typedef int gl_thread_t;
+# define glthread_create(THREADP, FUNC, ARG) ENOSYS
+# define glthread_sigmask(HOW, SET, OSET) 0
+# define glthread_join(THREAD, RETVALP) 0
+# define gl_thread_self() 0
+# define gl_thread_self_pointer() \
+    ((void *) gl_thread_self ())
+# define gl_thread_exit(RETVAL) 0
+# define glthread_atfork(PREPARE_FUNC, PARENT_FUNC, CHILD_FUNC) 0
+
+#endif
+
+/* ========================================================================= */
+
+/* Macros with built-in error handling.  */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline gl_thread_t
+gl_thread_create (void *(*func) (void *arg), void *arg)
+{
+  gl_thread_t thread;
+  int ret;
+
+  ret = glthread_create (&thread, func, arg);
+  if (ret != 0)
+    abort ();
+  return thread;
+}
+#define gl_thread_sigmask(HOW, SET, OSET)     \
+   do                                         \
+     {                                        \
+       if (glthread_sigmask (HOW, SET, OSET)) \
+         abort ();                            \
+     }                                        \
+   while (0)
+#define gl_thread_join(THREAD, RETVAL)     \
+   do                                      \
+     {                                     \
+       if (glthread_join (THREAD, RETVAL)) \
+         abort ();                         \
+     }                                     \
+   while (0)
+#define gl_thread_atfork(PREPARE, PARENT, CHILD)     \
+   do                                                \
+     {                                               \
+       if (glthread_atfork (PREPARE, PARENT, CHILD)) \
+         abort ();                                   \
+     }                                               \
+   while (0)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _GLTHREAD_THREAD_H */
diff --git a/gl/tests/glthread/threadlib.c b/gl/tests/glthread/threadlib.c
new file mode 100644
index 0000000..646defa
--- /dev/null
+++ b/gl/tests/glthread/threadlib.c
@@ -0,0 +1,74 @@
+/* Multithreading primitives.
+   Copyright (C) 2005-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* Written by Bruno Haible <address@hidden>, 2005.  */
+
+#include <config.h>
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* Use the POSIX threads library.  */
+
+# include <pthread.h>
+# include <stdlib.h>
+
+# if PTHREAD_IN_USE_DETECTION_HARD
+
+/* The function to be executed by a dummy thread.  */
+static void *
+dummy_thread_func (void *arg)
+{
+  return arg;
+}
+
+int
+glthread_in_use (void)
+{
+  static int tested;
+  static int result; /* 1: linked with -lpthread, 0: only with libc */
+
+  if (!tested)
+    {
+      pthread_t thread;
+
+      if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
+        /* Thread creation failed.  */
+        result = 0;
+      else
+        {
+          /* Thread creation works.  */
+          void *retval;
+          if (pthread_join (thread, &retval) != 0)
+            abort ();
+          result = 1;
+        }
+      tested = 1;
+    }
+  return result;
+}
+
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+/* This declaration is solely to ensure that after preprocessing
+   this file is never empty.  */
+typedef int dummy;
diff --git a/gl/tests/glthread/yield.h b/gl/tests/glthread/yield.h
new file mode 100644
index 0000000..4fa2d8b
--- /dev/null
+++ b/gl/tests/glthread/yield.h
@@ -0,0 +1,122 @@
+/* Yielding the processor to other threads and processes.
+   Copyright (C) 2005-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* This file contains a primitive for yielding the processor to other threads.
+     extern void gl_thread_yield (void);
+ */
+
+#ifndef _GLTHREAD_YIELD_H
+#define _GLTHREAD_YIELD_H
+
+#include <errno.h>
+
+/* ========================================================================= */
+
+#if USE_POSIX_THREADS
+
+/* Use the POSIX threads library.  */
+
+# include <sched.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# define gl_thread_yield() \
+    sched_yield ()
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_PTH_THREADS
+
+/* Use the GNU Pth threads library.  */
+
+# include <pth.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# define gl_thread_yield() \
+    pth_yield (NULL)
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_SOLARIS_THREADS
+
+/* Use the old Solaris threads library.  */
+
+# include <thread.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# define gl_thread_yield() \
+    thr_yield ()
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if USE_WIN32_THREADS
+
+# define WIN32_LEAN_AND_MEAN  /* avoid including junk */
+# include <windows.h>
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+# define gl_thread_yield() \
+    Sleep (0)
+
+# ifdef __cplusplus
+}
+# endif
+
+#endif
+
+/* ========================================================================= */
+
+#if !(USE_POSIX_THREADS || USE_PTH_THREADS || USE_SOLARIS_THREADS || 
USE_WIN32_THREADS)
+
+/* Provide dummy implementation if threads are not supported.  */
+
+# define gl_thread_yield() 0
+
+#endif
+
+/* ========================================================================= */
+
+#endif /* _GLTHREAD_YIELD_H */
diff --git a/gl/tests/ioctl.c b/gl/tests/ioctl.c
new file mode 100644
index 0000000..c6ba989
--- /dev/null
+++ b/gl/tests/ioctl.c
@@ -0,0 +1,79 @@
+/* ioctl.c --- wrappers for Windows ioctl function
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <config.h>
+
+#include <sys/ioctl.h>
+
+#include <stdarg.h>
+
+#if HAVE_IOCTL
+
+/* Provide a wrapper with the POSIX prototype.  */
+# undef ioctl
+int
+rpl_ioctl (int fd, int request, ... /* {void *,char *} arg */)
+{
+  void *buf;
+  va_list args;
+
+  va_start (args, request);
+  buf = va_arg (args, void *);
+  va_end (args);
+
+  /* Cast 'request' so that when the system's ioctl function takes a 64-bit
+     request argument, the value gets zero-extended, not sign-extended.  */
+  return ioctl (fd, (unsigned int) request, buf);
+}
+
+#else /* mingw */
+
+# include <errno.h>
+
+# include "fd-hook.h"
+
+static int
+primary_ioctl (int fd, int request, void *arg)
+{
+  /* We don't support FIONBIO on pipes here.  If you want to make pipe
+     fds non-blocking, use the gnulib 'nonblocking' module, until
+     gnulib implements fcntl F_GETFL / F_SETFL with O_NONBLOCK.  */
+
+  errno = ENOSYS;
+  return -1;
+}
+
+int
+ioctl (int fd, int request, ... /* {void *,char *} arg */)
+{
+  void *arg;
+  va_list args;
+
+  va_start (args, request);
+  arg = va_arg (args, void *);
+  va_end (args);
+
+# if WINDOWS_SOCKETS
+  return execute_all_ioctl_hooks (primary_ioctl, fd, request, arg);
+# else
+  return primary_ioctl (fd, request, arg);
+# endif
+}
+
+#endif
diff --git a/gl/tests/msvc-inval.c b/gl/tests/msvc-inval.c
deleted file mode 100644
index cff0796..0000000
--- a/gl/tests/msvc-inval.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/* Invalid parameter handler for MSVC runtime libraries.
-   Copyright (C) 2011 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#include <config.h>
-
-/* Specification.  */
-#include "msvc-inval.h"
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-
-# ifdef STATUS_GNULIB_INVALID_PARAMETER
-
-/* Get declarations of the Win32 API functions.  */
-#  define WIN32_LEAN_AND_MEAN
-#  include <windows.h>
-
-static void cdecl
-gl_msvc_invalid_parameter_handler (const wchar_t *expression,
-                                   const wchar_t *function,
-                                   const wchar_t *file,
-                                   unsigned int line,
-                                   uintptr_t dummy)
-{
-  RaiseException (STATUS_GNULIB_INVALID_PARAMETER, 0, 0, NULL);
-}
-
-static int gl_msvc_inval_initialized /* = 0 */;
-
-void
-gl_msvc_inval_ensure_handler (void)
-{
-  if (gl_msvc_inval_initialized == 0)
-    {
-      _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler);
-      gl_msvc_inval_initialized = 1;
-    }
-}
-
-# else
-
-jmp_buf gl_msvc_inval_restart;
-
-void cdecl
-gl_msvc_invalid_parameter_handler (const wchar_t *expression,
-                                   const wchar_t *function,
-                                   const wchar_t *file,
-                                   unsigned int line,
-                                   uintptr_t dummy)
-{
-  longjmp (gl_msvc_inval_restart, 1);
-}
-
-# endif
-
-#endif
diff --git a/gl/tests/msvc-inval.h b/gl/tests/msvc-inval.h
deleted file mode 100644
index 00d3a1e..0000000
--- a/gl/tests/msvc-inval.h
+++ /dev/null
@@ -1,167 +0,0 @@
-/* Invalid parameter handler for MSVC runtime libraries.
-   Copyright (C) 2011 Free Software Foundation, Inc.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation,
-   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
-
-#ifndef _MSVC_INVAL_H
-#define _MSVC_INVAL_H
-
-/* With MSVC runtime libraries with the "invalid parameter handler" concept,
-   functions like fprintf(), dup2(), or close() crash when the caller passes
-   an invalid argument.  But POSIX wants error codes (such as EINVAL or EBADF)
-   instead.
-   This file defines macros that turn such an invalid parameter notification
-   into a non-local exit.  An error code can then be produced at the target
-   of this exit.  You can thus write code like
-
-     TRY_MSVC_INVAL
-       {
-         <Code that can trigger an invalid parameter notification
-          but does not do 'return', 'break', 'continue', nor 'goto'.>
-       }
-     CATCH_MSVC_INVAL
-       {
-         <Code that handles an invalid parameter notification
-          but does not do 'return', 'break', 'continue', nor 'goto'.>
-       }
-     DONE_MSVC_INVAL;
-
-   This entire block expands to a single statement.
- */
-
-#if HAVE_MSVC_INVALID_PARAMETER_HANDLER
-/* A native Windows platform with the "invalid parameter handler" concept.  */
-
-/* Get _invalid_parameter_handler type and _set_invalid_parameter_handler
-   declaration.  */
-#include <stdlib.h>
-
-# if defined _MSC_VER
-/* A compiler that supports __try/__except, as described in the page
-   "try-except statement" on microsoft.com
-   <http://msdn.microsoft.com/en-us/library/s58ftw19.aspx>.
-   With __try/__except, we can use the multithread-safe exception handling.  */
-
-/* Gnulib can define its own status codes, as described in the page
-   "Raising Software Exceptions" on microsoft.com
-   <http://msdn.microsoft.com/en-us/library/het71c37.aspx>.
-   Our status codes are composed of
-     - 0xE0000000, mandatory for all user-defined status codes,
-     - 0x474E550, a API identifier ("GNU"),
-     - 0, 1, 2, ..., used to distinguish different status codes from the
-       same API.  */
-#  define STATUS_GNULIB_INVALID_PARAMETER (0xE0000000 + 0x474E550 + 0)
-
-#  ifdef __cplusplus
-extern "C" {
-#  endif
-
-/* Ensure that the invalid parameter handler in installed that raises a
-   software exception with code STATUS_GNULIB_INVALID_PARAMETER.
-   Because we assume no other part of the program installs a different
-   invalid parameter handler, this solution is multithread-safe.  */
-extern void gl_msvc_inval_ensure_handler (void);
-
-#  ifdef __cplusplus
-}
-#  endif
-
-#  define TRY_MSVC_INVAL \
-     do                                                                        
\
-       {                                                                       
\
-         gl_msvc_inval_ensure_handler ();                                      
\
-         __try
-#  define CATCH_MSVC_INVAL \
-         __except (GetExceptionCode () == STATUS_GNULIB_INVALID_PARAMETER      
\
-                   ? EXCEPTION_EXECUTE_HANDLER                                 
\
-                   : EXCEPTION_CONTINUE_SEARCH)
-#  define DONE_MSVC_INVAL \
-       }                                                                       
\
-     while (0)
-
-# else
-/* Any compiler.
-   We can only use setjmp/longjmp.
-   Unfortunately, this is *not* multithread-safe.  */
-
-#  include <setjmp.h>
-
-#  ifdef __cplusplus
-extern "C" {
-#  endif
-
-/* The restart that will resume execution at the code between
-   CATCH_MSVC_INVAL and DONE_MSVC_INVAL.  It is enabled only between
-   TRY_MSVC_INVAL and CATCH_MSVC_INVAL.  */
-extern jmp_buf gl_msvc_inval_restart;
-
-/* The invalid parameter handler that unwinds the stack up to the
-   gl_msvc_inval_restart.  It is enabled only between TRY_MSVC_INVAL
-   and CATCH_MSVC_INVAL.  */
-extern void cdecl gl_msvc_invalid_parameter_handler (const wchar_t *expression,
-                                                     const wchar_t *function,
-                                                     const wchar_t *file,
-                                                     unsigned int line,
-                                                     uintptr_t dummy);
-
-#  ifdef __cplusplus
-}
-#  endif
-
-#  define TRY_MSVC_INVAL \
-     do                                                                        
\
-       {                                                                       
\
-         _invalid_parameter_handler orig_handler;                              
\
-         /* First, initialize gl_msvc_inval_restart.  */                       
\
-         if (setjmp (gl_msvc_inval_restart) == 0)                              
\
-           {                                                                   
\
-             /* Then, enable gl_msvc_invalid_parameter_handler.  */            
\
-             orig_handler =                                                    
\
-               _set_invalid_parameter_handler 
(gl_msvc_invalid_parameter_handler);
-#  define CATCH_MSVC_INVAL \
-             /* Execution completed.                                           
\
-                Disable gl_msvc_invalid_parameter_handler.  */                 
\
-             _set_invalid_parameter_handler (orig_handler);                    
\
-           }                                                                   
\
-         else                                                                  
\
-           {                                                                   
\
-             /* Execution triggered an invalid parameter notification.         
\
-                Disable gl_msvc_invalid_parameter_handler.  */                 
\
-             _set_invalid_parameter_handler (orig_handler);
-#  define DONE_MSVC_INVAL \
-           }                                                                   
\
-       }                                                                       
\
-     while (0)
-
-# endif
-
-#else
-/* A platform that does not need to the invalid parameter handler.  */
-
-/* The braces here avoid GCC warnings like
-   "warning: suggest explicit braces to avoid ambiguous `else'".  */
-# define TRY_MSVC_INVAL \
-    do                                                                         
\
-      {                                                                        
\
-        if (1)
-# define CATCH_MSVC_INVAL \
-        else
-# define DONE_MSVC_INVAL \
-      }                                                                        
\
-    while (0)
-
-#endif
-
-#endif /* _MSVC_INVAL_H */
diff --git a/gl/tests/perror.c b/gl/tests/perror.c
new file mode 100644
index 0000000..af4b56c
--- /dev/null
+++ b/gl/tests/perror.c
@@ -0,0 +1,49 @@
+/* Print a message describing error code.
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+   Written by Bruno Haible and Simon Josefsson.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <stdio.h>
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "strerror-override.h"
+
+/* Use the system functions, not the gnulib overrides in this file.  */
+#undef fprintf
+
+void
+perror (const char *string)
+{
+  char stackbuf[STACKBUF_LEN];
+  int ret;
+
+  /* Our implementation guarantees that this will be a non-empty
+     string, even if it returns EINVAL; and stackbuf should be sized
+     large enough to avoid ERANGE.  */
+  ret = strerror_r (errno, stackbuf, sizeof stackbuf);
+  if (ret == ERANGE)
+    abort ();
+
+  if (string != NULL && *string != '\0')
+    fprintf (stderr, "%s: %s\n", string, stackbuf);
+  else
+    fprintf (stderr, "%s\n", stackbuf);
+}
diff --git a/gl/tests/pipe.c b/gl/tests/pipe.c
new file mode 100644
index 0000000..425dd70
--- /dev/null
+++ b/gl/tests/pipe.c
@@ -0,0 +1,51 @@
+/* Create a pipe.
+   Copyright (C) 2009-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <unistd.h>
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Native Woe32 API.  */
+
+/* Get _pipe().  */
+# include <io.h>
+
+/* Get _O_BINARY.  */
+# include <fcntl.h>
+
+int
+pipe (int fd[2])
+{
+  /* Mingw changes fd to {-1,-1} on failure, but this violates
+     http://austingroupbugs.net/view.php?id=467 */
+  int tmp[2];
+  int result = _pipe (tmp, 4096, _O_BINARY);
+  if (!result)
+    {
+      fd[0] = tmp[0];
+      fd[1] = tmp[1];
+    }
+  return result;
+}
+
+#else
+
+# error "This platform lacks a pipe function, and Gnulib doesn't provide a 
replacement. This is a bug in Gnulib."
+
+#endif
diff --git a/gl/tests/putenv.c b/gl/tests/putenv.c
index 3c33279..2da3376 100644
--- a/gl/tests/putenv.c
+++ b/gl/tests/putenv.c
@@ -36,7 +36,7 @@
 
 #if _LIBC
 # if HAVE_GNU_LD
-# define environ __environ
+#  define environ __environ
 # else
 extern char **environ;
 # endif
diff --git a/gl/tests/strerror_r.c b/gl/tests/strerror_r.c
new file mode 100644
index 0000000..e6cf99b
--- /dev/null
+++ b/gl/tests/strerror_r.c
@@ -0,0 +1,327 @@
+/* strerror_r.c --- POSIX compatible system error routine
+
+   Copyright (C) 2010-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2010.  */
+
+#include <config.h>
+
+/* Enable declaration of sys_nerr and sys_errlist in <errno.h> on NetBSD.  */
+#define _NETBSD_SOURCE 1
+
+/* Specification.  */
+#include <string.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "strerror-override.h"
+
+#if (__GLIBC__ >= 2 || defined __UCLIBC__ || defined __CYGWIN__) && 
HAVE___XPG_STRERROR_R /* glibc >= 2.3.4, cygwin >= 1.7.9 */
+
+# define USE_XPG_STRERROR_R 1
+
+#elif HAVE_DECL_STRERROR_R && !(__GLIBC__ >= 2 || defined __UCLIBC__ || 
defined __CYGWIN__)
+
+/* The system's strerror_r function is OK, except that its third argument
+   is 'int', not 'size_t', or its return type is wrong.  */
+
+# include <limits.h>
+
+# define USE_SYSTEM_STRERROR_R 1
+
+#else /* (__GLIBC__ >= 2 || defined __UCLIBC__ || defined __CYGWIN__ ? 
!HAVE___XPG_STRERROR_R : !HAVE_DECL_STRERROR_R) */
+
+/* Use the system's strerror().  Exclude glibc and cygwin because the
+   system strerror_r has the wrong return type, and cygwin 1.7.9
+   strerror_r clobbers strerror.  */
+# undef strerror
+
+# define USE_SYSTEM_STRERROR 1
+
+# if defined __NetBSD__ || defined __hpux || ((defined _WIN32 || defined 
__WIN32__) && !defined __CYGWIN__) || defined __sgi || (defined __sun && 
!defined _LP64) || defined __CYGWIN__
+
+/* No locking needed.  */
+
+/* Get catgets internationalization functions.  */
+#  if HAVE_CATGETS
+#   include <nl_types.h>
+#  endif
+
+/* Get sys_nerr, sys_errlist on HP-UX (otherwise only declared in C++ mode).
+   Get sys_nerr, sys_errlist on IRIX (otherwise only declared with _SGIAPI).  
*/
+#  if defined __hpux || defined __sgi
+extern int sys_nerr;
+extern char *sys_errlist[];
+#  endif
+
+/* Get sys_nerr on Solaris.  */
+#  if defined __sun && !defined _LP64
+extern int sys_nerr;
+#  endif
+
+# else
+
+#  include "glthread/lock.h"
+
+/* This lock protects the buffer returned by strerror().  We assume that
+   no other uses of strerror() exist in the program.  */
+gl_lock_define_initialized(static, strerror_lock)
+
+# endif
+
+#endif
+
+/* On MSVC, there is no snprintf() function, just a _snprintf().
+   It is of lower quality, but sufficient for the simple use here.
+   We only have to make sure to NUL terminate the result (_snprintf
+   does not NUL terminate, like strncpy).  */
+#if !HAVE_SNPRINTF
+static int
+local_snprintf (char *buf, size_t buflen, const char *format, ...)
+{
+  va_list args;
+  int result;
+
+  va_start (args, format);
+  result = _vsnprintf (buf, buflen, format, args);
+  va_end (args);
+  if (buflen > 0 && (result < 0 || result >= buflen))
+    buf[buflen - 1] = '\0';
+  return result;
+}
+# define snprintf local_snprintf
+#endif
+
+/* Copy as much of MSG into BUF as possible, without corrupting errno.
+   Return 0 if MSG fit in BUFLEN, otherwise return ERANGE.  */
+static int
+safe_copy (char *buf, size_t buflen, const char *msg)
+{
+  size_t len = strlen (msg);
+  int ret;
+
+  if (len < buflen)
+    {
+      /* Although POSIX allows memcpy() to corrupt errno, we don't
+         know of any implementation where this is a real problem.  */
+      memcpy (buf, msg, len + 1);
+      ret = 0;
+    }
+  else
+    {
+      memcpy (buf, msg, buflen - 1);
+      buf[buflen - 1] = '\0';
+      ret = ERANGE;
+    }
+  return ret;
+}
+
+
+int
+strerror_r (int errnum, char *buf, size_t buflen)
+#undef strerror_r
+{
+  /* Filter this out now, so that rest of this replacement knows that
+     there is room for a non-empty message and trailing NUL.  */
+  if (buflen <= 1)
+    {
+      if (buflen)
+        *buf = '\0';
+      return ERANGE;
+    }
+  *buf = '\0';
+
+  /* Check for gnulib overrides.  */
+  {
+    char const *msg = strerror_override (errnum);
+
+    if (msg)
+      return safe_copy (buf, buflen, msg);
+  }
+
+  {
+    int ret;
+    int saved_errno = errno;
+
+#if USE_XPG_STRERROR_R
+
+    {
+      extern int __xpg_strerror_r (int errnum, char *buf, size_t buflen);
+
+      ret = __xpg_strerror_r (errnum, buf, buflen);
+      if (ret < 0)
+        ret = errno;
+      if (!*buf)
+        {
+          /* glibc 2.13 would not touch buf on err, so we have to fall
+             back to GNU strerror_r which always returns a thread-safe
+             untruncated string to (partially) copy into our buf.  */
+          safe_copy (buf, buflen, strerror_r (errnum, buf, buflen));
+        }
+    }
+
+#elif USE_SYSTEM_STRERROR_R
+
+    if (buflen > INT_MAX)
+      buflen = INT_MAX;
+
+# ifdef __hpux
+    /* On HP-UX 11.31, strerror_r always fails when buflen < 80; it
+       also fails to change buf on EINVAL.  */
+    {
+      char stackbuf[80];
+
+      if (buflen < sizeof stackbuf)
+        {
+          ret = strerror_r (errnum, stackbuf, sizeof stackbuf);
+          if (ret == 0)
+            ret = safe_copy (buf, buflen, stackbuf);
+        }
+      else
+        ret = strerror_r (errnum, buf, buflen);
+    }
+# else
+    ret = strerror_r (errnum, buf, buflen);
+
+    /* Some old implementations may return (-1, EINVAL) instead of EINVAL.  */
+    if (ret < 0)
+      ret = errno;
+# endif
+
+# ifdef _AIX
+    /* AIX returns 0 rather than ERANGE when truncating strings; try
+       again until we are sure we got the entire string.  */
+    if (!ret && strlen (buf) == buflen - 1)
+      {
+        char stackbuf[STACKBUF_LEN];
+        size_t len;
+        strerror_r (errnum, stackbuf, sizeof stackbuf);
+        len = strlen (stackbuf);
+        /* STACKBUF_LEN should have been large enough.  */
+        if (len + 1 == sizeof stackbuf)
+          abort ();
+        if (buflen <= len)
+          ret = ERANGE;
+      }
+# else
+    /* Solaris 10 does not populate buf on ERANGE.  OpenBSD 4.7
+       truncates early on ERANGE rather than return a partial integer.
+       We prefer the maximal string.  We set buf[0] earlier, and we
+       know of no implementation that modifies buf to be an
+       unterminated string, so this strlen should be portable in
+       practice (rather than pulling in a safer strnlen).  */
+    if (ret == ERANGE && strlen (buf) < buflen - 1)
+      {
+        char stackbuf[STACKBUF_LEN];
+
+        /* STACKBUF_LEN should have been large enough.  */
+        if (strerror_r (errnum, stackbuf, sizeof stackbuf) == ERANGE)
+          abort ();
+        safe_copy (buf, buflen, stackbuf);
+      }
+# endif
+
+#else /* USE_SYSTEM_STRERROR */
+
+    /* Try to do what strerror (errnum) does, but without clobbering the
+       buffer used by strerror().  */
+
+# if defined __NetBSD__ || defined __hpux || ((defined _WIN32 || defined 
__WIN32__) && !defined __CYGWIN__) || defined __CYGWIN__ /* NetBSD, HP-UX, 
native Win32, Cygwin */
+
+    /* NetBSD:        sys_nerr, sys_errlist are declared through _NETBSD_SOURCE
+                      and <errno.h> above.
+       HP-UX:         sys_nerr, sys_errlist are declared explicitly above.
+       native Win32:  sys_nerr, sys_errlist are declared in <stdlib.h>.
+       Cygwin:        sys_nerr, sys_errlist are declared in <errno.h>.  */
+    if (errnum >= 0 && errnum < sys_nerr)
+      {
+#  if HAVE_CATGETS && (defined __NetBSD__ || defined __hpux)
+#   if defined __NetBSD__
+        nl_catd catd = catopen ("libc", NL_CAT_LOCALE);
+        const char *errmsg =
+          (catd != (nl_catd)-1
+           ? catgets (catd, 1, errnum, sys_errlist[errnum])
+           : sys_errlist[errnum]);
+#   endif
+#   if defined __hpux
+        nl_catd catd = catopen ("perror", NL_CAT_LOCALE);
+        const char *errmsg =
+          (catd != (nl_catd)-1
+           ? catgets (catd, 1, 1 + errnum, sys_errlist[errnum])
+           : sys_errlist[errnum]);
+#   endif
+#  else
+        const char *errmsg = sys_errlist[errnum];
+#  endif
+        if (errmsg == NULL || *errmsg == '\0')
+          ret = EINVAL;
+        else
+          ret = safe_copy (buf, buflen, errmsg);
+#  if HAVE_CATGETS && (defined __NetBSD__ || defined __hpux)
+        if (catd != (nl_catd)-1)
+          catclose (catd);
+#  endif
+      }
+    else
+      ret = EINVAL;
+
+# elif defined __sgi || (defined __sun && !defined _LP64) /* IRIX, Solaris <= 
9 32-bit */
+
+    /* For a valid error number, the system's strerror() function returns
+       a pointer to a not copied string, not to a buffer.  */
+    if (errnum >= 0 && errnum < sys_nerr)
+      {
+        char *errmsg = strerror (errnum);
+
+        if (errmsg == NULL || *errmsg == '\0')
+          ret = EINVAL;
+        else
+          ret = safe_copy (buf, buflen, errmsg);
+      }
+    else
+      ret = EINVAL;
+
+# else
+
+    gl_lock_lock (strerror_lock);
+
+    {
+      char *errmsg = strerror (errnum);
+
+      /* For invalid error numbers, strerror() on
+           - IRIX 6.5 returns NULL,
+           - HP-UX 11 returns an empty string.  */
+      if (errmsg == NULL || *errmsg == '\0')
+        ret = EINVAL;
+      else
+        ret = safe_copy (buf, buflen, errmsg);
+    }
+
+    gl_lock_unlock (strerror_lock);
+
+# endif
+
+#endif
+
+    if (ret == EINVAL && !*buf)
+      snprintf (buf, buflen, "Unknown error %d", errnum);
+
+    errno = saved_errno;
+    return ret;
+  }
+}
diff --git a/gl/tests/sys_ioctl.in.h b/gl/tests/sys_ioctl.in.h
new file mode 100644
index 0000000..dc8aeda
--- /dev/null
+++ b/gl/tests/sys_ioctl.in.h
@@ -0,0 +1,79 @@
+/* Substitute for and wrapper around <sys/ioctl.h>.
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifndef address@hidden@_SYS_IOCTL_H
+
+#if __GNUC__ >= 3
address@hidden@
+#endif
address@hidden@
+
+/* The include_next requires a split double-inclusion guard.  */
+#if @HAVE_SYS_IOCTL_H@
+# @INCLUDE_NEXT@ @NEXT_SYS_IOCTL_H@
+#endif
+
+#ifndef address@hidden@_SYS_IOCTL_H
+#define address@hidden@_SYS_IOCTL_H
+
+/* AIX 5.1 and Solaris 10 declare ioctl() in <unistd.h> and in <stropts.h>,
+   but not in <sys/ioctl.h>.
+   But avoid namespace pollution on glibc systems.  */
+#ifndef __GLIBC__
+# include <unistd.h>
+#endif
+
+/* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
+
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
+
+/* Declare overridden functions.  */
+
+#if @GNULIB_IOCTL@
+# if @REPLACE_IOCTL@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   undef ioctl
+#   define ioctl rpl_ioctl
+#  endif
+_GL_FUNCDECL_RPL (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
+_GL_CXXALIAS_RPL (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
+# else
+#  if @SYS_IOCTL_H_HAVE_WINSOCK2_H@ || 1
+_GL_FUNCDECL_SYS (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
+#  endif
+_GL_CXXALIAS_SYS (ioctl, int,
+                  (int fd, int request, ... /* {void *,char *} arg */));
+# endif
+_GL_CXXALIASWARN (ioctl);
+#elif @SYS_IOCTL_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
+# undef ioctl
+# define ioctl ioctl_used_without_requesting_gnulib_module_ioctl
+#elif defined GNULIB_POSIXCHECK
+# undef ioctl
+# if HAVE_RAW_DECL_IOCTL
+_GL_WARN_ON_USE (ioctl, "ioctl does not portably work on sockets - "
+                 "use gnulib module ioctl for portability");
+# endif
+#endif
+
+
+#endif /* address@hidden@_SYS_IOCTL_H */
+#endif /* address@hidden@_SYS_IOCTL_H */
diff --git a/gl/tests/test-accept.c b/gl/tests/test-accept.c
new file mode 100644
index 0000000..75161a4
--- /dev/null
+++ b/gl/tests/test-accept.c
@@ -0,0 +1,54 @@
+/* Test accepting a connection to a server socket.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (accept, int, (int, struct sockaddr *, socklen_t *));
+
+#include <errno.h>
+#include <netinet/in.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    struct sockaddr_in addr;
+    socklen_t addrlen = sizeof (addr);
+
+    errno = 0;
+    ASSERT (accept (-1, (struct sockaddr *) &addr, &addrlen) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    struct sockaddr_in addr;
+    socklen_t addrlen = sizeof (addr);
+
+    errno = 0;
+    ASSERT (accept (99, (struct sockaddr *) &addr, &addrlen) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-arpa_inet.c b/gl/tests/test-arpa_inet.c
new file mode 100644
index 0000000..ce7d19f
--- /dev/null
+++ b/gl/tests/test-arpa_inet.c
@@ -0,0 +1,27 @@
+/* Test of <arpa/inet.h> substitute.
+   Copyright (C) 2007, 2009-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2007.  */
+
+#include <config.h>
+
+#include <arpa/inet.h>
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gl/tests/test-bind.c b/gl/tests/test-bind.c
new file mode 100644
index 0000000..490c2fb
--- /dev/null
+++ b/gl/tests/test-bind.c
@@ -0,0 +1,56 @@
+/* Test binding a server socket to a port.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (bind, int, (int, const struct sockaddr *, socklen_t));
+
+#include <errno.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    struct sockaddr_in addr;
+
+    addr.sin_family = AF_INET;
+    inet_pton (AF_INET, "127.0.0.1", &addr.sin_addr);
+    addr.sin_port = htons (80);
+    {
+      errno = 0;
+      ASSERT (bind (-1, (const struct sockaddr *) &addr, sizeof (addr)) == -1);
+      ASSERT (errno == EBADF);
+    }
+    {
+      errno = 0;
+      ASSERT (bind (99, (const struct sockaddr *) &addr, sizeof (addr)) == -1);
+      ASSERT (errno == EBADF);
+    }
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-close.c b/gl/tests/test-close.c
new file mode 100644
index 0000000..2b87db1
--- /dev/null
+++ b/gl/tests/test-close.c
@@ -0,0 +1,44 @@
+/* Test closing a file or socket.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (close, int, (int));
+
+#include <errno.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (close (-1) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (close (99) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-connect.c b/gl/tests/test-connect.c
new file mode 100644
index 0000000..84f00b5
--- /dev/null
+++ b/gl/tests/test-connect.c
@@ -0,0 +1,58 @@
+/* Test connecting a client socket.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (connect, int, (int, const struct sockaddr *, socklen_t));
+
+#include <errno.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    struct sockaddr_in addr;
+
+    addr.sin_family = AF_INET;
+    inet_pton (AF_INET, "127.0.0.1", &addr.sin_addr);
+    addr.sin_port = htons (80);
+    {
+      errno = 0;
+      ASSERT (connect (-1, (const struct sockaddr *) &addr, sizeof (addr))
+              == -1);
+      ASSERT (errno == EBADF);
+    }
+    {
+      errno = 0;
+      ASSERT (connect (99, (const struct sockaddr *) &addr, sizeof (addr))
+              == -1);
+      ASSERT (errno == EBADF);
+    }
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-dup2.c b/gl/tests/test-dup2.c
index 37454e9..a14807a 100644
--- a/gl/tests/test-dup2.c
+++ b/gl/tests/test-dup2.c
@@ -36,6 +36,8 @@ SIGNATURE_CHECK (dup2, int, (int, int));
 /* Get declarations of the Win32 API functions.  */
 # define WIN32_LEAN_AND_MEAN
 # include <windows.h>
+/* Get _get_osfhandle.  */
+# include "msvc-nothrow.h"
 #endif
 
 #include "macros.h"
diff --git a/gl/tests/test-fgetc.c b/gl/tests/test-fgetc.c
index a4e1953..4df46fb 100644
--- a/gl/tests/test-fgetc.c
+++ b/gl/tests/test-fgetc.c
@@ -26,6 +26,8 @@ SIGNATURE_CHECK (fgetc, int, (FILE *));
 #include <fcntl.h>
 #include <unistd.h>
 
+#include "msvc-inval.h"
+
 #include "macros.h"
 
 int
@@ -33,6 +35,13 @@ main (int argc, char **argv)
 {
   const char *filename = "test-fgetc.txt";
 
+  /* We don't have an fgetc() function that installs an invalid parameter
+     handler so far.  So install that handler here, explicitly.  */
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+    && MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+  gl_msvc_inval_ensure_handler ();
+#endif
+
   /* Prepare a file.  */
   {
     const char text[] = "hello world";
@@ -51,6 +60,7 @@ main (int argc, char **argv)
     errno = 0;
     ASSERT (fgetc (fp) == EOF);
     ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
     fclose (fp);
   }
 
@@ -63,6 +73,7 @@ main (int argc, char **argv)
         errno = 0;
         ASSERT (fgetc (fp) == EOF);
         ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
         fclose (fp);
       }
   }
@@ -73,6 +84,7 @@ main (int argc, char **argv)
         errno = 0;
         ASSERT (fgetc (fp) == EOF);
         ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
         fclose (fp);
       }
   }
diff --git a/gl/tests/test-fputc.c b/gl/tests/test-fputc.c
new file mode 100644
index 0000000..03a3716
--- /dev/null
+++ b/gl/tests/test-fputc.c
@@ -0,0 +1,90 @@
+/* Test of fputc() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (fputc, int, (int, FILE *));
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "msvc-inval.h"
+
+#include "macros.h"
+
+int
+main (int argc, char **argv)
+{
+  const char *filename = "test-fputc.txt";
+
+  /* We don't have an fputc() function that installs an invalid parameter
+     handler so far.  So install that handler here, explicitly.  */
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+    && MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+  gl_msvc_inval_ensure_handler ();
+#endif
+
+  /* Test that fputc() on an unbuffered stream sets errno if someone else
+     closes the stream fd behind the back of stdio.  */
+  {
+    FILE *fp = fopen (filename, "w");
+    ASSERT (fp != NULL);
+    setvbuf (fp, NULL, _IONBF, 0);
+    ASSERT (close (fileno (fp)) == 0);
+    errno = 0;
+    ASSERT (fputc ('x', fp) == EOF);
+    ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
+    fclose (fp);
+  }
+
+  /* Test that fputc() on an unbuffered stream sets errno if the stream
+     was constructed with an invalid file descriptor.  */
+  {
+    FILE *fp = fdopen (-1, "w");
+    if (fp != NULL)
+      {
+        setvbuf (fp, NULL, _IONBF, 0);
+        errno = 0;
+        ASSERT (fputc ('x', fp) == EOF);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "w");
+    if (fp != NULL)
+      {
+        setvbuf (fp, NULL, _IONBF, 0);
+        errno = 0;
+        ASSERT (fputc ('x', fp) == EOF);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+
+  /* Clean up.  */
+  unlink (filename);
+
+  return 0;
+}
diff --git a/gl/tests/test-fread.c b/gl/tests/test-fread.c
new file mode 100644
index 0000000..e205c9e
--- /dev/null
+++ b/gl/tests/test-fread.c
@@ -0,0 +1,99 @@
+/* Test of fread() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (fread, size_t, (void *, size_t, size_t, FILE *));
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "msvc-inval.h"
+
+#include "macros.h"
+
+int
+main (int argc, char **argv)
+{
+  const char *filename = "test-fread.txt";
+
+  /* We don't have an fread() function that installs an invalid parameter
+     handler so far.  So install that handler here, explicitly.  */
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+    && MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+  gl_msvc_inval_ensure_handler ();
+#endif
+
+  /* Prepare a file.  */
+  {
+    const char text[] = "hello world";
+    int fd = open (filename, O_RDWR | O_CREAT | O_TRUNC, 0600);
+    ASSERT (fd >= 0);
+    ASSERT (write (fd, text, sizeof (text)) == sizeof (text));
+    ASSERT (close (fd) == 0);
+  }
+
+  /* Test that fread() sets errno if someone else closes the stream
+     fd behind the back of stdio.  */
+  {
+    FILE *fp = fopen (filename, "r");
+    char buf[5];
+    ASSERT (fp != NULL);
+    ASSERT (close (fileno (fp)) == 0);
+    errno = 0;
+    ASSERT (fread (buf, 1, sizeof (buf), fp) == 0);
+    ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
+    fclose (fp);
+  }
+
+  /* Test that fread() sets errno if the stream was constructed with
+     an invalid file descriptor.  */
+  {
+    FILE *fp = fdopen (-1, "r");
+    if (fp != NULL)
+      {
+        char buf[1];
+        errno = 0;
+        ASSERT (fread (buf, 1, 1, fp) == 0);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "r");
+    if (fp != NULL)
+      {
+        char buf[1];
+        errno = 0;
+        ASSERT (fread (buf, 1, 1, fp) == 0);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+
+  /* Clean up.  */
+  unlink (filename);
+
+  return 0;
+}
diff --git a/gl/tests/test-ftruncate.c b/gl/tests/test-ftruncate.c
new file mode 100644
index 0000000..c5da4eb
--- /dev/null
+++ b/gl/tests/test-ftruncate.c
@@ -0,0 +1,59 @@
+/* Test truncating a file.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (ftruncate, int, (int, off_t));
+
+#include <errno.h>
+#include <fcntl.h>
+
+#include "macros.h"
+
+int
+main (int argc, char *argv[])
+{
+  const char *filename = argv[1];
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (ftruncate (-1, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (ftruncate (99, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  /* Test behaviour for read-only file descriptors.  */
+  {
+    int fd = open (filename, O_RDONLY);
+    ASSERT (fd >= 0);
+    errno = 0;
+    ASSERT (ftruncate (fd, 0) == -1);
+    ASSERT (errno == EBADF || errno == EINVAL
+            || errno == EACCES /* seen on mingw */
+           );
+    close (fd);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-ftruncate.sh b/gl/tests/test-ftruncate.sh
new file mode 100755
index 0000000..d7394d2
--- /dev/null
+++ b/gl/tests/test-ftruncate.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exec ./test-ftruncate${EXEEXT} "$srcdir/test-ftruncate.sh"
diff --git a/gl/tests/test-fwrite.c b/gl/tests/test-fwrite.c
new file mode 100644
index 0000000..76ed05c
--- /dev/null
+++ b/gl/tests/test-fwrite.c
@@ -0,0 +1,93 @@
+/* Test of fwrite() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (fwrite, size_t, (const void *, size_t, size_t, FILE *));
+
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "msvc-inval.h"
+
+#include "macros.h"
+
+int
+main (int argc, char **argv)
+{
+  const char *filename = "test-fwrite.txt";
+
+  /* We don't have an fwrite() function that installs an invalid parameter
+     handler so far.  So install that handler here, explicitly.  */
+#if HAVE_MSVC_INVALID_PARAMETER_HANDLER \
+    && MSVC_INVALID_PARAMETER_HANDLING == DEFAULT_HANDLING
+  gl_msvc_inval_ensure_handler ();
+#endif
+
+  /* Test that fwrite() on an unbuffered stream sets errno if someone else
+     closes the stream fd behind the back of stdio.  */
+  {
+    FILE *fp = fopen (filename, "w");
+    char buf[5] = "world";
+    ASSERT (fp != NULL);
+    setvbuf (fp, NULL, _IONBF, 0);
+    ASSERT (close (fileno (fp)) == 0);
+    errno = 0;
+    ASSERT (fwrite (buf, 1, sizeof (buf), fp) == 0);
+    ASSERT (errno == EBADF);
+    ASSERT (ferror (fp));
+    fclose (fp);
+  }
+
+  /* Test that fwrite() on an unbuffered stream sets errno if the stream
+     was constructed with an invalid file descriptor.  */
+  {
+    FILE *fp = fdopen (-1, "w");
+    if (fp != NULL)
+      {
+        char buf[5] = "world";
+        setvbuf (fp, NULL, _IONBF, 0);
+        errno = 0;
+        ASSERT (fwrite (buf, 1, sizeof (buf), fp) == 0);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+  {
+    FILE *fp = fdopen (99, "w");
+    if (fp != NULL)
+      {
+        char buf[5] = "world";
+        setvbuf (fp, NULL, _IONBF, 0);
+        errno = 0;
+        ASSERT (fwrite (buf, 1, sizeof (buf), fp) == 0);
+        ASSERT (errno == EBADF);
+        ASSERT (ferror (fp));
+        fclose (fp);
+      }
+  }
+
+  /* Clean up.  */
+  unlink (filename);
+
+  return 0;
+}
diff --git a/gl/tests/test-getpeername.c b/gl/tests/test-getpeername.c
new file mode 100644
index 0000000..1ccd9b4
--- /dev/null
+++ b/gl/tests/test-getpeername.c
@@ -0,0 +1,54 @@
+/* Test getpeername() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (getpeername, int, (int, struct sockaddr *, socklen_t *));
+
+#include <errno.h>
+#include <netinet/in.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    struct sockaddr_in addr;
+    socklen_t addrlen = sizeof (addr);
+
+    errno = 0;
+    ASSERT (getpeername (-1, (struct sockaddr *) &addr, &addrlen) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    struct sockaddr_in addr;
+    socklen_t addrlen = sizeof (addr);
+
+    errno = 0;
+    ASSERT (getpeername (99, (struct sockaddr *) &addr, &addrlen) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-hmac-md5.c b/gl/tests/test-hmac-md5.c
deleted file mode 100644
index 575a716..0000000
--- a/gl/tests/test-hmac-md5.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright (C) 2005, 2010-2011 Free Software Foundation, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-/* Written by Simon Josefsson.  */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <string.h>
-#include "hmac.h"
-
-/* Test vectors from RFC 2104. */
-
-int
-main (int argc, char *argv[])
-{
-  {
-    /*
-       key =         0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
-       key_len =     16 bytes
-       data =        "Hi There"
-       data_len =    8  bytes
-       digest =      0x9294727a3638bb1c13f48ef8158bfc9d
-     */
-    char *key =
-      "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b";
-    size_t key_len = 16;
-    char *data = "Hi There";
-    size_t data_len = 8;
-    char *digest =
-      "\x92\x94\x72\x7a\x36\x38\xbb\x1c\x13\xf4\x8e\xf8\x15\x8b\xfc\x9d";
-    char out[16];
-
-    if (hmac_md5 (key, key_len, data, data_len, out) != 0)
-      {
-        printf ("call failure\n");
-        return 1;
-      }
-
-    if (memcmp (digest, out, 16) != 0)
-      {
-        size_t i;
-        printf ("hash 1 mismatch. expected:\n");
-        for (i = 0; i < 16; i++)
-          printf ("%02x ", digest[i] & 0xFF);
-        printf ("\ncomputed:\n");
-        for (i = 0; i < 16; i++)
-          printf ("%02x ", out[i] & 0xFF);
-        printf ("\n");
-        return 1;
-      }
-  }
-
-  {
-    /*
-       key =         "Jefe"
-       data =        "what do ya want for nothing?"
-       data_len =    28 bytes
-       digest =      0x750c783e6ab0b503eaa86e310a5db738
-     */
-    char *key = "Jefe";
-    size_t key_len = 4;
-    char *data = "what do ya want for nothing?";
-    size_t data_len = 28;
-    char *digest =
-      "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38";
-    char out[16];
-
-    if (hmac_md5 (key, key_len, data, data_len, out) != 0)
-      {
-        printf ("call failure\n");
-        return 1;
-      }
-
-    if (memcmp (digest, out, 16) != 0)
-      {
-        size_t i;
-        printf ("hash 2 mismatch. expected:\n");
-        for (i = 0; i < 16; i++)
-          printf ("%02x ", digest[i] & 0xFF);
-        printf ("\ncomputed:\n");
-        for (i = 0; i < 16; i++)
-          printf ("%02x ", out[i] & 0xFF);
-        printf ("\n");
-        return 1;
-      }
-  }
-
-  {
-    /*
-       key =         0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
-       key_len       16 bytes
-       data =        0xDDDDDDDDDDDDDDDDDDDD...
-       ..DDDDDDDDDDDDDDDDDDDD...
-       ..DDDDDDDDDDDDDDDDDDDD...
-       ..DDDDDDDDDDDDDDDDDDDD...
-       ..DDDDDDDDDDDDDDDDDDDD
-       data_len =    50 bytes
-       digest =      0x56be34521d144c88dbb8c733f0e8b3f6
-     */
-    char *key =
-      "\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA\xAA";
-    size_t key_len = 16;
-    char *data = "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
-      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
-      "\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD\xDD"
-      "\xDD\xDD";
-    size_t data_len = 50;
-    char *digest =
-      "\x56\xbe\x34\x52\x1d\x14\x4c\x88\xdb\xb8\xc7\x33\xf0\xe8\xb3\xf6";
-    char out[16];
-
-    if (hmac_md5 (key, key_len, data, data_len, out) != 0)
-      {
-        printf ("call failure\n");
-        return 1;
-      }
-
-    if (memcmp (digest, out, 16) != 0)
-      {
-        size_t i;
-        printf ("hash 3 mismatch. expected:\n");
-        for (i = 0; i < 16; i++)
-          printf ("%02x ", digest[i] & 0xFF);
-        printf ("\ncomputed:\n");
-        for (i = 0; i < 16; i++)
-          printf ("%02x ", out[i] & 0xFF);
-        printf ("\n");
-        return 1;
-      }
-  }
-
-  return 0;
-}
diff --git a/gl/tests/test-inet_ntop.c b/gl/tests/test-inet_ntop.c
new file mode 100644
index 0000000..ebb7c1c
--- /dev/null
+++ b/gl/tests/test-inet_ntop.c
@@ -0,0 +1,56 @@
+/* Test of inet_ntop function.
+   Copyright (C) 2009-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2009.  */
+
+#include <config.h>
+
+#include <arpa/inet.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (inet_ntop, char const *, (int, void const *, char *,
+                                           socklen_t));
+
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <string.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+#if defined AF_INET /* HAVE_IPV4 */
+  {
+    struct in_addr internal;
+    char printable[16];
+    const char *result;
+
+    /* This machine was for a long time known as
+       ma2s2.mathematik.uni-karlsruhe.de.  */
+# ifdef WORDS_BIGENDIAN
+    internal.s_addr = 0x810D7302;
+# else
+    internal.s_addr = 0x02730D81;
+# endif
+    result = inet_ntop (AF_INET, &internal, printable, sizeof (printable));
+    ASSERT (result != NULL);
+    ASSERT (strcmp (result, "129.13.115.2") == 0);
+  }
+#endif
+
+  return 0;
+}
diff --git a/gl/tests/test-inet_pton.c b/gl/tests/test-inet_pton.c
new file mode 100644
index 0000000..49c140c
--- /dev/null
+++ b/gl/tests/test-inet_pton.c
@@ -0,0 +1,58 @@
+/* Test of inet_pton function.
+   Copyright (C) 2009-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2009.  */
+
+#include <config.h>
+
+#include <arpa/inet.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (inet_pton, int, (int, const char *, void *));
+
+#include <netinet/in.h>
+#include <sys/socket.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+#if defined AF_INET /* HAVE_IPV4 */
+  {
+    /* This machine was for a long time known as
+       ma2s2.mathematik.uni-karlsruhe.de.  */
+    const char printable[] = "129.13.115.2";
+    struct in_addr internal;
+    int ret;
+
+    ret = inet_pton (AF_INET, printable, &internal);
+    ASSERT (ret == 1);
+    /* Verify that internal is filled in network byte order.  */
+    ASSERT (((unsigned char *) &internal)[0] == 0x81);
+    ASSERT (((unsigned char *) &internal)[1] == 0x0D);
+    ASSERT (((unsigned char *) &internal)[2] == 0x73);
+    ASSERT (((unsigned char *) &internal)[3] == 0x02);
+# ifdef WORDS_BIGENDIAN
+    ASSERT (internal.s_addr == 0x810D7302);
+# else
+    ASSERT (internal.s_addr == 0x02730D81);
+# endif
+  }
+#endif
+
+  return 0;
+}
diff --git a/gl/tests/test-ioctl.c b/gl/tests/test-ioctl.c
new file mode 100644
index 0000000..130ee42
--- /dev/null
+++ b/gl/tests/test-ioctl.c
@@ -0,0 +1,49 @@
+/* Test of ioctl() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include <sys/ioctl.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (ioctl, int, (int, int, ...));
+
+#include <errno.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+#ifdef FIONREAD
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    int value;
+    errno = 0;
+    ASSERT (ioctl (-1, FIONREAD, &value) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    int value;
+    errno = 0;
+    ASSERT (ioctl (99, FIONREAD, &value) == -1);
+    ASSERT (errno == EBADF);
+  }
+#endif
+
+  return 0;
+}
diff --git a/gl/tests/test-isnanl.h b/gl/tests/test-isnanl.h
index 055d05f..9f1d763 100644
--- a/gl/tests/test-isnanl.h
+++ b/gl/tests/test-isnanl.h
@@ -65,7 +65,7 @@ main ()
   }
 #endif
 
-#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined 
__amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined 
_M_IX86 || defined _X86_))
+#if ((defined __ia64 && LDBL_MANT_DIG == 64) || (defined __x86_64__ || defined 
__amd64__) || (defined __i386 || defined __i386__ || defined _I386 || defined 
_M_IX86 || defined _X86_)) && !HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
 /* Representation of an 80-bit 'long double' as an initializer for a sequence
    of 'unsigned int' words.  */
 # ifdef WORDS_BIGENDIAN
diff --git a/gl/tests/test-listen.c b/gl/tests/test-listen.c
new file mode 100644
index 0000000..becc453
--- /dev/null
+++ b/gl/tests/test-listen.c
@@ -0,0 +1,47 @@
+/* Test listen() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (listen, int, (int, int));
+
+#include <errno.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (listen (-1, 1) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (listen (99 ,1) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-lock.c b/gl/tests/test-lock.c
new file mode 100644
index 0000000..3f8846b
--- /dev/null
+++ b/gl/tests/test-lock.c
@@ -0,0 +1,601 @@
+/* Test of locking in multithreaded situations.
+   Copyright (C) 2005, 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2005.  */
+
+#include <config.h>
+
+#if USE_POSIX_THREADS || USE_SOLARIS_THREADS || USE_PTH_THREADS || 
USE_WIN32_THREADS
+
+#if USE_POSIX_THREADS
+# define TEST_POSIX_THREADS 1
+#endif
+#if USE_SOLARIS_THREADS
+# define TEST_SOLARIS_THREADS 1
+#endif
+#if USE_PTH_THREADS
+# define TEST_PTH_THREADS 1
+#endif
+#if USE_WIN32_THREADS
+# define TEST_WIN32_THREADS 1
+#endif
+
+/* Whether to enable locking.
+   Uncomment this to get a test program without locking, to verify that
+   it crashes.  */
+#define ENABLE_LOCKING 1
+
+/* Which tests to perform.
+   Uncomment some of these, to verify that all tests crash if no locking
+   is enabled.  */
+#define DO_TEST_LOCK 1
+#define DO_TEST_RWLOCK 1
+#define DO_TEST_RECURSIVE_LOCK 1
+#define DO_TEST_ONCE 1
+
+/* Whether to help the scheduler through explicit yield().
+   Uncomment this to see if the operating system has a fair scheduler.  */
+#define EXPLICIT_YIELD 1
+
+/* Whether to print debugging messages.  */
+#define ENABLE_DEBUGGING 0
+
+/* Number of simultaneous threads.  */
+#define THREAD_COUNT 10
+
+/* Number of operations performed in each thread.
+   This is quite high, because with a smaller count, say 5000, we often get
+   an "OK" result even without ENABLE_LOCKING (on Linux/x86).  */
+#define REPEAT_COUNT 50000
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if !ENABLE_LOCKING
+# undef USE_POSIX_THREADS
+# undef USE_SOLARIS_THREADS
+# undef USE_PTH_THREADS
+# undef USE_WIN32_THREADS
+#endif
+#include "glthread/lock.h"
+
+#if !ENABLE_LOCKING
+# if TEST_POSIX_THREADS
+#  define USE_POSIX_THREADS 1
+# endif
+# if TEST_SOLARIS_THREADS
+#  define USE_SOLARIS_THREADS 1
+# endif
+# if TEST_PTH_THREADS
+#  define USE_PTH_THREADS 1
+# endif
+# if TEST_WIN32_THREADS
+#  define USE_WIN32_THREADS 1
+# endif
+#endif
+
+#include "glthread/thread.h"
+#include "glthread/yield.h"
+
+#if ENABLE_DEBUGGING
+# define dbgprintf printf
+#else
+# define dbgprintf if (0) printf
+#endif
+
+#if EXPLICIT_YIELD
+# define yield() gl_thread_yield ()
+#else
+# define yield()
+#endif
+
+#define ACCOUNT_COUNT 4
+
+static int account[ACCOUNT_COUNT];
+
+static int
+random_account (void)
+{
+  return ((unsigned int) rand () >> 3) % ACCOUNT_COUNT;
+}
+
+static void
+check_accounts (void)
+{
+  int i, sum;
+
+  sum = 0;
+  for (i = 0; i < ACCOUNT_COUNT; i++)
+    sum += account[i];
+  if (sum != ACCOUNT_COUNT * 1000)
+    abort ();
+}
+
+
+/* ------------------- Test normal (non-recursive) locks ------------------- */
+
+/* Test normal locks by having several bank accounts and several threads
+   which shuffle around money between the accounts and another thread
+   checking that all the money is still there.  */
+
+gl_lock_define_initialized(static, my_lock)
+
+static void *
+lock_mutator_thread (void *arg)
+{
+  int repeat;
+
+  for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
+    {
+      int i1, i2, value;
+
+      dbgprintf ("Mutator %p before lock\n", gl_thread_self_pointer ());
+      gl_lock_lock (my_lock);
+      dbgprintf ("Mutator %p after  lock\n", gl_thread_self_pointer ());
+
+      i1 = random_account ();
+      i2 = random_account ();
+      value = ((unsigned int) rand () >> 3) % 10;
+      account[i1] += value;
+      account[i2] -= value;
+
+      dbgprintf ("Mutator %p before unlock\n", gl_thread_self_pointer ());
+      gl_lock_unlock (my_lock);
+      dbgprintf ("Mutator %p after  unlock\n", gl_thread_self_pointer ());
+
+      dbgprintf ("Mutator %p before check lock\n", gl_thread_self_pointer ());
+      gl_lock_lock (my_lock);
+      check_accounts ();
+      gl_lock_unlock (my_lock);
+      dbgprintf ("Mutator %p after  check unlock\n", gl_thread_self_pointer 
());
+
+      yield ();
+    }
+
+  dbgprintf ("Mutator %p dying.\n", gl_thread_self_pointer ());
+  return NULL;
+}
+
+static volatile int lock_checker_done;
+
+static void *
+lock_checker_thread (void *arg)
+{
+  while (!lock_checker_done)
+    {
+      dbgprintf ("Checker %p before check lock\n", gl_thread_self_pointer ());
+      gl_lock_lock (my_lock);
+      check_accounts ();
+      gl_lock_unlock (my_lock);
+      dbgprintf ("Checker %p after  check unlock\n", gl_thread_self_pointer 
());
+
+      yield ();
+    }
+
+  dbgprintf ("Checker %p dying.\n", gl_thread_self_pointer ());
+  return NULL;
+}
+
+static void
+test_lock (void)
+{
+  int i;
+  gl_thread_t checkerthread;
+  gl_thread_t threads[THREAD_COUNT];
+
+  /* Initialization.  */
+  for (i = 0; i < ACCOUNT_COUNT; i++)
+    account[i] = 1000;
+  lock_checker_done = 0;
+
+  /* Spawn the threads.  */
+  checkerthread = gl_thread_create (lock_checker_thread, NULL);
+  for (i = 0; i < THREAD_COUNT; i++)
+    threads[i] = gl_thread_create (lock_mutator_thread, NULL);
+
+  /* Wait for the threads to terminate.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    gl_thread_join (threads[i], NULL);
+  lock_checker_done = 1;
+  gl_thread_join (checkerthread, NULL);
+  check_accounts ();
+}
+
+
+/* ----------------- Test read-write (non-recursive) locks ----------------- */
+
+/* Test read-write locks by having several bank accounts and several threads
+   which shuffle around money between the accounts and several other threads
+   that check that all the money is still there.  */
+
+gl_rwlock_define_initialized(static, my_rwlock)
+
+static void *
+rwlock_mutator_thread (void *arg)
+{
+  int repeat;
+
+  for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
+    {
+      int i1, i2, value;
+
+      dbgprintf ("Mutator %p before wrlock\n", gl_thread_self_pointer ());
+      gl_rwlock_wrlock (my_rwlock);
+      dbgprintf ("Mutator %p after  wrlock\n", gl_thread_self_pointer ());
+
+      i1 = random_account ();
+      i2 = random_account ();
+      value = ((unsigned int) rand () >> 3) % 10;
+      account[i1] += value;
+      account[i2] -= value;
+
+      dbgprintf ("Mutator %p before unlock\n", gl_thread_self_pointer ());
+      gl_rwlock_unlock (my_rwlock);
+      dbgprintf ("Mutator %p after  unlock\n", gl_thread_self_pointer ());
+
+      yield ();
+    }
+
+  dbgprintf ("Mutator %p dying.\n", gl_thread_self_pointer ());
+  return NULL;
+}
+
+static volatile int rwlock_checker_done;
+
+static void *
+rwlock_checker_thread (void *arg)
+{
+  while (!rwlock_checker_done)
+    {
+      dbgprintf ("Checker %p before check rdlock\n", gl_thread_self_pointer 
());
+      gl_rwlock_rdlock (my_rwlock);
+      check_accounts ();
+      gl_rwlock_unlock (my_rwlock);
+      dbgprintf ("Checker %p after  check unlock\n", gl_thread_self_pointer 
());
+
+      yield ();
+    }
+
+  dbgprintf ("Checker %p dying.\n", gl_thread_self_pointer ());
+  return NULL;
+}
+
+static void
+test_rwlock (void)
+{
+  int i;
+  gl_thread_t checkerthreads[THREAD_COUNT];
+  gl_thread_t threads[THREAD_COUNT];
+
+  /* Initialization.  */
+  for (i = 0; i < ACCOUNT_COUNT; i++)
+    account[i] = 1000;
+  rwlock_checker_done = 0;
+
+  /* Spawn the threads.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    checkerthreads[i] = gl_thread_create (rwlock_checker_thread, NULL);
+  for (i = 0; i < THREAD_COUNT; i++)
+    threads[i] = gl_thread_create (rwlock_mutator_thread, NULL);
+
+  /* Wait for the threads to terminate.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    gl_thread_join (threads[i], NULL);
+  rwlock_checker_done = 1;
+  for (i = 0; i < THREAD_COUNT; i++)
+    gl_thread_join (checkerthreads[i], NULL);
+  check_accounts ();
+}
+
+
+/* -------------------------- Test recursive locks -------------------------- 
*/
+
+/* Test recursive locks by having several bank accounts and several threads
+   which shuffle around money between the accounts (recursively) and another
+   thread checking that all the money is still there.  */
+
+gl_recursive_lock_define_initialized(static, my_reclock)
+
+static void
+recshuffle (void)
+{
+  int i1, i2, value;
+
+  dbgprintf ("Mutator %p before lock\n", gl_thread_self_pointer ());
+  gl_recursive_lock_lock (my_reclock);
+  dbgprintf ("Mutator %p after  lock\n", gl_thread_self_pointer ());
+
+  i1 = random_account ();
+  i2 = random_account ();
+  value = ((unsigned int) rand () >> 3) % 10;
+  account[i1] += value;
+  account[i2] -= value;
+
+  /* Recursive with probability 0.5.  */
+  if (((unsigned int) rand () >> 3) % 2)
+    recshuffle ();
+
+  dbgprintf ("Mutator %p before unlock\n", gl_thread_self_pointer ());
+  gl_recursive_lock_unlock (my_reclock);
+  dbgprintf ("Mutator %p after  unlock\n", gl_thread_self_pointer ());
+}
+
+static void *
+reclock_mutator_thread (void *arg)
+{
+  int repeat;
+
+  for (repeat = REPEAT_COUNT; repeat > 0; repeat--)
+    {
+      recshuffle ();
+
+      dbgprintf ("Mutator %p before check lock\n", gl_thread_self_pointer ());
+      gl_recursive_lock_lock (my_reclock);
+      check_accounts ();
+      gl_recursive_lock_unlock (my_reclock);
+      dbgprintf ("Mutator %p after  check unlock\n", gl_thread_self_pointer 
());
+
+      yield ();
+    }
+
+  dbgprintf ("Mutator %p dying.\n", gl_thread_self_pointer ());
+  return NULL;
+}
+
+static volatile int reclock_checker_done;
+
+static void *
+reclock_checker_thread (void *arg)
+{
+  while (!reclock_checker_done)
+    {
+      dbgprintf ("Checker %p before check lock\n", gl_thread_self_pointer ());
+      gl_recursive_lock_lock (my_reclock);
+      check_accounts ();
+      gl_recursive_lock_unlock (my_reclock);
+      dbgprintf ("Checker %p after  check unlock\n", gl_thread_self_pointer 
());
+
+      yield ();
+    }
+
+  dbgprintf ("Checker %p dying.\n", gl_thread_self_pointer ());
+  return NULL;
+}
+
+static void
+test_recursive_lock (void)
+{
+  int i;
+  gl_thread_t checkerthread;
+  gl_thread_t threads[THREAD_COUNT];
+
+  /* Initialization.  */
+  for (i = 0; i < ACCOUNT_COUNT; i++)
+    account[i] = 1000;
+  reclock_checker_done = 0;
+
+  /* Spawn the threads.  */
+  checkerthread = gl_thread_create (reclock_checker_thread, NULL);
+  for (i = 0; i < THREAD_COUNT; i++)
+    threads[i] = gl_thread_create (reclock_mutator_thread, NULL);
+
+  /* Wait for the threads to terminate.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    gl_thread_join (threads[i], NULL);
+  reclock_checker_done = 1;
+  gl_thread_join (checkerthread, NULL);
+  check_accounts ();
+}
+
+
+/* ------------------------ Test once-only execution ------------------------ 
*/
+
+/* Test once-only execution by having several threads attempt to grab a
+   once-only task simultaneously (triggered by releasing a read-write lock).  
*/
+
+gl_once_define(static, fresh_once)
+static int ready[THREAD_COUNT];
+static gl_lock_t ready_lock[THREAD_COUNT];
+#if ENABLE_LOCKING
+static gl_rwlock_t fire_signal[REPEAT_COUNT];
+#else
+static volatile int fire_signal_state;
+#endif
+static gl_once_t once_control;
+static int performed;
+gl_lock_define_initialized(static, performed_lock)
+
+static void
+once_execute (void)
+{
+  gl_lock_lock (performed_lock);
+  performed++;
+  gl_lock_unlock (performed_lock);
+}
+
+static void *
+once_contender_thread (void *arg)
+{
+  int id = (int) (long) arg;
+  int repeat;
+
+  for (repeat = 0; repeat <= REPEAT_COUNT; repeat++)
+    {
+      /* Tell the main thread that we're ready.  */
+      gl_lock_lock (ready_lock[id]);
+      ready[id] = 1;
+      gl_lock_unlock (ready_lock[id]);
+
+      if (repeat == REPEAT_COUNT)
+        break;
+
+      dbgprintf ("Contender %p waiting for signal for round %d\n",
+                 gl_thread_self_pointer (), repeat);
+#if ENABLE_LOCKING
+      /* Wait for the signal to go.  */
+      gl_rwlock_rdlock (fire_signal[repeat]);
+      /* And don't hinder the others (if the scheduler is unfair).  */
+      gl_rwlock_unlock (fire_signal[repeat]);
+#else
+      /* Wait for the signal to go.  */
+      while (fire_signal_state <= repeat)
+        yield ();
+#endif
+      dbgprintf ("Contender %p got the     signal for round %d\n",
+                 gl_thread_self_pointer (), repeat);
+
+      /* Contend for execution.  */
+      gl_once (once_control, once_execute);
+    }
+
+  return NULL;
+}
+
+static void
+test_once (void)
+{
+  int i, repeat;
+  gl_thread_t threads[THREAD_COUNT];
+
+  /* Initialize all variables.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    {
+      ready[i] = 0;
+      gl_lock_init (ready_lock[i]);
+    }
+#if ENABLE_LOCKING
+  for (i = 0; i < REPEAT_COUNT; i++)
+    gl_rwlock_init (fire_signal[i]);
+#else
+  fire_signal_state = 0;
+#endif
+
+  /* Block all fire_signals.  */
+  for (i = REPEAT_COUNT-1; i >= 0; i--)
+    gl_rwlock_wrlock (fire_signal[i]);
+
+  /* Spawn the threads.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    threads[i] = gl_thread_create (once_contender_thread, (void *) (long) i);
+
+  for (repeat = 0; repeat <= REPEAT_COUNT; repeat++)
+    {
+      /* Wait until every thread is ready.  */
+      dbgprintf ("Main thread before synchonizing for round %d\n", repeat);
+      for (;;)
+        {
+          int ready_count = 0;
+          for (i = 0; i < THREAD_COUNT; i++)
+            {
+              gl_lock_lock (ready_lock[i]);
+              ready_count += ready[i];
+              gl_lock_unlock (ready_lock[i]);
+            }
+          if (ready_count == THREAD_COUNT)
+            break;
+          yield ();
+        }
+      dbgprintf ("Main thread after  synchonizing for round %d\n", repeat);
+
+      if (repeat > 0)
+        {
+          /* Check that exactly one thread executed the once_execute()
+             function.  */
+          if (performed != 1)
+            abort ();
+        }
+
+      if (repeat == REPEAT_COUNT)
+        break;
+
+      /* Preparation for the next round: Initialize once_control.  */
+      memcpy (&once_control, &fresh_once, sizeof (gl_once_t));
+
+      /* Preparation for the next round: Reset the performed counter.  */
+      performed = 0;
+
+      /* Preparation for the next round: Reset the ready flags.  */
+      for (i = 0; i < THREAD_COUNT; i++)
+        {
+          gl_lock_lock (ready_lock[i]);
+          ready[i] = 0;
+          gl_lock_unlock (ready_lock[i]);
+        }
+
+      /* Signal all threads simultaneously.  */
+      dbgprintf ("Main thread giving signal for round %d\n", repeat);
+#if ENABLE_LOCKING
+      gl_rwlock_unlock (fire_signal[repeat]);
+#else
+      fire_signal_state = repeat + 1;
+#endif
+    }
+
+  /* Wait for the threads to terminate.  */
+  for (i = 0; i < THREAD_COUNT; i++)
+    gl_thread_join (threads[i], NULL);
+}
+
+
+/* -------------------------------------------------------------------------- 
*/
+
+int
+main ()
+{
+#if TEST_PTH_THREADS
+  if (!pth_init ())
+    abort ();
+#endif
+
+#if DO_TEST_LOCK
+  printf ("Starting test_lock ..."); fflush (stdout);
+  test_lock ();
+  printf (" OK\n"); fflush (stdout);
+#endif
+#if DO_TEST_RWLOCK
+  printf ("Starting test_rwlock ..."); fflush (stdout);
+  test_rwlock ();
+  printf (" OK\n"); fflush (stdout);
+#endif
+#if DO_TEST_RECURSIVE_LOCK
+  printf ("Starting test_recursive_lock ..."); fflush (stdout);
+  test_recursive_lock ();
+  printf (" OK\n"); fflush (stdout);
+#endif
+#if DO_TEST_ONCE
+  printf ("Starting test_once ..."); fflush (stdout);
+  test_once ();
+  printf (" OK\n"); fflush (stdout);
+#endif
+
+  return 0;
+}
+
+#else
+
+/* No multithreading available.  */
+
+#include <stdio.h>
+
+int
+main ()
+{
+  fputs ("Skipping test: multithreading not enabled\n", stderr);
+  return 77;
+}
+
+#endif
diff --git a/gl/tests/test-md5.c b/gl/tests/test-md5.c
deleted file mode 100644
index 99d49b8..0000000
--- a/gl/tests/test-md5.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2005, 2009-2011 Free Software Foundation, Inc.
- * Written by Simon Josefsson
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
-
-/* Written by Simon Josefsson. */
-
-#include <config.h>
-
-#include <stdio.h>
-#include <string.h>
-
-#include "md5.h"
-
-int
-main (void)
-{
-  /* Test vectors from RFC 1321. */
-
-  const char *in1 = "abc";
-  const char *out1 =
-    "\x90\x01\x50\x98\x3C\xD2\x4F\xB0\xD6\x96\x3F\x7D\x28\xE1\x7F\x72";
-  const char *in2 = "message digest";
-  const char *out2 =
-    "\xF9\x6B\x69\x7D\x7C\xB7\x93\x8D\x52\x5A\x2F\x31\xAA\xF1\x61\xD0";
-  char buf[MD5_DIGEST_SIZE];
-
-  if (memcmp (md5_buffer (in1, strlen (in1), buf), out1, MD5_DIGEST_SIZE) != 0)
-    {
-      size_t i;
-      printf ("expected:\n");
-      for (i = 0; i < MD5_DIGEST_SIZE; i++)
-        printf ("%02x ", out1[i] & 0xFF);
-      printf ("\ncomputed:\n");
-      for (i = 0; i < MD5_DIGEST_SIZE; i++)
-        printf ("%02x ", buf[i] & 0xFF);
-      printf ("\n");
-      return 1;
-    }
-
-  if (memcmp (md5_buffer (in2, strlen (in2), buf), out2, MD5_DIGEST_SIZE) != 0)
-    {
-      size_t i;
-      printf ("expected:\n");
-      for (i = 0; i < MD5_DIGEST_SIZE; i++)
-        printf ("%02x ", out2[i] & 0xFF);
-      printf ("\ncomputed:\n");
-      for (i = 0; i < MD5_DIGEST_SIZE; i++)
-        printf ("%02x ", buf[i] & 0xFF);
-      printf ("\n");
-      return 1;
-    }
-
-  return 0;
-}
diff --git a/gl/tests/test-perror.c b/gl/tests/test-perror.c
new file mode 100644
index 0000000..d3751d8
--- /dev/null
+++ b/gl/tests/test-perror.c
@@ -0,0 +1,37 @@
+/* Test of perror() function.
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (perror, void, (char const *));
+
+#include <errno.h>
+
+int
+main (int argc, char **argv)
+{
+  const char *prefix = (argc > 1 ? argv[1] : NULL);
+
+  errno = EACCES;    perror (prefix);
+  errno = ETIMEDOUT; perror (prefix);
+  errno = EOVERFLOW; perror (prefix);
+
+  return 0;
+}
diff --git a/gl/tests/test-perror.sh b/gl/tests/test-perror.sh
new file mode 100755
index 0000000..7274d32
--- /dev/null
+++ b/gl/tests/test-perror.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+: ${srcdir=.}
+. "$srcdir/init.sh"; path_prepend_ .
+
+# Test NULL prefix. Result should not contain a number.
+test-perror 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror.tmp
+grep '[0-9]' t-perror.tmp > /dev/null \
+  && fail_ "result should not contain a number"
+
+# Test empty prefix. Result should be the same.
+test-perror '' 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror1.tmp
+diff t-perror.tmp t-perror1.tmp \
+  || fail_ "empty prefix should behave like NULL argument"
+
+# Test non-empty prefix.
+test-perror foo 2>&1 >/dev/null | LC_ALL=C tr -d '\r' > t-perror3.tmp
+sed -e 's/^/foo: /' < t-perror.tmp > t-perror2.tmp
+diff t-perror2.tmp t-perror3.tmp || fail_ "prefix applied incorrectly"
+
+# Test exit status.
+test-perror >out 2>/dev/null || fail_ "unexpected exit status"
+test -s out && fail_ "unexpected output"
+
+Exit 0
diff --git a/gl/tests/test-perror2.c b/gl/tests/test-perror2.c
new file mode 100644
index 0000000..e230f92
--- /dev/null
+++ b/gl/tests/test-perror2.c
@@ -0,0 +1,137 @@
+/* Test of perror() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+#include <stdio.h>
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+/* This test intentionally parses stderr.  So, we arrange to have fd 10
+   (outside the range of interesting fd's during the test) set up to
+   duplicate the original stderr.  */
+#define BACKUP_STDERR_FILENO 10
+#define ASSERT_STREAM myerr
+#include "macros.h"
+
+static FILE *myerr;
+
+#define BASE "test-perror2"
+
+int
+main (void)
+{
+  /* We change fd 2 later, so save it in fd 10.  */
+  if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO
+      || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL)
+    return 2;
+
+  ASSERT (freopen (BASE ".tmp", "w+", stderr) == stderr);
+
+  /* Test that perror does not clobber strerror buffer.  */
+  {
+    const char *msg1;
+    const char *msg2;
+    const char *msg3;
+    const char *msg4;
+    char *str1;
+    char *str2;
+    char *str3;
+    char *str4;
+
+    msg1 = strerror (ENOENT);
+    ASSERT (msg1);
+    str1 = strdup (msg1);
+    ASSERT (str1);
+
+    msg2 = strerror (ERANGE);
+    ASSERT (msg2);
+    str2 = strdup (msg2);
+    ASSERT (str2);
+
+    msg3 = strerror (-4);
+    ASSERT (msg3);
+    str3 = strdup (msg3);
+    ASSERT (str3);
+
+    msg4 = strerror (1729576);
+    ASSERT (msg4);
+    str4 = strdup (msg4);
+    ASSERT (str4);
+
+    errno = EACCES;
+    perror ("");
+    errno = -5;
+    perror ("");
+    ASSERT (!ferror (stderr));
+    ASSERT (msg1 == msg2 || msg1 == msg4 || STREQ (msg1, str1));
+    ASSERT (msg2 == msg4 || STREQ (msg2, str2));
+    ASSERT (msg3 == msg4 || STREQ (msg3, str3));
+    ASSERT (STREQ (msg4, str4));
+
+    free (str1);
+    free (str2);
+    free (str3);
+    free (str4);
+  }
+
+  /* Test that perror uses the same message as strerror.  */
+  {
+    int errs[] = { EACCES, 0, -3, };
+    int i;
+    for (i = 0; i < SIZEOF (errs); i++)
+      {
+        char buf[256];
+        char *err = strerror (errs[i]);
+
+        ASSERT (err);
+        ASSERT (strlen (err) < sizeof buf);
+        rewind (stderr);
+        ASSERT (ftruncate (fileno (stderr), 0) == 0);
+        errno = errs[i];
+        perror (NULL);
+        ASSERT (!ferror (stderr));
+        rewind (stderr);
+        ASSERT (fgets (buf, sizeof buf, stderr) == buf);
+        ASSERT (strstr (buf, err));
+      }
+  }
+
+  /* Test that perror reports write failure.  */
+  {
+    ASSERT (freopen (BASE ".tmp", "r", stderr) == stderr);
+    ASSERT (setvbuf (stderr, NULL, _IONBF, BUFSIZ) == 0);
+    errno = -1;
+    ASSERT (!ferror (stderr));
+    perror (NULL);
+#if 0
+    /* Commented out until cygwin behaves:
+       http://sourceware.org/ml/newlib/2011/msg00228.html */
+    ASSERT (errno > 0);
+    /* Commented out until glibc behaves:
+       http://sourceware.org/bugzilla/show_bug.cgi?id=12792 */
+    ASSERT (ferror (stderr));
+#endif
+  }
+
+  ASSERT (fclose (stderr) == 0);
+  ASSERT (remove (BASE ".tmp") == 0);
+
+  return 0;
+}
diff --git a/gl/tests/test-pipe.c b/gl/tests/test-pipe.c
new file mode 100644
index 0000000..90f41f9
--- /dev/null
+++ b/gl/tests/test-pipe.c
@@ -0,0 +1,105 @@
+/* Test of pipe.
+   Copyright (C) 2009-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (pipe, int, (int[2]));
+
+#include <fcntl.h>
+#include <stdbool.h>
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Get declarations of the Win32 API functions.  */
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+/* Get _get_osfhandle.  */
+# include "msvc-nothrow.h"
+#endif
+
+#include "binary-io.h"
+#include "macros.h"
+
+/* Return true if FD is open.  */
+static bool
+is_open (int fd)
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  /* On Win32, the initial state of unassigned standard file
+     descriptors is that they are open but point to an
+     INVALID_HANDLE_VALUE, and there is no fcntl.  */
+  return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
+#else
+# ifndef F_GETFL
+#  error Please port fcntl to your platform
+# endif
+  return 0 <= fcntl (fd, F_GETFL);
+#endif
+}
+
+/* Return true if FD is not inherited to child processes.  */
+static bool
+is_cloexec (int fd)
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  HANDLE h = (HANDLE) _get_osfhandle (fd);
+  DWORD flags;
+  ASSERT (GetHandleInformation (h, &flags));
+  return (flags & HANDLE_FLAG_INHERIT) == 0;
+#else
+  int flags;
+  ASSERT ((flags = fcntl (fd, F_GETFD)) >= 0);
+  return (flags & FD_CLOEXEC) != 0;
+#endif
+}
+
+/* Return true if FD is in non-blocking mode.  */
+static bool
+is_nonblocking (int fd)
+{
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+  /* We don't use the non-blocking mode for sockets here.  */
+  return 0;
+#else
+  int flags;
+  ASSERT ((flags = fcntl (fd, F_GETFL)) >= 0);
+  return (flags & O_NONBLOCK) != 0;
+#endif
+}
+
+int
+main ()
+{
+  int fd[2];
+
+  fd[0] = -1;
+  fd[1] = -1;
+  ASSERT (pipe (fd) >= 0);
+  ASSERT (fd[0] >= 0);
+  ASSERT (fd[1] >= 0);
+  ASSERT (fd[0] != fd[1]);
+  ASSERT (is_open (fd[0]));
+  ASSERT (is_open (fd[1]));
+  ASSERT (!is_cloexec (fd[0]));
+  ASSERT (!is_cloexec (fd[1]));
+  ASSERT (!is_nonblocking (fd[0]));
+  ASSERT (!is_nonblocking (fd[1]));
+
+  return 0;
+}
diff --git a/gl/tests/test-recv.c b/gl/tests/test-recv.c
new file mode 100644
index 0000000..ae811b6
--- /dev/null
+++ b/gl/tests/test-recv.c
@@ -0,0 +1,49 @@
+/* Test the recv() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (recv, ssize_t, (int, void *, size_t, int));
+
+#include <errno.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    char byte;
+    errno = 0;
+    ASSERT (recv (-1, &byte, 1, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    char byte;
+    errno = 0;
+    ASSERT (recv (99, &byte, 1, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-recvfrom.c b/gl/tests/test-recvfrom.c
new file mode 100644
index 0000000..069b9cf
--- /dev/null
+++ b/gl/tests/test-recvfrom.c
@@ -0,0 +1,60 @@
+/* Test the recvfrom() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (recvfrom, ssize_t,
+                 (int, void *, size_t, int,
+                  struct sockaddr *, socklen_t *));
+
+#include <errno.h>
+#include <netinet/in.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    char byte;
+    struct sockaddr_in addr;
+    socklen_t addrlen = sizeof (addr);
+
+    errno = 0;
+    ASSERT (recvfrom (-1, &byte, 1, 0, (struct sockaddr *) &addr, &addrlen)
+            == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    char byte;
+    struct sockaddr_in addr;
+    socklen_t addrlen = sizeof (addr);
+
+    errno = 0;
+    ASSERT (recvfrom (99, &byte, 1, 0, (struct sockaddr *) &addr, &addrlen)
+            == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-select-fd.c b/gl/tests/test-select-fd.c
new file mode 100644
index 0000000..de2f3e9
--- /dev/null
+++ b/gl/tests/test-select-fd.c
@@ -0,0 +1,72 @@
+/* Test of select() substitute, reading or writing from a given file 
descriptor.
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2008.  */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/select.h>
+
+int
+main (int argc, char *argv[])
+{
+  if (argc == 4)
+    {
+      char mode = argv[1][0];
+
+      if (mode == 'r' || mode == 'w')
+        {
+          int fd = atoi (argv[2]);
+
+          if (fd >= 0)
+            {
+              const char *result_file_name = argv[3];
+              FILE *result_file = fopen (result_file_name, "wb");
+
+              if (result_file != NULL)
+                {
+                  fd_set fds;
+                  struct timeval timeout;
+                  int ret;
+
+                  FD_ZERO (&fds);
+                  FD_SET (fd, &fds);
+                  timeout.tv_sec = 0;
+                  timeout.tv_usec = 10000;
+                  ret = (mode == 'r'
+                         ? select (fd + 1, &fds, NULL, NULL, &timeout)
+                         : select (fd + 1, NULL, &fds, NULL, &timeout));
+                  if (ret < 0)
+                    {
+                      perror ("select failed");
+                      exit (1);
+                    }
+                  if ((ret == 0) != ! FD_ISSET (fd, &fds))
+                    {
+                      fprintf (stderr, "incorrect return value\n");
+                      exit (1);
+                    }
+                  fprintf (result_file, "%d\n", ret);
+                  exit (0);
+                }
+            }
+        }
+    }
+  fprintf (stderr, "Usage: test-select-fd mode fd result-file-name\n");
+  exit (1);
+}
diff --git a/gl/tests/test-select-in.sh b/gl/tests/test-select-in.sh
new file mode 100755
index 0000000..2a8b742
--- /dev/null
+++ b/gl/tests/test-select-in.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# Test select() on file descriptors opened for reading.
+
+# This test is known to fail on Solaris 2.6 and older, due to its handling
+# of /dev/null.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles t-select-in.tmp"
+
+# Regular files.
+
+rm -f t-select-in.tmp
+./test-select-fd${EXEEXT} r 0 t-select-in.tmp < ./test-select-fd${EXEEXT}
+test `cat t-select-in.tmp` = "1" || exit 1
+
+# Pipes.
+
+rm -f t-select-in.tmp
+{ sleep 1; echo abc; } | \
+  { ./test-select-fd${EXEEXT} r 0 t-select-in.tmp; cat > /dev/null; }
+test `cat t-select-in.tmp` = "0" || exit 1
+
+rm -f t-select-in.tmp
+echo abc | { sleep 1; ./test-select-fd${EXEEXT} r 0 t-select-in.tmp; }
+test `cat t-select-in.tmp` = "1" || exit 1
+
+# Special files.
+# This part of the test is known to fail on Solaris 2.6 and older.
+
+# Doesn't work under mingw -- address@hidden
+#rm -f t-select-in.tmp
+#./test-select-fd${EXEEXT} r 0 t-select-in.tmp < /dev/null
+#test `cat t-select-in.tmp` = "1" || exit 1
+
+rm -fr $tmpfiles
+
+exit 0
diff --git a/gl/tests/test-select-out.sh b/gl/tests/test-select-out.sh
new file mode 100755
index 0000000..c5fd861
--- /dev/null
+++ b/gl/tests/test-select-out.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+# Test select() on file descriptors opened for writing.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles t-select-out.out t-select-out.tmp"
+
+# Regular files.
+
+rm -f t-select-out.tmp
+./test-select-fd${EXEEXT} w 1 t-select-out.tmp > t-select-out.out
+test `cat t-select-out.tmp` = "1" || exit 1
+
+# Pipes.
+
+if false; then # This test fails on some platforms.
+  rm -f t-select-out.tmp
+  ( { echo abc; ./test-select-fd${EXEEXT} w 1 t-select-out.tmp; } | { sleep 1; 
cat; } ) > /dev/null
+  test `cat t-select-out.tmp` = "0" || exit 1
+fi
+
+rm -f t-select-out.tmp
+( { sleep 1; echo abc; ./test-select-fd${EXEEXT} w 1 t-select-out.tmp; } | 
cat) > /dev/null
+test `cat t-select-out.tmp` = "1" || exit 1
+
+# Special files.
+
+rm -f t-select-out.tmp
+./test-select-fd${EXEEXT} w 1 t-select-out.tmp > /dev/null
+test `cat t-select-out.tmp` = "1" || exit 1
+
+rm -fr $tmpfiles
+
+exit 0
diff --git a/gl/tests/test-select-stdin.c b/gl/tests/test-select-stdin.c
new file mode 100644
index 0000000..5a6f81a
--- /dev/null
+++ b/gl/tests/test-select-stdin.c
@@ -0,0 +1,83 @@
+/* Test of select() substitute, reading from stdin.
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2008.  */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <unistd.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  printf ("Applying select() from standard input. Press Ctrl-C to abort.\n");
+  for (;;)
+    {
+      struct timeval before;
+      struct timeval after;
+      unsigned long spent_usec;
+      fd_set readfds;
+      struct timeval timeout;
+      int ret;
+
+      gettimeofday (&before, NULL);
+
+      FD_ZERO (&readfds);
+      FD_SET (0, &readfds);
+      timeout.tv_sec = 0;
+      timeout.tv_usec = 500000;
+      ret = select (1, &readfds, NULL, NULL, &timeout);
+
+      gettimeofday (&after, NULL);
+      spent_usec = (after.tv_sec - before.tv_sec) * 1000000
+                   + after.tv_usec - before.tv_usec;
+
+      if (ret < 0)
+        {
+          perror ("select failed");
+          exit (1);
+        }
+      if ((ret == 0) != ! FD_ISSET (0, &readfds))
+        {
+          fprintf (stderr, "incorrect return value\n");
+          exit (1);
+        }
+      if (ret == 0)
+        {
+          if (spent_usec < 250000)
+            {
+              fprintf (stderr, "returned too early\n");
+              exit (1);
+            }
+          /* Timeout */
+          printf (".");
+          ASSERT (fflush (stdout) == 0);
+        }
+      else
+        {
+          char c;
+
+          printf ("Input available! Trying to read 1 byte...\n");
+          ASSERT (read (0, &c, 1) == 1);
+        }
+    }
+}
diff --git a/gl/tests/test-select.c b/gl/tests/test-select.c
new file mode 100644
index 0000000..9c6fb9d
--- /dev/null
+++ b/gl/tests/test-select.c
@@ -0,0 +1,34 @@
+/* Test of select() substitute.
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini, 2008.  */
+
+#include <config.h>
+
+#include <sys/select.h>
+
+#include "signature.h"
+
+SIGNATURE_CHECK (select, int, (int, fd_set *, fd_set *, fd_set *,
+                               struct timeval *));
+
+#include "test-select.h"
+
+int
+main (void)
+{
+  return test_function (select);
+}
diff --git a/gl/tests/test-select.h b/gl/tests/test-select.h
new file mode 100644
index 0000000..4612dfc
--- /dev/null
+++ b/gl/tests/test-select.h
@@ -0,0 +1,436 @@
+/* Test of select() substitute.
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini, 2008.  */
+
+#include <stdio.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+
+#include "macros.h"
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# define WIN32_NATIVE
+#endif
+
+#ifdef HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+
+#ifndef SO_REUSEPORT
+# define SO_REUSEPORT    SO_REUSEADDR
+#endif
+
+#define TEST_PORT       12345
+
+
+typedef int (*select_fn) (int, fd_set *, fd_set *, fd_set *, struct timeval *);
+
+
+/* Minimal testing infrastructure.  */
+
+static int failures;
+
+static void
+failed (const char *reason)
+{
+  if (++failures > 1)
+    printf ("  ");
+  printf ("failed (%s)\n", reason);
+}
+
+static int
+test (void (*fn) (select_fn), select_fn my_select, const char *msg)
+{
+  failures = 0;
+  printf ("%s... ", msg);
+  fflush (stdout);
+  fn (my_select);
+
+  if (!failures)
+    printf ("passed\n");
+
+  return failures;
+}
+
+
+/* Funny socket code.  */
+
+static int
+open_server_socket (void)
+{
+  int s, x;
+  struct sockaddr_in ia;
+
+  s = socket (AF_INET, SOCK_STREAM, 0);
+
+  memset (&ia, 0, sizeof (ia));
+  ia.sin_family = AF_INET;
+  inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr);
+  ia.sin_port = htons (TEST_PORT);
+  if (bind (s, (struct sockaddr *) &ia, sizeof (ia)) < 0)
+    {
+      perror ("bind");
+      exit (77);
+    }
+
+  x = 1;
+  setsockopt (s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof (x));
+
+  if (listen (s, 1) < 0)
+    {
+      perror ("listen");
+      exit (77);
+    }
+
+  return s;
+}
+
+static int
+connect_to_socket (bool blocking)
+{
+  int s;
+  struct sockaddr_in ia;
+
+  s = socket (AF_INET, SOCK_STREAM, 0);
+
+  memset (&ia, 0, sizeof (ia));
+  ia.sin_family = AF_INET;
+  inet_pton (AF_INET, "127.0.0.1", &ia.sin_addr);
+  ia.sin_port = htons (TEST_PORT);
+
+  if (!blocking)
+    {
+#ifdef WIN32_NATIVE
+      unsigned long iMode = 1;
+      ioctl (s, FIONBIO, (char *) &iMode);
+
+#elif defined F_GETFL
+      int oldflags = fcntl (s, F_GETFL, NULL);
+
+      if (!(oldflags & O_NONBLOCK))
+        fcntl (s, F_SETFL, oldflags | O_NONBLOCK);
+#endif
+    }
+
+  if (connect (s, (struct sockaddr *) &ia, sizeof (ia)) < 0
+      && (blocking || errno != EINPROGRESS))
+    {
+      perror ("connect");
+      exit (77);
+    }
+
+  return s;
+}
+
+
+/* A slightly more convenient interface to select(2).
+   Waits until a specific event occurs on a file descriptor FD.
+   EV is a bit mask of events to look for:
+     SEL_IN - input can be polled without blocking,
+     SEL_OUT - output can be provided without blocking,
+     SEL_EXC - an exception occurred,
+   A maximum wait time is specified by TIMEOUT.
+   *TIMEOUT = { 0, 0 } means to return immediately,
+   TIMEOUT = NULL means to wait indefinitely.  */
+
+enum { SEL_IN = 1, SEL_OUT = 2, SEL_EXC = 4 };
+
+static int
+do_select (int fd, int ev, struct timeval *timeout, select_fn my_select)
+{
+  fd_set rfds, wfds, xfds;
+  int r, rev;
+
+  FD_ZERO (&rfds);
+  FD_ZERO (&wfds);
+  FD_ZERO (&xfds);
+  if (ev & SEL_IN)
+    FD_SET (fd, &rfds);
+  if (ev & SEL_OUT)
+    FD_SET (fd, &wfds);
+  if (ev & SEL_EXC)
+    FD_SET (fd, &xfds);
+  r = my_select (fd + 1, &rfds, &wfds, &xfds, timeout);
+  if (r < 0)
+    return r;
+
+  rev = 0;
+  if (FD_ISSET (fd, &rfds))
+    rev |= SEL_IN;
+  if (FD_ISSET (fd, &wfds))
+    rev |= SEL_OUT;
+  if (FD_ISSET (fd, &xfds))
+    rev |= SEL_EXC;
+  if (rev && r == 0)
+    failed ("select returned 0");
+  if (rev & ~ev)
+    failed ("select returned unrequested events");
+
+  return rev;
+}
+
+static int
+do_select_nowait (int fd, int ev, select_fn my_select)
+{
+  struct timeval tv0;
+  tv0.tv_sec = 0;
+  tv0.tv_usec = 0;
+  return do_select (fd, ev, &tv0, my_select);
+}
+
+static int
+do_select_wait (int fd, int ev, select_fn my_select)
+{
+  return do_select (fd, ev, NULL, my_select);
+}
+
+
+/* Test select(2) for TTYs.  */
+
+#ifdef INTERACTIVE
+static void
+test_tty (select_fn my_select)
+{
+  if (do_select_nowait (0, SEL_IN, my_select) != 0)
+    failed ("can read");
+  if (do_select_nowait (0, SEL_OUT, my_select) == 0)
+    failed ("cannot write");
+
+  if (do_select_wait (0, SEL_IN, my_select) == 0)
+    failed ("return with infinite timeout");
+
+  getchar ();
+  if (do_select_nowait (0, SEL_IN, my_select) != 0)
+    failed ("can read after getc");
+}
+#endif
+
+
+/* Test select(2) on invalid file descriptors.  */
+
+static int
+do_select_bad_fd (int fd, int ev, struct timeval *timeout, select_fn my_select)
+{
+  fd_set rfds, wfds, xfds;
+
+  FD_ZERO (&rfds);
+  FD_ZERO (&wfds);
+  FD_ZERO (&xfds);
+  if (ev & SEL_IN)
+    FD_SET (fd, &rfds);
+  if (ev & SEL_OUT)
+    FD_SET (fd, &wfds);
+  if (ev & SEL_EXC)
+    FD_SET (fd, &xfds);
+  return my_select (fd + 1, &rfds, &wfds, &xfds, timeout);
+  /* In this case, when fd is invalid, on some platforms, the bit for fd
+     is left alone in the fd_set, whereas on other platforms it is cleared.
+     So, don't check the bit for fd here.  */
+}
+
+static int
+do_select_bad_fd_nowait (int fd, int ev, select_fn my_select)
+{
+  struct timeval tv0;
+  tv0.tv_sec = 0;
+  tv0.tv_usec = 0;
+  return do_select_bad_fd (fd, ev, &tv0, my_select);
+}
+
+static void
+test_bad_fd (select_fn my_select)
+{
+  /* This tests fails on OSF/1 and native Windows, even with fd = 16.  */
+#if !(defined __osf__ || defined WIN32_NATIVE)
+  int fd;
+
+  /* On Linux, MacOS X, *BSD, values of fd like 99 or 399 are discarded
+     by the kernel early and therefore do *not* lead to EBADF, as required
+     by POSIX.  */
+# if defined __linux__ || (defined __APPLE__ && defined __MACH__) || defined 
__FreeBSD__ || defined __OpenBSD__ || defined __NetBSD__
+  fd = 16;
+# else
+  fd = 99;
+# endif
+
+  if (do_select_bad_fd_nowait (fd, SEL_IN, my_select) == 0 || errno != EBADF)
+    failed ("invalid fd among rfds");
+  if (do_select_bad_fd_nowait (fd, SEL_OUT, my_select) == 0 || errno != EBADF)
+    failed ("invalid fd among wfds");
+  if (do_select_bad_fd_nowait (fd, SEL_EXC, my_select) == 0 || errno != EBADF)
+    failed ("invalid fd among xfds");
+#endif
+}
+
+
+/* Test select(2) for unconnected nonblocking sockets.  */
+
+static void
+test_connect_first (select_fn my_select)
+{
+  int s = open_server_socket ();
+  struct sockaddr_in ia;
+  socklen_t addrlen;
+
+  int c1, c2;
+
+  if (do_select_nowait (s, SEL_IN | SEL_EXC, my_select) != 0)
+    failed ("can read, socket not connected");
+
+  c1 = connect_to_socket (false);
+
+  if (do_select_wait (s, SEL_IN | SEL_EXC, my_select) != SEL_IN)
+    failed ("expecting readability on passive socket");
+  if (do_select_nowait (s, SEL_IN | SEL_EXC, my_select) != SEL_IN)
+    failed ("expecting readability on passive socket");
+
+  addrlen = sizeof (ia);
+  c2 = accept (s, (struct sockaddr *) &ia, &addrlen);
+  ASSERT (close (s) == 0);
+  ASSERT (close (c1) == 0);
+  ASSERT (close (c2) == 0);
+}
+
+
+/* Test select(2) for unconnected blocking sockets.  */
+
+static void
+test_accept_first (select_fn my_select)
+{
+#ifndef WIN32_NATIVE
+  int s = open_server_socket ();
+  struct sockaddr_in ia;
+  socklen_t addrlen;
+  char buf[3];
+  int c, pid;
+
+  pid = fork ();
+  if (pid < 0)
+    return;
+
+  if (pid == 0)
+    {
+      addrlen = sizeof (ia);
+      c = accept (s, (struct sockaddr *) &ia, &addrlen);
+      ASSERT (close (s) == 0);
+      ASSERT (write (c, "foo", 3) == 3);
+      ASSERT (read (c, buf, 3) == 3);
+      shutdown (c, SHUT_RD);
+      ASSERT (close (c) == 0);
+      exit (0);
+    }
+  else
+    {
+      ASSERT (close (s) == 0);
+      c = connect_to_socket (true);
+      if (do_select_nowait (c, SEL_OUT, my_select) != SEL_OUT)
+        failed ("cannot write after blocking connect");
+      ASSERT (write (c, "foo", 3) == 3);
+      wait (&pid);
+      if (do_select_wait (c, SEL_IN, my_select) != SEL_IN)
+        failed ("cannot read data left in the socket by closed process");
+      ASSERT (read (c, buf, 3) == 3);
+      ASSERT (write (c, "foo", 3) == 3);
+      (void) close (c); /* may fail with errno = ECONNRESET */
+    }
+#endif
+}
+
+
+/* Common code for pipes and connected sockets.  */
+
+static void
+test_pair (int rd, int wd, select_fn my_select)
+{
+  char buf[3];
+  if (do_select_wait (wd, SEL_IN | SEL_OUT | SEL_EXC, my_select) != SEL_OUT)
+    failed ("expecting writability before writing");
+  if (do_select_nowait (wd, SEL_IN | SEL_OUT | SEL_EXC, my_select) != SEL_OUT)
+    failed ("expecting writability before writing");
+
+  ASSERT (write (wd, "foo", 3) == 3);
+  if (do_select_wait (rd, SEL_IN, my_select) != SEL_IN)
+    failed ("expecting readability after writing");
+  if (do_select_nowait (rd, SEL_IN, my_select) != SEL_IN)
+    failed ("expecting readability after writing");
+
+  ASSERT (read (rd, buf, 3) == 3);
+}
+
+
+/* Test select(2) on connected sockets.  */
+
+static void
+test_socket_pair (select_fn my_select)
+{
+  struct sockaddr_in ia;
+
+  socklen_t addrlen = sizeof (ia);
+  int s = open_server_socket ();
+  int c1 = connect_to_socket (false);
+  int c2 = accept (s, (struct sockaddr *) &ia, &addrlen);
+
+  ASSERT (close (s) == 0);
+
+  test_pair (c1, c2, my_select);
+  ASSERT (close (c1) == 0);
+  ASSERT (write (c2, "foo", 3) == 3);
+  (void) close (c2); /* may fail with errno = ECONNRESET */
+}
+
+
+/* Test select(2) on pipes.  */
+
+static void
+test_pipe (select_fn my_select)
+{
+  int fd[2];
+
+  ASSERT (pipe (fd) == 0);
+  test_pair (fd[0], fd[1], my_select);
+  ASSERT (close (fd[0]) == 0);
+  ASSERT (close (fd[1]) == 0);
+}
+
+
+/* Do them all.  */
+
+static int
+test_function (select_fn my_select)
+{
+  int result = 0;
+
+#ifdef INTERACTIVE
+  printf ("Please press Enter\n");
+  test (test_tty, "TTY", my_select);
+#endif
+
+  result += test (test_bad_fd, my_select, "Invalid fd test");
+  result += test (test_connect_first, my_select, "Unconnected socket test");
+  result += test (test_socket_pair, my_select, "Connected sockets test");
+  result += test (test_accept_first, my_select, "General socket test with 
fork");
+  result += test (test_pipe, my_select, "Pipe test");
+
+  return result;
+}
diff --git a/gl/tests/test-send.c b/gl/tests/test-send.c
new file mode 100644
index 0000000..9fb24d4
--- /dev/null
+++ b/gl/tests/test-send.c
@@ -0,0 +1,49 @@
+/* Test the send() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (send, ssize_t, (int, const void *, size_t, int));
+
+#include <errno.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    char byte = 'x';
+    errno = 0;
+    ASSERT (send (-1, &byte, 1, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    char byte = 'x';
+    errno = 0;
+    ASSERT (send (99, &byte, 1, 0) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-sendto.c b/gl/tests/test-sendto.c
new file mode 100644
index 0000000..9e8a519
--- /dev/null
+++ b/gl/tests/test-sendto.c
@@ -0,0 +1,64 @@
+/* Test the sendto() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (sendto, ssize_t,
+                 (int, const void *, size_t, int,
+                  const struct sockaddr *, socklen_t));
+
+#include <errno.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    struct sockaddr_in addr;
+
+    addr.sin_family = AF_INET;
+    inet_pton (AF_INET, "127.0.0.1", &addr.sin_addr);
+    addr.sin_port = htons (80);
+    {
+      char byte = 'x';
+      errno = 0;
+      ASSERT (sendto (-1, &byte, 1, 0,
+                      (const struct sockaddr *) &addr, sizeof (addr))
+              == -1);
+      ASSERT (errno == EBADF);
+    }
+    {
+      char byte = 'x';
+      errno = 0;
+      ASSERT (sendto (99, &byte, 1, 0,
+                      (const struct sockaddr *) &addr, sizeof (addr))
+              == -1);
+      ASSERT (errno == EBADF);
+    }
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-setsockopt.c b/gl/tests/test-setsockopt.c
new file mode 100644
index 0000000..7a16cfa
--- /dev/null
+++ b/gl/tests/test-setsockopt.c
@@ -0,0 +1,53 @@
+/* Test setsockopt() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (setsockopt, int, (int, int, int, const void *, socklen_t));
+
+#include <errno.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    int value = 1;
+
+    errno = 0;
+    ASSERT (setsockopt (-1, SOL_SOCKET, SO_REUSEADDR, &value, sizeof (value))
+            == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    int value = 1;
+
+    errno = 0;
+    ASSERT (setsockopt (99, SOL_SOCKET, SO_REUSEADDR, &value, sizeof (value))
+            == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-shutdown.c b/gl/tests/test-shutdown.c
new file mode 100644
index 0000000..d154f8e
--- /dev/null
+++ b/gl/tests/test-shutdown.c
@@ -0,0 +1,47 @@
+/* Test the shutdown() function.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+#include <sys/socket.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (shutdown, int, (int, int));
+
+#include <errno.h>
+
+#include "sockets.h"
+#include "macros.h"
+
+int
+main (void)
+{
+  gl_sockets_startup (SOCKETS_1_1);
+
+  /* Test behaviour for invalid file descriptors.  */
+  {
+    errno = 0;
+    ASSERT (shutdown (-1, SHUT_RD) == -1);
+    ASSERT (errno == EBADF);
+  }
+  {
+    errno = 0;
+    ASSERT (shutdown (99, SHUT_RD) == -1);
+    ASSERT (errno == EBADF);
+  }
+
+  return 0;
+}
diff --git a/gl/tests/test-signal-h.c b/gl/tests/test-signal-h.c
new file mode 100644
index 0000000..7103e1f
--- /dev/null
+++ b/gl/tests/test-signal-h.c
@@ -0,0 +1,129 @@
+/* Test of <signal.h> substitute.
+   Copyright (C) 2009-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Eric Blake <address@hidden>, 2009.  */
+
+#include <config.h>
+
+#include <signal.h>
+
+/* Check for required types.  */
+struct
+{
+  size_t a;
+  uid_t b;
+  volatile sig_atomic_t c;
+  sigset_t d;
+  pid_t e;
+#if 0
+  /* Not guaranteed by gnulib.  */
+  pthread_t f;
+  struct timespec g;
+#endif
+} s;
+
+/* Check that NSIG is defined.  */
+int nsig = NSIG;
+
+int
+main (void)
+{
+  switch (0)
+    {
+      /* The following are guaranteed by C.  */
+    case 0:
+    case SIGABRT:
+    case SIGFPE:
+    case SIGILL:
+    case SIGINT:
+    case SIGSEGV:
+    case SIGTERM:
+      /* The following is guaranteed by gnulib.  */
+#if GNULIB_SIGPIPE || defined SIGPIPE
+    case SIGPIPE:
+#endif
+      /* Ensure no conflict with other standardized names.  */
+#ifdef SIGALRM
+    case SIGALRM:
+#endif
+      /* On Haiku, SIGBUS is mistakenly equal to SIGSEGV.  */
+#if defined SIGBUS && SIGBUS != SIGSEGV
+    case SIGBUS:
+#endif
+#ifdef SIGCHLD
+    case SIGCHLD:
+#endif
+#ifdef SIGCONT
+    case SIGCONT:
+#endif
+#ifdef SIGHUP
+    case SIGHUP:
+#endif
+#ifdef SIGKILL
+    case SIGKILL:
+#endif
+#ifdef SIGQUIT
+    case SIGQUIT:
+#endif
+#ifdef SIGSTOP
+    case SIGSTOP:
+#endif
+#ifdef SIGTSTP
+    case SIGTSTP:
+#endif
+#ifdef SIGTTIN
+    case SIGTTIN:
+#endif
+#ifdef SIGTTOU
+    case SIGTTOU:
+#endif
+#ifdef SIGUSR1
+    case SIGUSR1:
+#endif
+#ifdef SIGUSR2
+    case SIGUSR2:
+#endif
+#ifdef SIGSYS
+    case SIGSYS:
+#endif
+#ifdef SIGTRAP
+    case SIGTRAP:
+#endif
+#ifdef SIGURG
+    case SIGURG:
+#endif
+#ifdef SIGVTALRM
+    case SIGVTALRM:
+#endif
+#ifdef SIGXCPU
+    case SIGXCPU:
+#endif
+#ifdef SIGXFSZ
+    case SIGXFSZ:
+#endif
+      /* SIGRTMIN and SIGRTMAX need not be compile-time constants.  */
+#if 0
+# ifdef SIGRTMIN
+    case SIGRTMIN:
+# endif
+# ifdef SIGRTMAX
+    case SIGRTMAX:
+# endif
+#endif
+      ;
+    }
+  return s.a + s.b + s.c + s.e;
+}
diff --git a/gl/tests/test-stdalign.c b/gl/tests/test-stdalign.c
new file mode 100644
index 0000000..7090a26
--- /dev/null
+++ b/gl/tests/test-stdalign.c
@@ -0,0 +1,116 @@
+/* Test of <stdalign.h>.
+   Copyright 2009-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paul Eggert, inspired by Bruno Haible's test-alignof.c.  */
+
+#include <config.h>
+
+#include <stdalign.h>
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "verify.h"
+
+#include "macros.h"
+
+typedef long double longdouble;
+typedef struct { char a[1]; } struct1;
+typedef struct { char a[2]; } struct2;
+typedef struct { char a[3]; } struct3;
+typedef struct { char a[4]; } struct4;
+
+verify (__alignof_is_defined == 1);
+#ifndef alignof
+# error "alignof is not a macro"
+#endif
+
+#if __alignas_is_defined
+verify (__alignas_is_defined == 1);
+# ifndef alignas
+#  error "alignas is not a macro"
+# endif
+/* mingw can go up only to 8.  8 is all that GNU Emacs needs, so let's
+   limit the test to 8 for now.  */
+# define TEST_ALIGNMENT 8
+#else
+# define _Alignas(alignment)
+# define alignas(alignment)
+# define TEST_ALIGNMENT 1
+#endif
+
+#define CHECK_STATIC(type) \
+  typedef struct { char slot1; type slot2; } type##_helper; \
+  verify (alignof (type) == offsetof (type##_helper, slot2)); \
+  verify (_Alignof (type) == alignof (type)); \
+  const int type##_alignment = alignof (type); \
+  type alignas (TEST_ALIGNMENT) static_##type##_alignas; \
+  type _Alignas (TEST_ALIGNMENT) static_##type##_Alignas
+
+#define CHECK_ALIGNED(var) ASSERT ((uintptr_t) &(var) % TEST_ALIGNMENT == 0)
+
+CHECK_STATIC (char);
+CHECK_STATIC (short);
+CHECK_STATIC (int);
+CHECK_STATIC (long);
+#ifdef INT64_MAX
+CHECK_STATIC (int64_t);
+#endif
+CHECK_STATIC (float);
+CHECK_STATIC (double);
+CHECK_STATIC (longdouble);
+CHECK_STATIC (struct1);
+CHECK_STATIC (struct2);
+CHECK_STATIC (struct3);
+CHECK_STATIC (struct4);
+
+int
+main ()
+{
+#if defined __SUNPRO_C
+  /* Avoid a test failure due to Sun Studio Developer Bug Report #2125432.  */
+  fputs ("Skipping test: known Sun C compiler bug\n", stderr);
+  return 77;
+#else
+  CHECK_ALIGNED (static_char_alignas);
+  CHECK_ALIGNED (static_char_Alignas);
+  CHECK_ALIGNED (static_short_alignas);
+  CHECK_ALIGNED (static_short_Alignas);
+  CHECK_ALIGNED (static_int_alignas);
+  CHECK_ALIGNED (static_int_Alignas);
+  CHECK_ALIGNED (static_long_alignas);
+  CHECK_ALIGNED (static_long_Alignas);
+# ifdef INT64_MAX
+  CHECK_ALIGNED (static_int64_t_alignas);
+  CHECK_ALIGNED (static_int64_t_Alignas);
+# endif
+  CHECK_ALIGNED (static_float_alignas);
+  CHECK_ALIGNED (static_float_Alignas);
+  CHECK_ALIGNED (static_double_alignas);
+  CHECK_ALIGNED (static_double_Alignas);
+  CHECK_ALIGNED (static_longdouble_alignas);
+  CHECK_ALIGNED (static_longdouble_Alignas);
+  CHECK_ALIGNED (static_struct1_alignas);
+  CHECK_ALIGNED (static_struct1_Alignas);
+  CHECK_ALIGNED (static_struct2_alignas);
+  CHECK_ALIGNED (static_struct2_Alignas);
+  CHECK_ALIGNED (static_struct3_alignas);
+  CHECK_ALIGNED (static_struct3_Alignas);
+  CHECK_ALIGNED (static_struct4_alignas);
+  CHECK_ALIGNED (static_struct4_Alignas);
+  return 0;
+#endif
+}
diff --git a/gl/tests/test-strerror_r.c b/gl/tests/test-strerror_r.c
new file mode 100644
index 0000000..956c458
--- /dev/null
+++ b/gl/tests/test-strerror_r.c
@@ -0,0 +1,182 @@
+/* Test of strerror_r() function.
+   Copyright (C) 2007-2011 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+#include <string.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (strerror_r, int, (int, char *, size_t));
+
+#include <errno.h>
+
+#include "macros.h"
+
+int
+main (void)
+{
+  char buf[100];
+  int ret;
+
+  /* Test results with valid errnum and enough room.  */
+
+  errno = 0;
+  buf[0] = '\0';
+  ASSERT (strerror_r (EACCES, buf, sizeof buf) == 0);
+  ASSERT (buf[0] != '\0');
+  ASSERT (errno == 0);
+  ASSERT (strlen (buf) < sizeof buf);
+
+  errno = 0;
+  buf[0] = '\0';
+  ASSERT (strerror_r (ETIMEDOUT, buf, sizeof buf) == 0);
+  ASSERT (buf[0] != '\0');
+  ASSERT (errno == 0);
+  ASSERT (strlen (buf) < sizeof buf);
+
+  errno = 0;
+  buf[0] = '\0';
+  ASSERT (strerror_r (EOVERFLOW, buf, sizeof buf) == 0);
+  ASSERT (buf[0] != '\0');
+  ASSERT (errno == 0);
+  ASSERT (strlen (buf) < sizeof buf);
+
+  /* POSIX requires strerror (0) to succeed.  Reject use of "Unknown
+     error", but allow "Success", "No error", or even Solaris' "Error
+     0" which are distinct patterns from true out-of-range strings.
+     http://austingroupbugs.net/view.php?id=382  */
+  errno = 0;
+  buf[0] = '\0';
+  ret = strerror_r (0, buf, sizeof buf);
+  ASSERT (ret == 0);
+  ASSERT (buf[0]);
+  ASSERT (errno == 0);
+  ASSERT (strstr (buf, "nknown") == NULL);
+  ASSERT (strstr (buf, "ndefined") == NULL);
+
+  /* Test results with out-of-range errnum and enough room.  POSIX
+     allows an empty string on success, and allows an unchanged buf on
+     error, but these are not useful, so we guarantee contents.  */
+  errno = 0;
+  buf[0] = '^';
+  ret = strerror_r (-3, buf, sizeof buf);
+  ASSERT (ret == 0 || ret == EINVAL);
+  ASSERT (buf[0] != '^');
+  ASSERT (*buf);
+  ASSERT (errno == 0);
+  ASSERT (strlen (buf) < sizeof buf);
+
+  /* Test results with a too small buffer.  POSIX requires an error;
+     only ERANGE for 0 and valid errors, and a choice of ERANGE or
+     EINVAL for out-of-range values.  On error, POSIX permits buf to
+     be empty, unchanged, or unterminated, but these are not useful,
+     so we guarantee NUL-terminated truncated contents for all but
+     size 0.  http://austingroupbugs.net/view.php?id=398.  Also ensure
+     that no out-of-bounds writes occur.  */
+  {
+    int errs[] = { EACCES, 0, -3, };
+    int j;
+
+    buf[sizeof buf - 1] = '\0';
+    for (j = 0; j < SIZEOF (errs); j++)
+      {
+        int err = errs[j];
+        char buf2[sizeof buf] = "";
+        size_t len;
+        size_t i;
+
+        strerror_r (err, buf2, sizeof buf2);
+        len = strlen (buf2);
+        ASSERT (len < sizeof buf);
+
+        for (i = 0; i <= len; i++)
+          {
+            memset (buf, '^', sizeof buf - 1);
+            errno = 0;
+            ret = strerror_r (err, buf, i);
+            ASSERT (errno == 0);
+            if (err < 0)
+              ASSERT (ret == ERANGE || ret == EINVAL);
+            else
+              ASSERT (ret == ERANGE);
+            if (i)
+              {
+                ASSERT (strncmp (buf, buf2, i - 1) == 0);
+                ASSERT (buf[i - 1] == '\0');
+              }
+            ASSERT (strspn (buf + i, "^") == sizeof buf - 1 - i);
+          }
+
+        strcpy (buf, "BADFACE");
+        errno = 0;
+        ret = strerror_r (err, buf, len + 1);
+        ASSERT (ret != ERANGE);
+        ASSERT (errno == 0);
+        ASSERT (strcmp (buf, buf2) == 0);
+      }
+  }
+
+#if GNULIB_STRERROR
+  /* Test that strerror_r does not clobber strerror buffer.  On some
+     platforms, this test can only succeed if gnulib also replaces
+     strerror.  */
+  {
+    const char *msg1;
+    const char *msg2;
+    const char *msg3;
+    const char *msg4;
+    char *str1;
+    char *str2;
+    char *str3;
+    char *str4;
+
+    msg1 = strerror (ENOENT);
+    ASSERT (msg1);
+    str1 = strdup (msg1);
+    ASSERT (str1);
+
+    msg2 = strerror (ERANGE);
+    ASSERT (msg2);
+    str2 = strdup (msg2);
+    ASSERT (str2);
+
+    msg3 = strerror (-4);
+    ASSERT (msg3);
+    str3 = strdup (msg3);
+    ASSERT (str3);
+
+    msg4 = strerror (1729576);
+    ASSERT (msg4);
+    str4 = strdup (msg4);
+    ASSERT (str4);
+
+    strerror_r (EACCES, buf, sizeof buf);
+    strerror_r (-5, buf, sizeof buf);
+    ASSERT (msg1 == msg2 || msg1 == msg4 || STREQ (msg1, str1));
+    ASSERT (msg2 == msg4 || STREQ (msg2, str2));
+    ASSERT (msg3 == msg4 || STREQ (msg3, str3));
+    ASSERT (STREQ (msg4, str4));
+
+    free (str1);
+    free (str2);
+    free (str3);
+    free (str4);
+  }
+#endif
+
+  return 0;
+}
diff --git a/gl/tests/test-sys_ioctl.c b/gl/tests/test-sys_ioctl.c
new file mode 100644
index 0000000..dd01b4a
--- /dev/null
+++ b/gl/tests/test-sys_ioctl.c
@@ -0,0 +1,27 @@
+/* Test of <sys/ioctl.h> substitute.
+   Copyright (C) 2009-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Eric Blake <address@hidden>, 2009.  */
+
+#include <config.h>
+
+#include <sys/ioctl.h>
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gl/tests/test-sys_select.c b/gl/tests/test-sys_select.c
new file mode 100644
index 0000000..76596db
--- /dev/null
+++ b/gl/tests/test-sys_select.c
@@ -0,0 +1,55 @@
+/* Test of <sys/select.h> substitute.
+   Copyright (C) 2007-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2007.  */
+
+#include <config.h>
+
+#include <sys/select.h>
+
+#include "signature.h"
+
+/* The following may be macros without underlying functions, so only
+   check signature if they are not macros.  */
+#ifndef FD_CLR
+SIGNATURE_CHECK (FD_CLR, void, (int, fd_set *));
+#endif
+#ifndef FD_ISSET
+SIGNATURE_CHECK (FD_ISSET, void, (int, fd_set *));
+#endif
+#ifndef FD_SET
+SIGNATURE_CHECK (FD_SET, int, (int, fd_set *));
+#endif
+#ifndef FD_ZERO
+SIGNATURE_CHECK (FD_ZERO, void, (fd_set *));
+#endif
+
+/* Check that the 'struct timeval' type is defined.  */
+struct timeval t1;
+
+/* Check that sigset_t is defined.  */
+sigset_t t2;
+
+int
+main (void)
+{
+  /* Check that FD_ZERO can be used.  This should not yield a warning
+     such as "warning: implicit declaration of function 'memset'".  */
+  fd_set fds;
+  FD_ZERO (&fds);
+
+  return 0;
+}
diff --git a/gl/tests/test-thread_create.c b/gl/tests/test-thread_create.c
new file mode 100644
index 0000000..1348c8c
--- /dev/null
+++ b/gl/tests/test-thread_create.c
@@ -0,0 +1,78 @@
+/* Test of gl_thread_create () macro.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2011.  */
+
+#include <config.h>
+
+#include "glthread/thread.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include "macros.h"
+
+static gl_thread_t main_thread_before;
+static gl_thread_t main_thread_after;
+static gl_thread_t worker_thread;
+
+static int dummy;
+static volatile int work_done;
+
+static void *
+worker_thread_func (void *arg)
+{
+  work_done = 1;
+  return &dummy;
+}
+
+int
+main ()
+{
+  main_thread_before = gl_thread_self ();
+
+  if (glthread_create (&worker_thread, worker_thread_func, NULL) == 0)
+    {
+      void *ret;
+
+      /* Check that gl_thread_self () has the same value before than after the
+         first call to gl_thread_create ().  */
+      main_thread_after = gl_thread_self ();
+      ASSERT (memcmp (&main_thread_before, &main_thread_after,
+                      sizeof (gl_thread_t))
+              == 0);
+
+      gl_thread_join (worker_thread, &ret);
+
+      /* Check the return value of the thread.  */
+      ASSERT (ret == &dummy);
+
+      /* Check that worker_thread_func () has finished executing.  */
+      ASSERT (work_done);
+
+      return 0;
+    }
+  else
+    {
+#if USE_POSIX_THREADS || USE_SOLARIS_THREADS || USE_PTH_THREADS || 
USE_WIN32_THREADS
+      fputs ("glthread_create failed\n", stderr);
+      return 1;
+#else
+      fputs ("Skipping test: multithreading not enabled\n", stderr);
+      return 77;
+#endif
+    }
+}
diff --git a/gl/tests/test-thread_self.c b/gl/tests/test-thread_self.c
new file mode 100644
index 0000000..816ee09
--- /dev/null
+++ b/gl/tests/test-thread_self.c
@@ -0,0 +1,34 @@
+/* Test of gl_thread_self () macro.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <address@hidden>, 2011.  */
+
+#include <config.h>
+
+#include "glthread/thread.h"
+
+gl_thread_t main_thread;
+
+int
+main ()
+{
+  /* Check that gl_thread_self () can be used with just $(LIBTHREAD), not
+     $(LIBMULTITHREAD), i.e. in libraries that are multithread-safe but don't
+     create threads themselves.  */
+  main_thread = gl_thread_self ();
+
+  return 0;
+}
diff --git a/gl/tests/w32sock.h b/gl/tests/w32sock.h
new file mode 100644
index 0000000..0b8334e
--- /dev/null
+++ b/gl/tests/w32sock.h
@@ -0,0 +1,136 @@
+/* w32sock.h --- internal auxilliary functions for Windows socket functions
+
+   Copyright (C) 2008-2011 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Paolo Bonzini */
+
+#include <errno.h>
+
+/* Get O_RDWR and O_BINARY.  */
+#include <fcntl.h>
+
+/* Get _open_osfhandle().  */
+#include <io.h>
+
+/* Get _get_osfhandle().  */
+#include "msvc-nothrow.h"
+
+#define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
+#define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
+
+static inline void
+set_winsock_errno (void)
+{
+  int err = WSAGetLastError ();
+
+  /* Map some WSAE* errors to the runtime library's error codes.  */
+  switch (err)
+    {
+    case WSA_INVALID_HANDLE:
+      errno = EBADF;
+      break;
+    case WSA_NOT_ENOUGH_MEMORY:
+      errno = ENOMEM;
+      break;
+    case WSA_INVALID_PARAMETER:
+      errno = EINVAL;
+      break;
+    case WSAENAMETOOLONG:
+      errno = ENAMETOOLONG;
+      break;
+    case WSAENOTEMPTY:
+      errno = ENOTEMPTY;
+      break;
+    case WSAEWOULDBLOCK:
+      errno = EWOULDBLOCK;
+      break;
+    case WSAEINPROGRESS:
+      errno = EINPROGRESS;
+      break;
+    case WSAEALREADY:
+      errno = EALREADY;
+      break;
+    case WSAENOTSOCK:
+      errno = ENOTSOCK;
+      break;
+    case WSAEDESTADDRREQ:
+      errno = EDESTADDRREQ;
+      break;
+    case WSAEMSGSIZE:
+      errno = EMSGSIZE;
+      break;
+    case WSAEPROTOTYPE:
+      errno = EPROTOTYPE;
+      break;
+    case WSAENOPROTOOPT:
+      errno = ENOPROTOOPT;
+      break;
+    case WSAEPROTONOSUPPORT:
+      errno = EPROTONOSUPPORT;
+      break;
+    case WSAEOPNOTSUPP:
+      errno = EOPNOTSUPP;
+      break;
+    case WSAEAFNOSUPPORT:
+      errno = EAFNOSUPPORT;
+      break;
+    case WSAEADDRINUSE:
+      errno = EADDRINUSE;
+      break;
+    case WSAEADDRNOTAVAIL:
+      errno = EADDRNOTAVAIL;
+      break;
+    case WSAENETDOWN:
+      errno = ENETDOWN;
+      break;
+    case WSAENETUNREACH:
+      errno = ENETUNREACH;
+      break;
+    case WSAENETRESET:
+      errno = ENETRESET;
+      break;
+    case WSAECONNABORTED:
+      errno = ECONNABORTED;
+      break;
+    case WSAECONNRESET:
+      errno = ECONNRESET;
+      break;
+    case WSAENOBUFS:
+      errno = ENOBUFS;
+      break;
+    case WSAEISCONN:
+      errno = EISCONN;
+      break;
+    case WSAENOTCONN:
+      errno = ENOTCONN;
+      break;
+    case WSAETIMEDOUT:
+      errno = ETIMEDOUT;
+      break;
+    case WSAECONNREFUSED:
+      errno = ECONNREFUSED;
+      break;
+    case WSAELOOP:
+      errno = ELOOP;
+      break;
+    case WSAEHOSTUNREACH:
+      errno = EHOSTUNREACH;
+      break;
+    default:
+      errno = (err > 10000 && err < 10025) ? err - 10000 : err;
+      break;
+    }
+}
diff --git a/gl/unistd.in.h b/gl/unistd.in.h
index 7df1ed0..77e5675 100644
--- a/gl/unistd.in.h
+++ b/gl/unistd.in.h
@@ -83,11 +83,13 @@
 # include <stdlib.h>
 #endif
 
-/* mingw declares getcwd in <io.h>, not in <unistd.h>.  */
-#if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
+/* Native Windows platforms declare chdir, getcwd, rmdir in
+   <io.h> and/or <direct.h>, not in <unistd.h>.  */
+#if ((@GNULIB_CHDIR@ || @GNULIB_GETCWD@ || @GNULIB_RMDIR@ \
+      || defined GNULIB_POSIXCHECK) \
      && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
 # include <io.h>     /* mingw32, mingw64 */
-# include <direct.h> /* mingw64 */
+# include <direct.h> /* mingw64, MSVC 9 */
 #endif
 
 /* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.
@@ -231,6 +233,18 @@ _GL_WARN_ON_USE (access, "the access function is a 
security risk - "
 #endif
 
 
+#if @GNULIB_CHDIR@
+_GL_CXXALIAS_SYS (chdir, int, (const char *file) _GL_ARG_NONNULL ((1)));
+_GL_CXXALIASWARN (chdir);
+#elif defined GNULIB_POSIXCHECK
+# undef chdir
+# if HAVE_RAW_DECL_CHDIR
+_GL_WARN_ON_USE (chown, "chdir is not always in <unistd.h> - "
+                 "use gnulib module chdir for portability");
+# endif
+#endif
+
+
 #if @GNULIB_CHOWN@
 /* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
    to GID (if GID is not -1).  Follow symbolic links.
@@ -287,16 +301,24 @@ _GL_WARN_ON_USE (close, "close does not portably work on 
sockets - "
 #endif
 
 
-#if @REPLACE_DUP@
-# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
-#  define dup rpl_dup
-# endif
+#if @GNULIB_DUP@
+# if @REPLACE_DUP@
+#  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
+#   define dup rpl_dup
+#  endif
 _GL_FUNCDECL_RPL (dup, int, (int oldfd));
 _GL_CXXALIAS_RPL (dup, int, (int oldfd));
-#else
+# else
 _GL_CXXALIAS_SYS (dup, int, (int oldfd));
-#endif
+# endif
 _GL_CXXALIASWARN (dup);
+#elif defined GNULIB_POSIXCHECK
+# undef dup
+# if HAVE_RAW_DECL_DUP
+_GL_WARN_ON_USE (dup, "dup is unportable - "
+                 "use gnulib module dup for portability");
+# endif
+#endif
 
 
 #if @GNULIB_DUP2@
@@ -1155,7 +1177,7 @@ _GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
 /* Read up to COUNT bytes from file descriptor FD into the buffer starting
    at BUF.  See the POSIX:2008 specification
    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/read.html>.  */
-# if @REPLACE_READ@ && @GNULIB_UNISTD_H_NONBLOCKING@
+# if @REPLACE_READ@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef read
 #   define read rpl_read
@@ -1427,7 +1449,7 @@ _GL_WARN_ON_USE (usleep, "usleep is unportable - "
 /* Write up to COUNT bytes starting at BUF to file descriptor FD.
    See the POSIX:2008 specification
    <http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html>.  */
-# if @REPLACE_WRITE@ && (@GNULIB_UNISTD_H_NONBLOCKING@ || 
@GNULIB_UNISTD_H_SIGPIPE@)
+# if @REPLACE_WRITE@
 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
 #   undef write
 #   define write rpl_write
diff --git a/gl/vasnprintf.c b/gl/vasnprintf.c
index 3f2e91d..71f8d80 100644
--- a/gl/vasnprintf.c
+++ b/gl/vasnprintf.c
@@ -553,32 +553,61 @@ divide (mpn_t a, mpn_t b, mpn_t *q)
       size_t s;
       {
         mp_limb_t msd = b_ptr[b_len - 1]; /* = b[n-1], > 0 */
-        s = 31;
-        if (msd >= 0x10000)
-          {
-            msd = msd >> 16;
-            s -= 16;
-          }
-        if (msd >= 0x100)
-          {
-            msd = msd >> 8;
-            s -= 8;
-          }
-        if (msd >= 0x10)
-          {
-            msd = msd >> 4;
-            s -= 4;
-          }
-        if (msd >= 0x4)
+        /* Determine s = GMP_LIMB_BITS - integer_length (msd).
+           Code copied from gnulib's integer_length.c.  */
+# if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+        s = __builtin_clz (msd);
+# else
+#  if defined DBL_EXPBIT0_WORD && defined DBL_EXPBIT0_BIT
+        if (GMP_LIMB_BITS <= DBL_MANT_BIT)
           {
-            msd = msd >> 2;
-            s -= 2;
+            /* Use 'double' operations.
+               Assumes an IEEE 754 'double' implementation.  */
+#   define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7)
+#   define DBL_EXP_BIAS (DBL_EXP_MASK / 2 - 1)
+#   define NWORDS \
+     ((sizeof (double) + sizeof (unsigned int) - 1) / sizeof (unsigned int))
+            union { double value; unsigned int word[NWORDS]; } m;
+
+            /* Use a single integer to floating-point conversion.  */
+            m.value = msd;
+
+            s = GMP_LIMB_BITS
+                - (((m.word[DBL_EXPBIT0_WORD] >> DBL_EXPBIT0_BIT) & 
DBL_EXP_MASK)
+                   - DBL_EXP_BIAS);
           }
-        if (msd >= 0x2)
+        else
+#   undef NWORDS
+#  endif
           {
-            msd = msd >> 1;
-            s -= 1;
+            s = 31;
+            if (msd >= 0x10000)
+              {
+                msd = msd >> 16;
+                s -= 16;
+              }
+            if (msd >= 0x100)
+              {
+                msd = msd >> 8;
+                s -= 8;
+              }
+            if (msd >= 0x10)
+              {
+                msd = msd >> 4;
+                s -= 4;
+              }
+            if (msd >= 0x4)
+              {
+                msd = msd >> 2;
+                s -= 2;
+              }
+            if (msd >= 0x2)
+              {
+                msd = msd >> 1;
+                s -= 1;
+              }
           }
+# endif
       }
       /* 0 <= s < GMP_LIMB_BITS.
          Copy b, shifting it left by s bits.  */
@@ -885,9 +914,9 @@ decode_long_double (long double x, int *ep, mpn_t *mp)
   y = frexpl (x, &exp);
   if (!(y >= 0.0L && y < 1.0L))
     abort ();
-  /* x = 2^exp * y = 2^(exp - LDBL_MANT_BIT) * (y * LDBL_MANT_BIT), and the
+  /* x = 2^exp * y = 2^(exp - LDBL_MANT_BIT) * (y * 2^LDBL_MANT_BIT), and the
      latter is an integer.  */
-  /* Convert the mantissa (y * LDBL_MANT_BIT) to a sequence of limbs.
+  /* Convert the mantissa (y * 2^LDBL_MANT_BIT) to a sequence of limbs.
      I'm not sure whether it's safe to cast a 'long double' value between
      2^31 and 2^32 to 'unsigned int', therefore play safe and cast only
      'long double' values between 0 and 2^16 (to 'unsigned int' or 'int',
@@ -973,9 +1002,9 @@ decode_double (double x, int *ep, mpn_t *mp)
   y = frexp (x, &exp);
   if (!(y >= 0.0 && y < 1.0))
     abort ();
-  /* x = 2^exp * y = 2^(exp - DBL_MANT_BIT) * (y * DBL_MANT_BIT), and the
+  /* x = 2^exp * y = 2^(exp - DBL_MANT_BIT) * (y * 2^DBL_MANT_BIT), and the
      latter is an integer.  */
-  /* Convert the mantissa (y * DBL_MANT_BIT) to a sequence of limbs.
+  /* Convert the mantissa (y * 2^DBL_MANT_BIT) to a sequence of limbs.
      I'm not sure whether it's safe to cast a 'double' value between
      2^31 and 2^32 to 'unsigned int', therefore play safe and cast only
      'double' values between 0 and 2^16 (to 'unsigned int' or 'int',
diff --git a/gl/w32sock.h b/gl/w32sock.h
index 651a76d..0b8334e 100644
--- a/gl/w32sock.h
+++ b/gl/w32sock.h
@@ -22,9 +22,12 @@
 /* Get O_RDWR and O_BINARY.  */
 #include <fcntl.h>
 
-/* Get _get_osfhandle() and _open_osfhandle().  */
+/* Get _open_osfhandle().  */
 #include <io.h>
 
+/* Get _get_osfhandle().  */
+#include "msvc-nothrow.h"
+
 #define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
 #define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
 
@@ -45,15 +48,87 @@ set_winsock_errno (void)
     case WSA_INVALID_PARAMETER:
       errno = EINVAL;
       break;
-    case WSAEWOULDBLOCK:
-      errno = EWOULDBLOCK;
-      break;
     case WSAENAMETOOLONG:
       errno = ENAMETOOLONG;
       break;
     case WSAENOTEMPTY:
       errno = ENOTEMPTY;
       break;
+    case WSAEWOULDBLOCK:
+      errno = EWOULDBLOCK;
+      break;
+    case WSAEINPROGRESS:
+      errno = EINPROGRESS;
+      break;
+    case WSAEALREADY:
+      errno = EALREADY;
+      break;
+    case WSAENOTSOCK:
+      errno = ENOTSOCK;
+      break;
+    case WSAEDESTADDRREQ:
+      errno = EDESTADDRREQ;
+      break;
+    case WSAEMSGSIZE:
+      errno = EMSGSIZE;
+      break;
+    case WSAEPROTOTYPE:
+      errno = EPROTOTYPE;
+      break;
+    case WSAENOPROTOOPT:
+      errno = ENOPROTOOPT;
+      break;
+    case WSAEPROTONOSUPPORT:
+      errno = EPROTONOSUPPORT;
+      break;
+    case WSAEOPNOTSUPP:
+      errno = EOPNOTSUPP;
+      break;
+    case WSAEAFNOSUPPORT:
+      errno = EAFNOSUPPORT;
+      break;
+    case WSAEADDRINUSE:
+      errno = EADDRINUSE;
+      break;
+    case WSAEADDRNOTAVAIL:
+      errno = EADDRNOTAVAIL;
+      break;
+    case WSAENETDOWN:
+      errno = ENETDOWN;
+      break;
+    case WSAENETUNREACH:
+      errno = ENETUNREACH;
+      break;
+    case WSAENETRESET:
+      errno = ENETRESET;
+      break;
+    case WSAECONNABORTED:
+      errno = ECONNABORTED;
+      break;
+    case WSAECONNRESET:
+      errno = ECONNRESET;
+      break;
+    case WSAENOBUFS:
+      errno = ENOBUFS;
+      break;
+    case WSAEISCONN:
+      errno = EISCONN;
+      break;
+    case WSAENOTCONN:
+      errno = ENOTCONN;
+      break;
+    case WSAETIMEDOUT:
+      errno = ETIMEDOUT;
+      break;
+    case WSAECONNREFUSED:
+      errno = ECONNREFUSED;
+      break;
+    case WSAELOOP:
+      errno = ELOOP;
+      break;
+    case WSAEHOSTUNREACH:
+      errno = EHOSTUNREACH;
+      break;
     default:
       errno = (err > 10000 && err < 10025) ? err - 10000 : err;
       break;
diff --git a/gtk-doc.make b/gtk-doc.make
index ab9cbf7..1f75dfd 100644
--- a/gtk-doc.make
+++ b/gtk-doc.make
@@ -5,12 +5,12 @@
 ####################################
 
 if GTK_DOC_USE_LIBTOOL
-GTKDOC_CC = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(INCLUDES) 
$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-GTKDOC_LD = $(LIBTOOL) --tag=CC --mode=link $(CC) $(AM_CFLAGS) $(CFLAGS) 
$(AM_LDFLAGS) $(LDFLAGS)
+GTKDOC_CC = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(INCLUDES) 
$(GTKDOC_DEPS_CFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+GTKDOC_LD = $(LIBTOOL) --tag=CC --mode=link $(CC) $(GTKDOC_DEPS_LIBS) 
$(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS)
 GTKDOC_RUN = $(LIBTOOL) --mode=execute
 else
-GTKDOC_CC = $(CC) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
-GTKDOC_LD = $(CC) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS)
+GTKDOC_CC = $(CC) $(INCLUDES) $(GTKDOC_DEPS_CFLAGS) $(AM_CPPFLAGS) $(CPPFLAGS) 
$(AM_CFLAGS) $(CFLAGS)
+GTKDOC_LD = $(CC) $(GTKDOC_DEPS_LIBS) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) 
$(LDFLAGS)
 GTKDOC_RUN =
 endif
 
@@ -23,20 +23,22 @@ GPATH = $(srcdir)
 
 TARGET_DIR=$(HTML_DIR)/$(DOC_MODULE)
 
-EXTRA_DIST =                           \
+SETUP_FILES = \
        $(content_files)                \
-       $(HTML_IMAGES)                  \
        $(DOC_MAIN_SGML_FILE)           \
        $(DOC_MODULE)-sections.txt      \
        $(DOC_MODULE)-overrides.txt
 
-DOC_STAMPS=scan-build.stamp tmpl-build.stamp sgml-build.stamp html-build.stamp 
\
-       pdf-build.stamp \
-       $(srcdir)/tmpl.stamp $(srcdir)/sgml.stamp $(srcdir)/html.stamp \
-       $(srcdir)/pdf.stamp
+EXTRA_DIST =                           \
+       $(HTML_IMAGES)                  \
+       $(SETUP_FILES)
+
+DOC_STAMPS=setup-build.stamp scan-build.stamp tmpl-build.stamp 
sgml-build.stamp \
+       html-build.stamp pdf-build.stamp \
+       tmpl.stamp sgml.stamp html.stamp pdf.stamp
 
-SCANOBJ_FILES =                        \
-       $(DOC_MODULE).args      \
+SCANOBJ_FILES =                 \
+       $(DOC_MODULE).args       \
        $(DOC_MODULE).hierarchy  \
        $(DOC_MODULE).interfaces \
        $(DOC_MODULE).prerequisites \
@@ -70,22 +72,47 @@ docs: $(HTML_BUILD_STAMP) $(PDF_BUILD_STAMP)
 
 $(REPORT_FILES): sgml-build.stamp
 
+#### setup ####
+
+setup-build.stamp:
+       address@hidden test "$(abs_srcdir)" != "$(abs_builddir)" ; then \
+           echo '  DOC   Preparing build'; \
+           files=`echo $(SETUP_FILES) $(expand_content_files) 
$(DOC_MODULE).types`; \
+           if test "x$$files" != "x" ; then \
+               for file in $$files ; do \
+                   test -f $(abs_srcdir)/$$file && \
+                       cp -pu $(abs_srcdir)/$$file $(abs_builddir)/ || true; \
+               done; \
+           fi; \
+           test -d $(abs_srcdir)/tmpl && \
+               { cp -rp $(abs_srcdir)/tmpl $(abs_builddir)/; \
+               chmod -R u+w $(abs_builddir)/tmpl; } \
+       fi
+       @touch setup-build.stamp
+
 #### scan ####
 
 scan-build.stamp: $(HFILE_GLOB) $(CFILE_GLOB)
-       @echo 'gtk-doc: Scanning header files'
-       @-chmod -R u+w $(srcdir)
-       @_source_dir='' ; for i in $(DOC_SOURCE_DIR) ; do \
+       @echo '  DOC   Scanning header files'
+       @_source_dir='' ; \
+       for i in $(DOC_SOURCE_DIR) ; do \
            _source_dir="$${_source_dir} --source-dir=$$i" ; \
-         done ; \
-         cd $(srcdir) && \
-         gtkdoc-scan --module=$(DOC_MODULE) 
--ignore-headers="$(IGNORE_HFILES)" $${_source_dir} $(SCAN_OPTIONS) 
$(EXTRA_HFILES)
-       @if grep -l '^..*$$' $(srcdir)/$(DOC_MODULE).types > /dev/null 2>&1 ; 
then \
-           CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)" RUN="$(GTKDOC_RUN)" 
CFLAGS="$(GTKDOC_CFLAGS) $(CFLAGS)" LDFLAGS="$(GTKDOC_LIBS) $(LDFLAGS)" 
gtkdoc-scangobj $(SCANGOBJ_OPTIONS) --module=$(DOC_MODULE) 
--output-dir=$(srcdir) ; \
+       done ; \
+       gtkdoc-scan --module=$(DOC_MODULE) --ignore-headers="$(IGNORE_HFILES)" 
$${_source_dir} $(SCAN_OPTIONS) $(EXTRA_HFILES)
+       @if grep -l '^..*$$' $(DOC_MODULE).types > /dev/null 2>&1 ; then \
+           echo "  DOC   Introspecting gobjects"; \
+           scanobj_options=""; \
+           gtkdoc-scangobj 2>&1 --help | grep  >/dev/null "\-\-verbose"; \
+           if test "$(?)" = "0"; then \
+               if test "x$(V)" = "x1"; then \
+                   scanobj_options="--verbose"; \
+               fi; \
+           fi; \
+           CC="$(GTKDOC_CC)" LD="$(GTKDOC_LD)" RUN="$(GTKDOC_RUN)" 
CFLAGS="$(GTKDOC_CFLAGS) $(CFLAGS)" LDFLAGS="$(GTKDOC_LIBS) $(LDFLAGS)" \
+           gtkdoc-scangobj $(SCANGOBJ_OPTIONS) $$scanobj_options 
--module=$(DOC_MODULE); \
        else \
-           cd $(srcdir) ; \
            for i in $(SCANOBJ_FILES) ; do \
-               test -f $$i || touch $$i ; \
+               test -f $$i || touch $$i ; \
            done \
        fi
        @touch scan-build.stamp
@@ -95,10 +122,14 @@ $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) 
$(DOC_MODULE)-sections.txt $(DOC_MODULE)
 
 #### templates ####
 
-tmpl-build.stamp: $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) 
$(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt
-       @echo 'gtk-doc: Rebuilding template files'
-       @-chmod -R u+w $(srcdir)
-       @cd $(srcdir) && gtkdoc-mktmpl --module=$(DOC_MODULE) $(MKTMPL_OPTIONS)
+tmpl-build.stamp: setup-build.stamp $(DOC_MODULE)-decl.txt $(SCANOBJ_FILES) 
$(DOC_MODULE)-sections.txt $(DOC_MODULE)-overrides.txt
+       @echo '  DOC   Rebuilding template files'
+       @gtkdoc-mktmpl --module=$(DOC_MODULE) $(MKTMPL_OPTIONS)
+       @if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \
+         if test -w $(abs_srcdir) ; then \
+           cp -rp $(abs_builddir)/tmpl $(abs_srcdir)/; \
+         fi \
+       fi
        @touch tmpl-build.stamp
 
 tmpl.stamp: tmpl-build.stamp
@@ -110,13 +141,13 @@ $(srcdir)/tmpl/*.sgml:
 #### xml ####
 
 sgml-build.stamp: tmpl.stamp $(DOC_MODULE)-sections.txt $(srcdir)/tmpl/*.sgml 
$(expand_content_files)
-       @echo 'gtk-doc: Building XML'
+       @echo '  DOC   Building XML'
        @-chmod -R u+w $(srcdir)
-       @_source_dir='' ; for i in $(DOC_SOURCE_DIR) ; do \
+       @_source_dir='' ; \
+       for i in $(DOC_SOURCE_DIR) ; do \
            _source_dir="$${_source_dir} --source-dir=$$i" ; \
-         done ; \
-         cd $(srcdir) && \
-         gtkdoc-mkdb --module=$(DOC_MODULE) --output-format=xml 
--expand-content-files="$(expand_content_files)" 
--main-sgml-file=$(DOC_MAIN_SGML_FILE) $${_source_dir} $(MKDB_OPTIONS)
+       done ; \
+       gtkdoc-mkdb --module=$(DOC_MODULE) --output-format=xml 
--expand-content-files="$(expand_content_files)" 
--main-sgml-file=$(DOC_MAIN_SGML_FILE) $${_source_dir} $(MKDB_OPTIONS)
        @touch sgml-build.stamp
 
 sgml.stamp: sgml-build.stamp
@@ -125,58 +156,79 @@ sgml.stamp: sgml-build.stamp
 #### html ####
 
 html-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files)
-       @echo 'gtk-doc: Building HTML'
-       @-chmod -R u+w $(srcdir)
-       @rm -rf $(srcdir)/html
-       @mkdir $(srcdir)/html
+       @echo '  DOC   Building HTML'
+       @rm -rf html
+       @mkdir html
        @mkhtml_options=""; \
+       gtkdoc-mkhtml 2>&1 --help | grep  >/dev/null "\-\-verbose"; \
+       if test "$(?)" = "0"; then \
+         if test "x$(V)" = "x1"; then \
+           mkhtml_options="$$mkhtml_options --verbose"; \
+         fi; \
+       fi; \
        gtkdoc-mkhtml 2>&1 --help | grep  >/dev/null "\-\-path"; \
        if test "$(?)" = "0"; then \
-         mkhtml_options=--path="$(srcdir)"; \
+         mkhtml_options="$$mkhtml_options --path=\"$(abs_srcdir)\""; \
        fi; \
-       cd $(srcdir)/html && gtkdoc-mkhtml $$mkhtml_options $(MKHTML_OPTIONS) 
$(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE)
-       @test "x$(HTML_IMAGES)" = "x" || ( cd $(srcdir) && cp $(HTML_IMAGES) 
html )
-       @echo 'gtk-doc: Fixing cross-references'
-       @cd $(srcdir) && gtkdoc-fixxref --module=$(DOC_MODULE) 
--module-dir=html --html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS)
+       cd html && gtkdoc-mkhtml $$mkhtml_options $(MKHTML_OPTIONS) 
$(DOC_MODULE) ../$(DOC_MAIN_SGML_FILE)
+       address@hidden "x$(HTML_IMAGES)" = "x" || \
+       for file in $(HTML_IMAGES) ; do \
+         if test -f $(abs_srcdir)/$$file ; then \
+           cp $(abs_srcdir)/$$file $(abs_builddir)/html; \
+         fi; \
+         if test -f $(abs_builddir)/$$file ; then \
+           cp $(abs_builddir)/$$file $(abs_builddir)/html; \
+         fi; \
+       done;
+       @echo '  DOC   Fixing cross-references'
+       @gtkdoc-fixxref --module=$(DOC_MODULE) --module-dir=html 
--html-dir=$(HTML_DIR) $(FIXXREF_OPTIONS)
        @touch html-build.stamp
 
 #### pdf ####
 
 pdf-build.stamp: sgml.stamp $(DOC_MAIN_SGML_FILE) $(content_files)
-       @echo 'gtk-doc: Building PDF'
-       @-chmod -R u+w $(srcdir)
-       @rm -rf $(srcdir)/$(DOC_MODULE).pdf
-       @mkpdf_imgdirs=""; \
+       @echo '  DOC   Building PDF'
+       @rm -f $(DOC_MODULE).pdf
+       @mkpdf_options=""; \
+       gtkdoc-mkpdf 2>&1 --help | grep  >/dev/null "\-\-verbose"; \
+       if test "$(?)" = "0"; then \
+         if test "x$(V)" = "x1"; then \
+           mkpdf_options="$$mkpdf_options --verbose"; \
+         fi; \
+       fi; \
        if test "x$(HTML_IMAGES)" != "x"; then \
          for img in $(HTML_IMAGES); do \
            part=`dirname $$img`; \
-           echo $$mkpdf_imgdirs | grep >/dev/null "\-\-imgdir=$$part "; \
+           echo $$mkpdf_options | grep >/dev/null "\-\-imgdir=$$part "; \
            if test $$? != 0; then \
-             mkpdf_imgdirs="$$mkpdf_imgdirs --imgdir=$$part"; \
+             mkpdf_options="$$mkpdf_options --imgdir=$$part"; \
            fi; \
          done; \
        fi; \
-       cd $(srcdir) && gtkdoc-mkpdf --path="$(abs_srcdir)" $$mkpdf_imgdirs 
$(DOC_MODULE) $(DOC_MAIN_SGML_FILE) $(MKPDF_OPTIONS)
+       gtkdoc-mkpdf --path="$(abs_srcdir)" $$mkpdf_options $(DOC_MODULE) 
$(DOC_MAIN_SGML_FILE) $(MKPDF_OPTIONS)
        @touch pdf-build.stamp
 
 ##############
 
 clean-local:
-       rm -f *~ *.bak
-       rm -rf .libs
+       @rm -f *~ *.bak
+       @rm -rf .libs
 
 distclean-local:
-       cd $(srcdir) && \
-         rm -rf xml $(REPORT_FILES) $(DOC_MODULE).pdf \
-                $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt
+       @rm -rf xml html $(REPORT_FILES) $(DOC_MODULE).pdf \
+           $(DOC_MODULE)-decl-list.txt $(DOC_MODULE)-decl.txt
+       @if test "$(abs_srcdir)" != "$(abs_builddir)" ; then \
+           rm -f $(SETUP_FILES) $(expand_content_files) $(DOC_MODULE).types; \
+           rm -rf tmpl; \
+       fi
 
 maintainer-clean-local: clean
-       cd $(srcdir) && rm -rf xml html
+       @rm -rf xml html
 
 install-data-local:
-       @installfiles=`echo $(srcdir)/html/*`; \
-       if test "$$installfiles" = '$(srcdir)/html/*'; \
-       then echo '-- Nothing to install' ; \
+       @installfiles=`echo $(builddir)/html/*`; \
+       if test "$$installfiles" = '$(builddir)/html/*'; \
+       then echo 1>&2 'Nothing to install' ; \
        else \
          if test -n "$(DOC_MODULE_VERSION)"; then \
            installdir="$(DESTDIR)$(TARGET_DIR)-$(DOC_MODULE_VERSION)"; \
@@ -185,14 +237,12 @@ install-data-local:
          fi; \
          $(mkinstalldirs) $${installdir} ; \
          for i in $$installfiles; do \
-           echo '-- Installing '$$i ; \
+           echo ' $(INSTALL_DATA) '$$i ; \
            $(INSTALL_DATA) $$i $${installdir}; \
          done; \
          if test -n "$(DOC_MODULE_VERSION)"; then \
            mv -f $${installdir}/$(DOC_MODULE).devhelp2 \
              $${installdir}/$(DOC_MODULE)-$(DOC_MODULE_VERSION).devhelp2; \
-           mv -f $${installdir}/$(DOC_MODULE).devhelp \
-             $${installdir}/$(DOC_MODULE)-$(DOC_MODULE_VERSION).devhelp; \
          fi; \
          $(GTKDOC_REBASE) --relative --dest-dir=$(DESTDIR) 
--html-dir=$${installdir}; \
        fi
@@ -217,14 +267,14 @@ dist-check-gtkdoc:
 endif
 
 dist-hook: dist-check-gtkdoc dist-hook-local
-       mkdir $(distdir)/tmpl
-       mkdir $(distdir)/html
-       -cp $(srcdir)/tmpl/*.sgml $(distdir)/tmpl
-       -cp $(srcdir)/html/* $(distdir)/html
-       -cp $(srcdir)/$(DOC_MODULE).pdf $(distdir)/
-       -cp $(srcdir)/$(DOC_MODULE).types $(distdir)/
-       -cp $(srcdir)/$(DOC_MODULE)-sections.txt $(distdir)/
-       cd $(distdir) && rm -f $(DISTCLEANFILES)
-       $(GTKDOC_REBASE) --online --relative --html-dir=$(distdir)/html
+       @mkdir $(distdir)/tmpl
+       @mkdir $(distdir)/html
+       @-cp ./tmpl/*.sgml $(distdir)/tmpl
+       @cp ./html/* $(distdir)/html
+       @-cp ./$(DOC_MODULE).pdf $(distdir)/
+       @-cp ./$(DOC_MODULE).types $(distdir)/
+       @-cp ./$(DOC_MODULE)-sections.txt $(distdir)/
+       @cd $(distdir) && rm -f $(DISTCLEANFILES)
+       @$(GTKDOC_REBASE) --online --relative --html-dir=$(distdir)/html
 
 .PHONY : dist-hook-local docs
diff --git a/guile/modules/Makefile.am b/guile/modules/Makefile.am
index d1b1cac..ebe1d6e 100644
--- a/guile/modules/Makefile.am
+++ b/guile/modules/Makefile.am
@@ -17,7 +17,8 @@
 
 guilemoduledir = $(GUILE_SITE)
 
-nobase_dist_guilemodule_DATA = gnutls.scm gnutls/extra.scm
+nobase_nodist_guilemodule_DATA = gnutls.scm
+nobase_dist_guilemodule_DATA   = gnutls/extra.scm
 
 documentation_modules = system/documentation/README            \
                        system/documentation/c-snarf.scm        \
@@ -26,4 +27,12 @@ documentation_modules = system/documentation/README          
\
 EXTRA_DIST = gnutls/build/enums.scm gnutls/build/smobs.scm     \
             gnutls/build/utils.scm gnutls/build/priorities.scm \
             gnutls/build/tests.scm                             \
+            gnutls.in                                          \
              $(documentation_modules)
+
+CLEANFILES = gnutls.scm
+
+.in.scm:
+       cat "$^" | $(SED) -e's|address@hidden@]|$(guileextensiondir)|g' \
+         > "address@hidden"
+       mv "address@hidden" "$@"
diff --git a/guile/modules/gnutls.in b/guile/modules/gnutls.in
new file mode 100644
index 0000000..56e3137
--- /dev/null
+++ b/guile/modules/gnutls.in
@@ -0,0 +1,413 @@
+;;; GnuTLS --- Guile bindings for GnuTLS.
+;;; Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
+;;;
+;;; GnuTLS is free software; you can redistribute it and/or
+;;; modify it under the terms of the GNU Lesser General Public
+;;; License as published by the Free Software Foundation; either
+;;; version 2.1 of the License, or (at your option) any later version.
+;;;
+;;; GnuTLS is distributed in the hope that it will be useful,
+;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;;; Lesser General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU Lesser General Public
+;;; License along with GnuTLS; if not, write to the Free Software
+;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
+
+;;; Written by Ludovic Courtès <address@hidden>
+
+(define-module (gnutls)
+  ;; Note: The export list must be manually kept in sync with the build
+  ;; system.
+  :export (;; versioning
+           gnutls-version
+
+           ;; sessions
+           session?
+           make-session bye handshake rehandshake
+           alert-get alert-send
+           session-cipher session-kx session-mac session-protocol
+           session-compression-method session-certificate-type
+           session-authentication-type session-server-authentication-type
+           session-client-authentication-type
+           session-peer-certificate-chain session-our-certificate-chain
+           set-session-transport-fd! set-session-transport-port!
+           set-session-credentials! set-server-session-certificate-request!
+
+           ;; anonymous credentials
+           anonymous-client-credentials? anonymous-server-credentials?
+           make-anonymous-client-credentials make-anonymous-server-credentials
+           set-anonymous-server-dh-parameters!
+
+           ;; certificate credentials
+           certificate-credentials? make-certificate-credentials
+           set-certificate-credentials-dh-parameters!
+           set-certificate-credentials-rsa-export-parameters!
+           set-certificate-credentials-x509-key-files!
+           set-certificate-credentials-x509-trust-file!
+           set-certificate-credentials-x509-crl-file!
+           set-certificate-credentials-x509-key-data!
+           set-certificate-credentials-x509-trust-data!
+           set-certificate-credentials-x509-crl-data!
+           set-certificate-credentials-x509-keys!
+           set-certificate-credentials-verify-limits!
+           set-certificate-credentials-verify-flags!
+           peer-certificate-status
+
+           ;; SRP credentials
+           srp-client-credentials? srp-server-credentials?
+           make-srp-client-credentials make-srp-server-credentials
+           set-srp-client-credentials!
+           set-srp-server-credentials-files!
+           server-session-srp-username
+           srp-base64-encode srp-base64-decode
+
+           ;; PSK credentials
+           psk-client-credentials? psk-server-credentials?
+           make-psk-client-credentials make-psk-server-credentials
+           set-psk-client-credentials!
+           set-psk-server-credentials-file!
+           server-session-psk-username
+
+           ;; priorities
+           set-session-priorities!
+
+           ;; priority functions (deprecated)
+           set-session-cipher-priority! set-session-mac-priority!
+           set-session-compression-method-priority!
+           set-session-kx-priority! set-session-protocol-priority!
+           set-session-certificate-type-priority!
+           set-session-default-priority! set-session-default-export-priority!
+
+           ;; DH
+           set-session-dh-prime-bits!
+           make-dh-parameters dh-parameters?
+           pkcs3-import-dh-parameters pkcs3-export-dh-parameters
+
+           ;; RSA
+           make-rsa-parameters rsa-parameters?
+           pkcs1-import-rsa-parameters pkcs1-export-rsa-parameters
+
+           ;; X.509
+           x509-certificate? x509-private-key?
+           import-x509-certificate  x509-certificate-matches-hostname?
+           x509-certificate-dn x509-certificate-dn-oid
+           x509-certificate-issuer-dn x509-certificate-issuer-dn-oid
+           x509-certificate-signature-algorithm x509-certificate-version
+           x509-certificate-key-id x509-certificate-authority-key-id
+           x509-certificate-subject-key-id
+           x509-certificate-subject-alternative-name
+           x509-certificate-public-key-algorithm x509-certificate-key-usage
+           import-x509-private-key pkcs8-import-x509-private-key
+
+           ;; record layer
+           record-send record-receive!
+           session-record-port
+
+           ;; debugging
+           set-log-procedure! set-log-level!
+
+           ;; enum->string functions
+           cipher->string kx->string params->string credentials->string
+           mac->string digest->string compression-method->string
+           connection-end->string alert-level->string
+           alert-description->string handshake-description->string
+           certificate-status->string certificate-request->string
+           close-request->string
+           protocol->string certificate-type->string
+           x509-certificate-format->string
+           x509-subject-alternative-name->string pk-algorithm->string
+           sign-algorithm->string psk-key-format->string key-usage->string
+           certificate-verify->string error->string
+           cipher-suite->string
+
+           ;; enum values
+           cipher/null
+           cipher/arcfour cipher/arcfour-128
+           cipher/3des-cbc
+           cipher/aes-128-cbc cipher/rijndael-cbc cipher/rijndael-128-cbc
+           cipher/aes-256-cbc cipher/rijndael-256-cbc
+           cipher/arcfour-40
+           cipher/rc2-40-cbc
+           cipher/des-cbc
+           kx/rsa
+           kx/dhe-dss
+           kx/dhe-rsa
+           kx/anon-dh
+           kx/srp
+           kx/rsa-export
+           kx/srp-rsa
+           kx/srp-dss
+           kx/psk
+           kx/dhe-dss
+           params/rsa-export
+           params/dh
+           credentials/certificate
+           credentials/anon
+           credentials/anonymous
+           credentials/srp
+           credentials/psk
+           credentials/ia
+           mac/unknown
+           mac/null
+           mac/md5
+           mac/sha1
+           mac/rmd160
+           mac/md2
+           digest/null
+           digest/md5
+           digest/sha1
+           digest/rmd160
+           digest/md2
+           compression-method/null
+           compression-method/deflate
+           compression-method/lzo
+           connection-end/server
+           connection-end/client
+           alert-level/warning
+           alert-level/fatal
+           alert-description/close-notify
+           alert-description/unexpected-message
+           alert-description/bad-record-mac
+           alert-description/decryption-failed
+           alert-description/record-overflow
+           alert-description/decompression-failure
+           alert-description/handshake-failure
+           alert-description/ssl3-no-certificate
+           alert-description/bad-certificate
+           alert-description/unsupported-certificate
+           alert-description/certificate-revoked
+           alert-description/certificate-expired
+           alert-description/certificate-unknown
+           alert-description/illegal-parameter
+           alert-description/unknown-ca
+           alert-description/access-denied
+           alert-description/decode-error
+           alert-description/decrypt-error
+           alert-description/export-restriction
+           alert-description/protocol-version
+           alert-description/insufficient-security
+           alert-description/internal-error
+           alert-description/user-canceled
+           alert-description/no-renegotiation
+           alert-description/unsupported-extension
+           alert-description/certificate-unobtainable
+           alert-description/unrecognized-name
+           alert-description/unknown-psk-identity
+           alert-description/inner-application-failure
+           alert-description/inner-application-verification
+           handshake-description/hello-request
+           handshake-description/client-hello
+           handshake-description/server-hello
+           handshake-description/certificate-pkt
+           handshake-description/server-key-exchange
+           handshake-description/certificate-request
+           handshake-description/server-hello-done
+           handshake-description/certificate-verify
+           handshake-description/client-key-exchange
+           handshake-description/finished
+           certificate-status/invalid
+           certificate-status/revoked
+           certificate-status/signer-not-found
+           certificate-status/signer-not-ca
+           certificate-status/insecure-algorithm
+           certificate-request/ignore
+           certificate-request/request
+           certificate-request/require
+           close-request/rdwr
+           close-request/wr
+           protocol/ssl-3
+           protocol/tls-1.0
+           protocol/tls-1.1
+           protocol/version-unknown
+           certificate-type/x509
+           certificate-type/openpgp
+           x509-certificate-format/der
+           x509-certificate-format/pem
+           x509-subject-alternative-name/dnsname
+           x509-subject-alternative-name/rfc822name
+           x509-subject-alternative-name/uri
+           x509-subject-alternative-name/ipaddress
+           pk-algorithm/rsa
+           pk-algorithm/dsa
+           pk-algorithm/unknown
+           sign-algorithm/unknown
+           sign-algorithm/rsa-sha1
+           sign-algorithm/dsa-sha1
+           sign-algorithm/rsa-md5
+           sign-algorithm/rsa-md2
+           sign-algorithm/rsa-rmd160
+           psk-key-format/raw
+           psk-key-format/hex
+           key-usage/digital-signature
+           key-usage/non-repudiation
+           key-usage/key-encipherment
+           key-usage/data-encipherment
+           key-usage/key-agreement
+           key-usage/key-cert-sign
+           key-usage/crl-sign
+           key-usage/encipher-only
+           key-usage/decipher-only
+           certificate-verify/disable-ca-sign
+           certificate-verify/allow-x509-v1-ca-crt
+           certificate-verify/allow-x509-v1-ca-certificate
+           certificate-verify/do-not-allow-same
+           certificate-verify/allow-any-x509-v1-ca-crt
+           certificate-verify/allow-any-x509-v1-ca-certificate
+           certificate-verify/allow-sign-rsa-md2
+           certificate-verify/allow-sign-rsa-md5
+
+           error/success
+           error/unknown-compression-algorithm
+           error/unknown-cipher-type
+           error/large-packet
+           error/unsupported-version-packet
+           error/unexpected-packet-length
+           error/invalid-session
+           error/fatal-alert-received
+           error/unexpected-packet
+           error/warning-alert-received
+           error/error-in-finished-packet
+           error/unexpected-handshake-packet
+           error/unknown-cipher-suite
+           error/unwanted-algorithm
+           error/mpi-scan-failed
+           error/decryption-failed
+           error/memory-error
+           error/decompression-failed
+           error/compression-failed
+           error/again
+           error/expired
+           error/db-error
+           error/srp-pwd-error
+           error/insufficient-credentials
+           error/insuficient-credentials
+           error/insufficient-cred
+           error/insuficient-cred
+           error/hash-failed
+           error/base64-decoding-error
+           error/mpi-print-failed
+           error/rehandshake
+           error/got-application-data
+           error/record-limit-reached
+           error/encryption-failed
+           error/pk-encryption-failed
+           error/pk-decryption-failed
+           error/pk-sign-failed
+           error/x509-unsupported-critical-extension
+           error/key-usage-violation
+           error/no-certificate-found
+           error/invalid-request
+           error/short-memory-buffer
+           error/interrupted
+           error/push-error
+           error/pull-error
+           error/received-illegal-parameter
+           error/requested-data-not-available
+           error/pkcs1-wrong-pad
+           error/received-illegal-extension
+           error/internal-error
+           error/dh-prime-unacceptable
+           error/file-error
+           error/too-many-empty-packets
+           error/unknown-pk-algorithm
+           error/no-temporary-rsa-params
+           error/lzo-init-failed
+           error/no-compression-algorithms
+           error/no-cipher-suites
+           error/openpgp-getkey-failed
+           error/pk-sig-verify-failed
+           error/illegal-srp-username
+           error/srp-pwd-parsing-error
+           error/no-temporary-dh-params
+           error/asn1-element-not-found
+           error/asn1-identifier-not-found
+           error/asn1-der-error
+           error/asn1-value-not-found
+           error/asn1-generic-error
+           error/asn1-value-not-valid
+           error/asn1-tag-error
+           error/asn1-tag-implicit
+           error/asn1-type-any-error
+           error/asn1-syntax-error
+           error/asn1-der-overflow
+           error/openpgp-uid-revoked
+           error/certificate-error
+           error/x509-certificate-error
+           error/certificate-key-mismatch
+           error/unsupported-certificate-type
+           error/x509-unknown-san
+           error/openpgp-fingerprint-unsupported
+           error/x509-unsupported-attribute
+           error/unknown-algorithm
+           error/unknown-hash-algorithm
+           error/unknown-pkcs-content-type
+           error/unknown-pkcs-bag-type
+           error/invalid-password
+           error/mac-verify-failed
+           error/constraint-error
+           error/warning-ia-iphf-received
+           error/warning-ia-fphf-received
+           error/ia-verify-failed
+           error/base64-encoding-error
+           error/incompatible-gcrypt-library
+           error/incompatible-crypto-library
+           error/incompatible-libtasn1-library
+           error/openpgp-keyring-error
+           error/x509-unsupported-oid
+           error/random-failed
+           error/unimplemented-feature
+
+           ;; OpenPGP keys (formerly in GnuTLS-extra)
+           openpgp-certificate? openpgp-private-key?
+           import-openpgp-certificate import-openpgp-private-key
+           openpgp-certificate-id openpgp-certificate-id!
+           openpgp-certificate-fingerprint openpgp-certificate-fingerprint!
+           openpgp-certificate-name openpgp-certificate-names
+           openpgp-certificate-algorithm openpgp-certificate-version
+           openpgp-certificate-usage
+
+           ;; OpenPGP keyrings
+           openpgp-keyring? import-openpgp-keyring
+           openpgp-keyring-contains-key-id?
+
+           ;; certificate credentials
+           set-certificate-credentials-openpgp-keys!
+
+           ;; enum->string functions
+           openpgp-certificate-format->string
+
+           ;; enum values
+           openpgp-certificate-format/raw
+           openpgp-certificate-format/base64))
+
+(define %libdir
+  (or (getenv "GNUTLS_GUILE_EXTENSION_DIR")
+      "@guileextensiondir@"))
+
+(load-extension (string-append %libdir "/guile-gnutls-v-2")
+                "scm_init_gnutls")
+
+;; Renaming.
+(define protocol/ssl-3 protocol/ssl3)
+(define protocol/tls-1.0 protocol/tls1-0)
+(define protocol/tls-1.1 protocol/tls1-1)
+
+;; Aliases.
+(define credentials/anonymous   credentials/anon)
+(define cipher/rijndael-256-cbc cipher/aes-256-cbc)
+(define cipher/rijndael-128-cbc cipher/aes-128-cbc)
+(define cipher/rijndael-cbc     cipher/aes-128-cbc)
+(define cipher/arcfour-128      cipher/arcfour)
+(define certificate-verify/allow-any-x509-v1-ca-certificate
+  certificate-verify/allow-any-x509-v1-ca-crt)
+(define certificate-verify/allow-x509-v1-ca-certificate
+  certificate-verify/allow-x509-v1-ca-crt)
+
+;;; Local Variables:
+;;; mode: scheme
+;;; coding: latin-1
+;;; End:
+
+;;; arch-tag: 3394732c-d9fa-48dd-a093-9fba3a325b8b
diff --git a/guile/modules/gnutls.scm b/guile/modules/gnutls.scm
deleted file mode 100644
index 0f4aa62..0000000
--- a/guile/modules/gnutls.scm
+++ /dev/null
@@ -1,387 +0,0 @@
-;;; GnuTLS --- Guile bindings for GnuTLS.
-;;; Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
-;;;
-;;; GnuTLS is free software; you can redistribute it and/or
-;;; modify it under the terms of the GNU Lesser General Public
-;;; License as published by the Free Software Foundation; either
-;;; version 2.1 of the License, or (at your option) any later version.
-;;;
-;;; GnuTLS is distributed in the hope that it will be useful,
-;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-;;; Lesser General Public License for more details.
-;;;
-;;; You should have received a copy of the GNU Lesser General Public
-;;; License along with GnuTLS; if not, write to the Free Software
-;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  
USA
-
-;;; Written by Ludovic Courtès <address@hidden>
-
-(define-module (gnutls)
-  ;; Note: The export list must be manually kept in sync with the build
-  ;; system.
-  :export (;; versioning
-           gnutls-version
-
-           ;; sessions
-           session?
-           make-session bye handshake rehandshake
-           alert-get alert-send
-           session-cipher session-kx session-mac session-protocol
-           session-compression-method session-certificate-type
-           session-authentication-type session-server-authentication-type
-           session-client-authentication-type
-           session-peer-certificate-chain session-our-certificate-chain
-           set-session-transport-fd! set-session-transport-port!
-           set-session-credentials! set-server-session-certificate-request!
-
-           ;; anonymous credentials
-           anonymous-client-credentials? anonymous-server-credentials?
-           make-anonymous-client-credentials make-anonymous-server-credentials
-           set-anonymous-server-dh-parameters!
-
-           ;; certificate credentials
-           certificate-credentials? make-certificate-credentials
-           set-certificate-credentials-dh-parameters!
-           set-certificate-credentials-rsa-export-parameters!
-           set-certificate-credentials-x509-key-files!
-           set-certificate-credentials-x509-trust-file!
-           set-certificate-credentials-x509-crl-file!
-           set-certificate-credentials-x509-key-data!
-           set-certificate-credentials-x509-trust-data!
-           set-certificate-credentials-x509-crl-data!
-           set-certificate-credentials-x509-keys!
-           set-certificate-credentials-verify-limits!
-           set-certificate-credentials-verify-flags!
-           peer-certificate-status
-
-           ;; SRP credentials
-           srp-client-credentials? srp-server-credentials?
-           make-srp-client-credentials make-srp-server-credentials
-           set-srp-client-credentials!
-           set-srp-server-credentials-files!
-           server-session-srp-username
-           srp-base64-encode srp-base64-decode
-
-           ;; PSK credentials
-           psk-client-credentials? psk-server-credentials?
-           make-psk-client-credentials make-psk-server-credentials
-           set-psk-client-credentials!
-           set-psk-server-credentials-file!
-           server-session-psk-username
-
-           ;; priorities
-           set-session-priorities!
-
-           ;; priority functions (deprecated)
-           set-session-cipher-priority! set-session-mac-priority!
-           set-session-compression-method-priority!
-           set-session-kx-priority! set-session-protocol-priority!
-           set-session-certificate-type-priority!
-           set-session-default-priority! set-session-default-export-priority!
-
-           ;; DH
-           set-session-dh-prime-bits!
-           make-dh-parameters dh-parameters?
-           pkcs3-import-dh-parameters pkcs3-export-dh-parameters
-
-           ;; RSA
-           make-rsa-parameters rsa-parameters?
-           pkcs1-import-rsa-parameters pkcs1-export-rsa-parameters
-
-           ;; X.509
-           x509-certificate? x509-private-key?
-           import-x509-certificate  x509-certificate-matches-hostname?
-           x509-certificate-dn x509-certificate-dn-oid
-           x509-certificate-issuer-dn x509-certificate-issuer-dn-oid
-           x509-certificate-signature-algorithm x509-certificate-version
-           x509-certificate-key-id x509-certificate-authority-key-id
-           x509-certificate-subject-key-id
-           x509-certificate-subject-alternative-name
-           x509-certificate-public-key-algorithm x509-certificate-key-usage
-           import-x509-private-key pkcs8-import-x509-private-key
-
-           ;; record layer
-           record-send record-receive!
-           session-record-port
-
-           ;; debugging
-           set-log-procedure! set-log-level!
-
-           ;; enum->string functions
-           cipher->string kx->string params->string credentials->string
-           mac->string digest->string compression-method->string
-           connection-end->string alert-level->string
-           alert-description->string handshake-description->string
-           certificate-status->string certificate-request->string
-           close-request->string
-           protocol->string certificate-type->string
-           x509-certificate-format->string
-           x509-subject-alternative-name->string pk-algorithm->string
-           sign-algorithm->string psk-key-format->string key-usage->string
-           certificate-verify->string error->string
-           cipher-suite->string
-
-           ;; enum values
-           cipher/null
-           cipher/arcfour cipher/arcfour-128
-           cipher/3des-cbc
-           cipher/aes-128-cbc cipher/rijndael-cbc cipher/rijndael-128-cbc
-           cipher/aes-256-cbc cipher/rijndael-256-cbc
-           cipher/arcfour-40
-           cipher/rc2-40-cbc
-           cipher/des-cbc
-           kx/rsa
-           kx/dhe-dss
-           kx/dhe-rsa
-           kx/anon-dh
-           kx/srp
-           kx/rsa-export
-           kx/srp-rsa
-           kx/srp-dss
-           kx/psk
-           kx/dhe-dss
-           params/rsa-export
-           params/dh
-           credentials/certificate
-           credentials/anon
-           credentials/anonymous
-           credentials/srp
-           credentials/psk
-           credentials/ia
-           mac/unknown
-           mac/null
-           mac/md5
-           mac/sha1
-           mac/rmd160
-           mac/md2
-           digest/null
-           digest/md5
-           digest/sha1
-           digest/rmd160
-           digest/md2
-           compression-method/null
-           compression-method/deflate
-           compression-method/lzo
-           connection-end/server
-           connection-end/client
-           alert-level/warning
-           alert-level/fatal
-           alert-description/close-notify
-           alert-description/unexpected-message
-           alert-description/bad-record-mac
-           alert-description/decryption-failed
-           alert-description/record-overflow
-           alert-description/decompression-failure
-           alert-description/handshake-failure
-           alert-description/ssl3-no-certificate
-           alert-description/bad-certificate
-           alert-description/unsupported-certificate
-           alert-description/certificate-revoked
-           alert-description/certificate-expired
-           alert-description/certificate-unknown
-           alert-description/illegal-parameter
-           alert-description/unknown-ca
-           alert-description/access-denied
-           alert-description/decode-error
-           alert-description/decrypt-error
-           alert-description/export-restriction
-           alert-description/protocol-version
-           alert-description/insufficient-security
-           alert-description/internal-error
-           alert-description/user-canceled
-           alert-description/no-renegotiation
-           alert-description/unsupported-extension
-           alert-description/certificate-unobtainable
-           alert-description/unrecognized-name
-           alert-description/unknown-psk-identity
-           alert-description/inner-application-failure
-           alert-description/inner-application-verification
-           handshake-description/hello-request
-           handshake-description/client-hello
-           handshake-description/server-hello
-           handshake-description/certificate-pkt
-           handshake-description/server-key-exchange
-           handshake-description/certificate-request
-           handshake-description/server-hello-done
-           handshake-description/certificate-verify
-           handshake-description/client-key-exchange
-           handshake-description/finished
-           certificate-status/invalid
-           certificate-status/revoked
-           certificate-status/signer-not-found
-           certificate-status/signer-not-ca
-           certificate-status/insecure-algorithm
-           certificate-request/ignore
-           certificate-request/request
-           certificate-request/require
-           close-request/rdwr
-           close-request/wr
-           protocol/ssl-3
-           protocol/tls-1.0
-           protocol/tls-1.1
-           protocol/version-unknown
-           certificate-type/x509
-           certificate-type/openpgp
-           x509-certificate-format/der
-           x509-certificate-format/pem
-           x509-subject-alternative-name/dnsname
-           x509-subject-alternative-name/rfc822name
-           x509-subject-alternative-name/uri
-           x509-subject-alternative-name/ipaddress
-           pk-algorithm/rsa
-           pk-algorithm/dsa
-           pk-algorithm/unknown
-           sign-algorithm/unknown
-           sign-algorithm/rsa-sha1
-           sign-algorithm/dsa-sha1
-           sign-algorithm/rsa-md5
-           sign-algorithm/rsa-md2
-           sign-algorithm/rsa-rmd160
-           psk-key-format/raw
-           psk-key-format/hex
-           key-usage/digital-signature
-           key-usage/non-repudiation
-           key-usage/key-encipherment
-           key-usage/data-encipherment
-           key-usage/key-agreement
-           key-usage/key-cert-sign
-           key-usage/crl-sign
-           key-usage/encipher-only
-           key-usage/decipher-only
-           certificate-verify/disable-ca-sign
-           certificate-verify/allow-x509-v1-ca-crt
-           certificate-verify/allow-x509-v1-ca-certificate
-           certificate-verify/do-not-allow-same
-           certificate-verify/allow-any-x509-v1-ca-crt
-           certificate-verify/allow-any-x509-v1-ca-certificate
-           certificate-verify/allow-sign-rsa-md2
-           certificate-verify/allow-sign-rsa-md5
-
-           error/success
-           error/unknown-compression-algorithm
-           error/unknown-cipher-type
-           error/large-packet
-           error/unsupported-version-packet
-           error/unexpected-packet-length
-           error/invalid-session
-           error/fatal-alert-received
-           error/unexpected-packet
-           error/warning-alert-received
-           error/error-in-finished-packet
-           error/unexpected-handshake-packet
-           error/unknown-cipher-suite
-           error/unwanted-algorithm
-           error/mpi-scan-failed
-           error/decryption-failed
-           error/memory-error
-           error/decompression-failed
-           error/compression-failed
-           error/again
-           error/expired
-           error/db-error
-           error/srp-pwd-error
-           error/insufficient-credentials
-           error/insuficient-credentials
-           error/insufficient-cred
-           error/insuficient-cred
-           error/hash-failed
-           error/base64-decoding-error
-           error/mpi-print-failed
-           error/rehandshake
-           error/got-application-data
-           error/record-limit-reached
-           error/encryption-failed
-           error/pk-encryption-failed
-           error/pk-decryption-failed
-           error/pk-sign-failed
-           error/x509-unsupported-critical-extension
-           error/key-usage-violation
-           error/no-certificate-found
-           error/invalid-request
-           error/short-memory-buffer
-           error/interrupted
-           error/push-error
-           error/pull-error
-           error/received-illegal-parameter
-           error/requested-data-not-available
-           error/pkcs1-wrong-pad
-           error/received-illegal-extension
-           error/internal-error
-           error/dh-prime-unacceptable
-           error/file-error
-           error/too-many-empty-packets
-           error/unknown-pk-algorithm
-           error/init-libextra
-           error/library-version-mismatch
-           error/no-temporary-rsa-params
-           error/lzo-init-failed
-           error/no-compression-algorithms
-           error/no-cipher-suites
-           error/openpgp-getkey-failed
-           error/pk-sig-verify-failed
-           error/illegal-srp-username
-           error/srp-pwd-parsing-error
-           error/no-temporary-dh-params
-           error/asn1-element-not-found
-           error/asn1-identifier-not-found
-           error/asn1-der-error
-           error/asn1-value-not-found
-           error/asn1-generic-error
-           error/asn1-value-not-valid
-           error/asn1-tag-error
-           error/asn1-tag-implicit
-           error/asn1-type-any-error
-           error/asn1-syntax-error
-           error/asn1-der-overflow
-           error/openpgp-uid-revoked
-           error/certificate-error
-           error/x509-certificate-error
-           error/certificate-key-mismatch
-           error/unsupported-certificate-type
-           error/x509-unknown-san
-           error/openpgp-fingerprint-unsupported
-           error/x509-unsupported-attribute
-           error/unknown-algorithm
-           error/unknown-hash-algorithm
-           error/unknown-pkcs-content-type
-           error/unknown-pkcs-bag-type
-           error/invalid-password
-           error/mac-verify-failed
-           error/constraint-error
-           error/warning-ia-iphf-received
-           error/warning-ia-fphf-received
-           error/ia-verify-failed
-           error/base64-encoding-error
-           error/incompatible-gcrypt-library
-           error/incompatible-crypto-library
-           error/incompatible-libtasn1-library
-           error/openpgp-keyring-error
-           error/x509-unsupported-oid
-           error/random-failed
-           error/unimplemented-feature))
-
-(load-extension "libguile-gnutls-v-1" "scm_init_gnutls")
-
-;; Renaming.
-(define protocol/ssl-3 protocol/ssl3)
-(define protocol/tls-1.0 protocol/tls1-0)
-(define protocol/tls-1.1 protocol/tls1-1)
-
-;; Aliases.
-(define credentials/anonymous   credentials/anon)
-(define cipher/rijndael-256-cbc cipher/aes-256-cbc)
-(define cipher/rijndael-128-cbc cipher/aes-128-cbc)
-(define cipher/rijndael-cbc     cipher/aes-128-cbc)
-(define cipher/arcfour-128      cipher/arcfour)
-(define certificate-verify/allow-any-x509-v1-ca-certificate
-  certificate-verify/allow-any-x509-v1-ca-crt)
-(define certificate-verify/allow-x509-v1-ca-certificate
-  certificate-verify/allow-x509-v1-ca-crt)
-
-;;; Local Variables:
-;;; mode: scheme
-;;; coding: latin-1
-;;; End:
-
-;;; arch-tag: 3394732c-d9fa-48dd-a093-9fba3a325b8b
diff --git a/guile/modules/gnutls/build/enums.scm 
b/guile/modules/gnutls/build/enums.scm
index 93293f2..5277646 100644
--- a/guile/modules/gnutls/build/enums.scm
+++ b/guile/modules/gnutls/build/enums.scm
@@ -36,7 +36,7 @@
            %cipher-enum %mac-enum %compression-method-enum %kx-enum
            %protocol-enum %certificate-type-enum
 
-           %gnutls-enums %gnutls-extra-enums))
+           %gnutls-enums))
 
 ;;;
 ;;; This module helps with the creation of bindings for the C enumerate
@@ -513,8 +513,6 @@ dh-prime-unacceptable
 file-error
 too-many-empty-packets
 unknown-pk-algorithm
-init-libextra
-library-version-mismatch
 no-temporary-rsa-params
 no-compression-algorithms
 no-cipher-suites
@@ -581,11 +579,9 @@ unimplemented-feature)
         %x509-certificate-format-enum %x509-subject-alternative-name-enum
         %pk-algorithm-enum %sign-algorithm-enum
         %psk-key-format-enum %key-usage-enum %certificate-verify-enum
-        %error-enum))
+        %error-enum
 
-(define %gnutls-extra-enums
-  ;; All enums for GnuTLS-extra (GPL).
-  (list %openpgp-certificate-format-enum))
+        %openpgp-certificate-format-enum))
 
 ;;; Local Variables:
 ;;; mode: scheme
diff --git a/guile/modules/gnutls/build/smobs.scm 
b/guile/modules/gnutls/build/smobs.scm
index f20e223..8df455a 100644
--- a/guile/modules/gnutls/build/smobs.scm
+++ b/guile/modules/gnutls/build/smobs.scm
@@ -1,7 +1,7 @@
 ;;; Help produce Guile wrappers for GnuTLS types.
 ;;;
 ;;; GnuTLS --- Guile bindings for GnuTLS.
-;;; Copyright (C) 2007, 2010 Free Software Foundation, Inc.
+;;; Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
 ;;;
 ;;; GnuTLS is free software; you can redistribute it and/or
 ;;; modify it under the terms of the GNU Lesser General Public
@@ -31,7 +31,7 @@
            output-smob-type-predicate
            output-c->smob-converter output-smob->c-converter
 
-           %gnutls-smobs %gnutls-extra-smobs))
+           %gnutls-smobs))
 
 
 ;;;
@@ -222,11 +222,9 @@
         %certificate-credentials-smob
         %srp-server-credentials-smob %srp-client-credentials-smob
         %psk-server-credentials-smob %psk-client-credentials-smob
-        %x509-certificate-smob %x509-private-key-smob))
+        %x509-certificate-smob %x509-private-key-smob
 
-(define %gnutls-extra-smobs
-  ;; All SMOB types for GnuTLS-extra (GPL).
-  (list %openpgp-certificate-smob %openpgp-private-key-smob
+        %openpgp-certificate-smob %openpgp-private-key-smob
         %openpgp-keyring-smob))
 
 
diff --git a/guile/modules/gnutls/extra.scm b/guile/modules/gnutls/extra.scm
index b47f490..be8f7bb 100644
--- a/guile/modules/gnutls/extra.scm
+++ b/guile/modules/gnutls/extra.scm
@@ -1,5 +1,5 @@
 ;;; GnuTLS-extra --- Guile bindings for GnuTLS-EXTRA.
-;;; Copyright (C) 2007, 2010 Free Software Foundation, Inc.
+;;; Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
 ;;;
 ;;; GnuTLS-extra is free software; you can redistribute it and/or modify
 ;;; it under the terms of the GNU General Public License as published by
@@ -20,12 +20,9 @@
 
 (define-module (gnutls extra)
 
-;;; Important note: As written above, this part of the code is ditributed
-;;; under the GPL, not the LGPL.
-
   :use-module (gnutls)
 
-  :export (;; OpenPGP keys
+  :re-export (;; OpenPGP keys
            openpgp-certificate? openpgp-private-key?
            import-openpgp-certificate import-openpgp-private-key
            openpgp-certificate-id openpgp-certificate-id!
@@ -49,7 +46,13 @@
            openpgp-certificate-format/base64))
 
 
-(load-extension "libguile-gnutls-extra-v-1" "scm_init_gnutls_extra")
+
+;;;
+;;; This module will be removed in a future version.
+;;;
+
+(issue-deprecation-warning
+ "The (gnutls extra) module is deprecated; use (gnutls) instead")
 
 
 ;;;
diff --git a/guile/pre-inst-guile.in b/guile/pre-inst-guile.in
index b078b74..12789d7 100644
--- a/guile/pre-inst-guile.in
+++ b/guile/pre-inst-guile.in
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright (C) 2007, 2010 Free Software Foundation, Inc.
+# Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -23,7 +23,9 @@
 GUILE_LOAD_PATH="@abs_top_srcdir@/guile/modules:$GUILE_LOAD_PATH"
 export GUILE_LOAD_PATH
 
+GNUTLS_GUILE_EXTENSION_DIR="@abs_top_srcdir@/guile/src"
+export GNUTLS_GUILE_EXTENSION_DIR
+
 exec @abs_top_builddir@/libtool --mode=execute                             \
-       -dlopen "@abs_top_builddir@/guile/src/libguile-gnutls-v-1.la"        \
-       -dlopen "@abs_top_builddir@/guile/src/libguile-gnutls-extra-v-1.la"  \
+       -dlopen "@abs_top_builddir@/guile/src/guile-gnutls-v-2.la"        \
        @GUILE@ "$@"
diff --git a/guile/src/Makefile.am b/guile/src/Makefile.am
index bc47807..06d24e0 100644
--- a/guile/src/Makefile.am
+++ b/guile/src/Makefile.am
@@ -1,5 +1,5 @@
 #  GnuTLS --- Guile bindings for GnuTLS.
-#  Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+#  Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 #
 #  GnuTLS is free software; you can redistribute it and/or
 #  modify it under the terms of the GNU Lesser General Public
@@ -27,42 +27,32 @@ EXTRA_DIST =                                        \
 
 BUILT_SOURCES = enum-map.i.c smob-types.i.c enums.h smobs.h    \
                priorities.i.c                                  \
-               extra-smobs.h extra-enums.h                     \
-               extra-enum-map.i.c extra-smob-types.i.c         \
-                core.x errors.x extra.x
+                core.x errors.x
 
 CLEANFILES = $(BUILT_SOURCES)
 
-lib_LTLIBRARIES = libguile-gnutls-v-1.la libguile-gnutls-extra-v-1.la
+guileextension_LTLIBRARIES  = guile-gnutls-v-2.la
+guile_gnutls_v_2_la_LDFLAGS = -module
 
 # Linking against GnuTLS.
 GNUTLS_CORE_LIBS  = $(top_builddir)/lib/libgnutls.la
-GNUTLS_EXTRA_LIBS = $(top_builddir)/libextra/libgnutls-extra.la
 
 # Linking against Gnulib modules.
 GNULIB_LIBS    = $(top_builddir)/gl/libgnu.la
 GNULIB_CFLAGS  = -I$(top_builddir)/gl -I$(top_srcdir)/gl
 
 
-libguile_gnutls_v_1_la_SOURCES = core.c errors.c utils.c
-libguile_gnutls_v_1_la_CFLAGS =                        \
+guile_gnutls_v_2_la_SOURCES = core.c errors.c utils.c
+guile_gnutls_v_2_la_CFLAGS =                   \
   $(AM_CFLAGS) $(GNULIB_CFLAGS) $(GUILE_CFLAGS)
-libguile_gnutls_v_1_la_LIBADD = \
+guile_gnutls_v_2_la_LIBADD = \
        $(GNUTLS_CORE_LIBS) $(GNULIB_LIBS) \
        $(GUILE_LDFLAGS)
 
-libguile_gnutls_extra_v_1_la_SOURCES = extra.c
-libguile_gnutls_extra_v_1_la_CFLAGS =          \
-  $(AM_CFLAGS) $(GNULIB_CFLAGS) $(GUILE_CFLAGS)
-libguile_gnutls_extra_v_1_la_LIBADD =          \
-  $(GNUTLS_CORE_LIBS) $(GNUTLS_EXTRA_LIBS)     \
-  $(builddir)/libguile-gnutls-v-1.la           \
-  $(GNULIB_LIBS) $(GUILE_LDFLAGS)
-
 AM_CPPFLAGS = \
        -I$(top_srcdir)/lib/includes \
        -I$(top_builddir)/lib/includes  \
-       -I$(top_srcdir)/libextra/includes \
+       -I$(top_srcdir)/extra/includes \
        -I$(top_builddir) \
        -I$(builddir)
 
@@ -100,21 +90,6 @@ priorities.i.c: $(srcdir)/make-session-priorities.scm
        $(GUILE_FOR_BUILD) $^ > $@
 
 
-# GnuTLS-extra
-
-extra-enums.h: $(srcdir)/make-enum-header.scm
-       $(GUILE_FOR_BUILD) $^ extra > $@
-
-extra-enum-map.i.c: $(srcdir)/make-enum-map.scm
-       $(GUILE_FOR_BUILD) $^ extra > $@
-
-extra-smobs.h: $(srcdir)/make-smob-header.scm
-       $(GUILE_FOR_BUILD) $^ extra > $@
-
-extra-smob-types.i.c: $(srcdir)/make-smob-types.scm
-       $(GUILE_FOR_BUILD) $^ extra > $@
-
-
 # C file snarfing.
 
 # `$(GUILE_CFLAGS)' may contain a series of `-I' switches so it must be
diff --git a/guile/src/core.c b/guile/src/core.c
index ba9ffab..3b81268 100644
--- a/guile/src/core.c
+++ b/guile/src/core.c
@@ -25,6 +25,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <gnutls/gnutls.h>
+#include <gnutls/openpgp.h>
 #include <libguile.h>
 
 #include <alloca.h>
@@ -2795,6 +2796,495 @@ SCM_DEFINE 
(scm_gnutls_x509_certificate_subject_alternative_name,
 #undef FUNC_NAME
 
 
+/* OpenPGP keys.  */
+
+
+/* Maximum size we support for the name of OpenPGP keys.  */
+#define GUILE_GNUTLS_MAX_OPENPGP_NAME_LENGTH  2048
+
+SCM_DEFINE (scm_gnutls_import_openpgp_certificate,
+            "import-openpgp-certificate", 2, 0, 0, (SCM data, SCM format),
+            "Return a new OpenPGP certificate object resulting from the "
+            "import of @var{data} (a uniform array) according to "
+            "@var{format}.")
+#define FUNC_NAME s_scm_gnutls_import_openpgp_certificate
+{
+  int err;
+  gnutls_openpgp_crt_t c_key;
+  gnutls_openpgp_crt_fmt_t c_format;
+  gnutls_datum_t c_data_d;
+  scm_t_array_handle c_data_handle;
+  const char *c_data;
+  size_t c_data_len;
+
+  SCM_VALIDATE_ARRAY (1, data);
+  c_format = scm_to_gnutls_openpgp_certificate_format (format, 2, FUNC_NAME);
+
+  c_data = scm_gnutls_get_array (data, &c_data_handle, &c_data_len,
+                                 FUNC_NAME);
+  c_data_d.data = (unsigned char *) c_data;
+  c_data_d.size = c_data_len;
+
+  err = gnutls_openpgp_crt_init (&c_key);
+  if (EXPECT_FALSE (err))
+    {
+      scm_gnutls_release_array (&c_data_handle);
+      scm_gnutls_error (err, FUNC_NAME);
+    }
+
+  err = gnutls_openpgp_crt_import (c_key, &c_data_d, c_format);
+  scm_gnutls_release_array (&c_data_handle);
+
+  if (EXPECT_FALSE (err))
+    {
+      gnutls_openpgp_crt_deinit (c_key);
+      scm_gnutls_error (err, FUNC_NAME);
+    }
+
+  return (scm_from_gnutls_openpgp_certificate (c_key));
+}
+
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_gnutls_import_openpgp_private_key,
+            "import-openpgp-private-key", 2, 1, 0, (SCM data, SCM format,
+                                                    SCM pass),
+            "Return a new OpenPGP private key object resulting from the "
+            "import of @var{data} (a uniform array) according to "
+            "@var{format}.  Optionally, a passphrase may be provided.")
+#define FUNC_NAME s_scm_gnutls_import_openpgp_private_key
+{
+  int err;
+  gnutls_openpgp_privkey_t c_key;
+  gnutls_openpgp_crt_fmt_t c_format;
+  gnutls_datum_t c_data_d;
+  scm_t_array_handle c_data_handle;
+  const char *c_data;
+  char *c_pass;
+  size_t c_data_len, c_pass_len;
+
+  SCM_VALIDATE_ARRAY (1, data);
+  c_format = scm_to_gnutls_openpgp_certificate_format (format, 2, FUNC_NAME);
+  if ((pass == SCM_UNDEFINED) || (scm_is_false (pass)))
+    c_pass = NULL;
+  else
+    {
+      c_pass_len = scm_c_string_length (pass);
+      c_pass = (char *) alloca (c_pass_len + 1);
+      (void) scm_to_locale_stringbuf (pass, c_pass, c_pass_len + 1);
+      c_pass[c_pass_len] = '\0';
+    }
+
+  c_data = scm_gnutls_get_array (data, &c_data_handle, &c_data_len,
+                                 FUNC_NAME);
+  c_data_d.data = (unsigned char *) c_data;
+  c_data_d.size = c_data_len;
+
+  err = gnutls_openpgp_privkey_init (&c_key);
+  if (EXPECT_FALSE (err))
+    {
+      scm_gnutls_release_array (&c_data_handle);
+      scm_gnutls_error (err, FUNC_NAME);
+    }
+
+  err = gnutls_openpgp_privkey_import (c_key, &c_data_d, c_format, c_pass,
+                                       0 /* currently unused */ );
+  scm_gnutls_release_array (&c_data_handle);
+
+  if (EXPECT_FALSE (err))
+    {
+      gnutls_openpgp_privkey_deinit (c_key);
+      scm_gnutls_error (err, FUNC_NAME);
+    }
+
+  return (scm_from_gnutls_openpgp_private_key (c_key));
+}
+
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_gnutls_openpgp_certificate_id, "openpgp-certificate-id",
+            1, 0, 0,
+            (SCM key),
+            "Return the ID (an 8-element u8vector) of certificate "
+            "@var{key}.")
+#define FUNC_NAME s_scm_gnutls_openpgp_certificate_id
+{
+  int err;
+  unsigned char *c_id;
+  gnutls_openpgp_crt_t c_key;
+
+  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
+
+  c_id = (unsigned char *) malloc (8);
+  if (c_id == NULL)
+    scm_gnutls_error (GNUTLS_E_MEMORY_ERROR, FUNC_NAME);
+
+  err = gnutls_openpgp_crt_get_key_id (c_key, c_id);
+  if (EXPECT_FALSE (err))
+    scm_gnutls_error (err, FUNC_NAME);
+
+  return (scm_take_u8vector (c_id, 8));
+}
+
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_gnutls_openpgp_certificate_id_x, "openpgp-certificate-id!",
+            2, 0, 0,
+            (SCM key, SCM id),
+            "Store the ID (an 8 byte sequence) of certificate "
+            "@var{key} in @var{id} (a u8vector).")
+#define FUNC_NAME s_scm_gnutls_openpgp_certificate_id_x
+{
+  int err;
+  char *c_id;
+  scm_t_array_handle c_id_handle;
+  size_t c_id_size;
+  gnutls_openpgp_crt_t c_key;
+
+  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
+  c_id = scm_gnutls_get_writable_array (id, &c_id_handle, &c_id_size,
+                                        FUNC_NAME);
+
+  if (EXPECT_FALSE (c_id_size < 8))
+    {
+      scm_gnutls_release_array (&c_id_handle);
+      scm_misc_error (FUNC_NAME, "ID vector too small: ~A", scm_list_1 (id));
+    }
+
+  err = gnutls_openpgp_crt_get_key_id (c_key, (unsigned char *) c_id);
+  scm_gnutls_release_array (&c_id_handle);
+
+  if (EXPECT_FALSE (err))
+    scm_gnutls_error (err, FUNC_NAME);
+
+  return SCM_UNSPECIFIED;
+}
+
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_gnutls_openpgp_certificate_fingerpint_x,
+            "openpgp-certificate-fingerprint!",
+            2, 0, 0,
+            (SCM key, SCM fpr),
+            "Store in @var{fpr} (a u8vector) the fingerprint of @var{key}.  "
+            "Return the number of bytes stored in @var{fpr}.")
+#define FUNC_NAME s_scm_gnutls_openpgp_certificate_fingerpint_x
+{
+  int err;
+  gnutls_openpgp_crt_t c_key;
+  char *c_fpr;
+  scm_t_array_handle c_fpr_handle;
+  size_t c_fpr_len, c_actual_len = 0;
+
+  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
+  SCM_VALIDATE_ARRAY (2, fpr);
+
+  c_fpr = scm_gnutls_get_writable_array (fpr, &c_fpr_handle, &c_fpr_len,
+                                         FUNC_NAME);
+
+  err = gnutls_openpgp_crt_get_fingerprint (c_key, c_fpr, &c_actual_len);
+  scm_gnutls_release_array (&c_fpr_handle);
+
+  if (EXPECT_FALSE (err))
+    scm_gnutls_error (err, FUNC_NAME);
+
+  return (scm_from_size_t (c_actual_len));
+}
+
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_gnutls_openpgp_certificate_fingerprint,
+            "openpgp-certificate-fingerprint",
+            1, 0, 0,
+            (SCM key),
+            "Return a new u8vector denoting the fingerprint of " "@var{key}.")
+#define FUNC_NAME s_scm_gnutls_openpgp_certificate_fingerprint
+{
+  int err;
+  gnutls_openpgp_crt_t c_key;
+  unsigned char *c_fpr;
+  size_t c_fpr_len, c_actual_len;
+
+  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
+
+  /* V4 fingerprints are 160-bit SHA-1 hashes (see RFC2440).  */
+  c_fpr_len = 20;
+  c_fpr = (unsigned char *) malloc (c_fpr_len);
+  if (EXPECT_FALSE (c_fpr == NULL))
+    scm_gnutls_error (GNUTLS_E_MEMORY_ERROR, FUNC_NAME);
+
+  do
+    {
+      c_actual_len = 0;
+      err = gnutls_openpgp_crt_get_fingerprint (c_key, c_fpr, &c_actual_len);
+      if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
+        {
+          /* Grow C_FPR.  */
+          unsigned char *c_new;
+
+          c_new = (unsigned char *) realloc (c_fpr, c_fpr_len * 2);
+          if (EXPECT_FALSE (c_new == NULL))
+            {
+              free (c_fpr);
+              scm_gnutls_error (GNUTLS_E_MEMORY_ERROR, FUNC_NAME);
+            }
+          else
+            {
+              c_fpr_len *= 2;
+              c_fpr = c_new;
+            }
+        }
+    }
+  while (err == GNUTLS_E_SHORT_MEMORY_BUFFER);
+
+  if (EXPECT_FALSE (err))
+    {
+      free (c_fpr);
+      scm_gnutls_error (err, FUNC_NAME);
+    }
+
+  if (c_actual_len < c_fpr_len)
+    /* Shrink C_FPR.  */
+    c_fpr = realloc (c_fpr, c_actual_len);
+
+  return (scm_take_u8vector (c_fpr, c_actual_len));
+}
+
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_gnutls_openpgp_certificate_name, "openpgp-certificate-name",
+            2, 0, 0,
+            (SCM key, SCM index),
+            "Return the @var{index}th name of @var{key}.")
+#define FUNC_NAME s_scm_gnutls_openpgp_certificate_name
+{
+  int err;
+  gnutls_openpgp_crt_t c_key;
+  int c_index;
+  char c_name[GUILE_GNUTLS_MAX_OPENPGP_NAME_LENGTH];
+  size_t c_name_len = sizeof (c_name);
+
+  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
+  c_index = scm_to_int (index);
+
+  err = gnutls_openpgp_crt_get_name (c_key, c_index, c_name, &c_name_len);
+  if (EXPECT_FALSE (err))
+    scm_gnutls_error (err, FUNC_NAME);
+
+  /* XXX: The name is really UTF-8.  */
+  return (scm_from_locale_string (c_name));
+}
+
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_gnutls_openpgp_certificate_names, "openpgp-certificate-names",
+            1, 0, 0, (SCM key), "Return the list of names for @var{key}.")
+#define FUNC_NAME s_scm_gnutls_openpgp_certificate_names
+{
+  int err;
+  SCM result = SCM_EOL;
+  gnutls_openpgp_crt_t c_key;
+  int c_index = 0;
+  char c_name[GUILE_GNUTLS_MAX_OPENPGP_NAME_LENGTH];
+  size_t c_name_len = sizeof (c_name);
+
+  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
+
+  do
+    {
+      err = gnutls_openpgp_crt_get_name (c_key, c_index, c_name, &c_name_len);
+      if (!err)
+        {
+          result = scm_cons (scm_from_locale_string (c_name), result);
+          c_index++;
+        }
+    }
+  while (!err);
+
+  if (EXPECT_FALSE (err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE))
+    scm_gnutls_error (err, FUNC_NAME);
+
+  return (scm_reverse_x (result, SCM_EOL));
+}
+
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_gnutls_openpgp_certificate_algorithm,
+            "openpgp-certificate-algorithm",
+            1, 0, 0,
+            (SCM key),
+            "Return two values: the certificate algorithm used by "
+            "@var{key} and the number of bits used.")
+#define FUNC_NAME s_scm_gnutls_openpgp_certificate_algorithm
+{
+  gnutls_openpgp_crt_t c_key;
+  unsigned int c_bits;
+  gnutls_pk_algorithm_t c_algo;
+
+  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
+  c_algo = gnutls_openpgp_crt_get_pk_algorithm (c_key, &c_bits);
+
+  return (scm_values (scm_list_2 (scm_from_gnutls_pk_algorithm (c_algo),
+                                  scm_from_uint (c_bits))));
+}
+
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_gnutls_openpgp_certificate_version,
+            "openpgp-certificate-version",
+            1, 0, 0,
+            (SCM key),
+            "Return the version of the OpenPGP message format (RFC2440) "
+            "honored by @var{key}.")
+#define FUNC_NAME s_scm_gnutls_openpgp_certificate_version
+{
+  int c_version;
+  gnutls_openpgp_crt_t c_key;
+
+  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
+  c_version = gnutls_openpgp_crt_get_version (c_key);
+
+  return (scm_from_int (c_version));
+}
+
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_gnutls_openpgp_certificate_usage, "openpgp-certificate-usage",
+            1, 0, 0,
+            (SCM key),
+            "Return a list of values denoting the key usage of @var{key}.")
+#define FUNC_NAME s_scm_gnutls_openpgp_certificate_usage
+{
+  int err;
+  unsigned int c_usage = 0;
+  gnutls_openpgp_crt_t c_key;
+
+  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
+
+  err = gnutls_openpgp_crt_get_key_usage (c_key, &c_usage);
+  if (EXPECT_FALSE (err))
+    scm_gnutls_error (err, FUNC_NAME);
+
+  return (scm_from_gnutls_key_usage_flags (c_usage));
+}
+
+#undef FUNC_NAME
+
+
+
+/* OpenPGP keyrings.  */
+
+SCM_DEFINE (scm_gnutls_import_openpgp_keyring, "import-openpgp-keyring",
+            2, 0, 0,
+            (SCM data, SCM format),
+            "Import @var{data} (a u8vector) according to @var{format} "
+            "and return the imported keyring.")
+#define FUNC_NAME s_scm_gnutls_import_openpgp_keyring
+{
+  int err;
+  gnutls_openpgp_keyring_t c_keyring;
+  gnutls_openpgp_crt_fmt_t c_format;
+  gnutls_datum_t c_data_d;
+  scm_t_array_handle c_data_handle;
+  const char *c_data;
+  size_t c_data_len;
+
+  SCM_VALIDATE_ARRAY (1, data);
+  c_format = scm_to_gnutls_openpgp_certificate_format (format, 2, FUNC_NAME);
+
+  c_data = scm_gnutls_get_array (data, &c_data_handle, &c_data_len,
+                                 FUNC_NAME);
+
+  c_data_d.data = (unsigned char *) c_data;
+  c_data_d.size = c_data_len;
+
+  err = gnutls_openpgp_keyring_init (&c_keyring);
+  if (EXPECT_FALSE (err))
+    {
+      scm_gnutls_release_array (&c_data_handle);
+      scm_gnutls_error (err, FUNC_NAME);
+    }
+
+  err = gnutls_openpgp_keyring_import (c_keyring, &c_data_d, c_format);
+  scm_gnutls_release_array (&c_data_handle);
+
+  if (EXPECT_FALSE (err))
+    {
+      gnutls_openpgp_keyring_deinit (c_keyring);
+      scm_gnutls_error (err, FUNC_NAME);
+    }
+
+  return (scm_from_gnutls_openpgp_keyring (c_keyring));
+}
+
+#undef FUNC_NAME
+
+SCM_DEFINE (scm_gnutls_openpgp_keyring_contains_key_id_p,
+            "openpgp-keyring-contains-key-id?",
+            2, 0, 0,
+            (SCM keyring, SCM id),
+            "Return @code{#f} if key ID @var{id} is in @var{keyring}, "
+            "@code{#f} otherwise.")
+#define FUNC_NAME s_scm_gnutls_openpgp_keyring_contains_key_id_p
+{
+  int c_result;
+  gnutls_openpgp_keyring_t c_keyring;
+  scm_t_array_handle c_id_handle;
+  const char *c_id;
+  size_t c_id_len;
+
+  c_keyring = scm_to_gnutls_openpgp_keyring (keyring, 1, FUNC_NAME);
+  SCM_VALIDATE_ARRAY (1, id);
+
+  c_id = scm_gnutls_get_array (id, &c_id_handle, &c_id_len, FUNC_NAME);
+  if (EXPECT_FALSE (c_id_len != 8))
+    {
+      scm_gnutls_release_array (&c_id_handle);
+      scm_wrong_type_arg (FUNC_NAME, 1, id);
+    }
+
+  c_result = gnutls_openpgp_keyring_check_id (c_keyring,
+                                              (unsigned char *) c_id,
+                                              0 /* unused */ );
+
+  scm_gnutls_release_array (&c_id_handle);
+
+  return (scm_from_bool (c_result == 0));
+}
+
+#undef FUNC_NAME
+
+
+/* OpenPGP certificates.  */
+
+SCM_DEFINE (scm_gnutls_set_certificate_credentials_openpgp_keys_x,
+            "set-certificate-credentials-openpgp-keys!",
+            3, 0, 0,
+            (SCM cred, SCM pub, SCM sec),
+            "Use certificate @var{pub} and secret key @var{sec} in "
+            "certificate credentials @var{cred}.")
+#define FUNC_NAME s_scm_gnutls_set_certificate_credentials_openpgp_keys_x
+{
+  int err;
+  gnutls_certificate_credentials_t c_cred;
+  gnutls_openpgp_crt_t c_pub;
+  gnutls_openpgp_privkey_t c_sec;
+
+  c_cred = scm_to_gnutls_certificate_credentials (cred, 1, FUNC_NAME);
+  c_pub = scm_to_gnutls_openpgp_certificate (pub, 2, FUNC_NAME);
+  c_sec = scm_to_gnutls_openpgp_private_key (sec, 3, FUNC_NAME);
+
+  err = gnutls_certificate_set_openpgp_key (c_cred, c_pub, c_sec);
+  if (EXPECT_FALSE (err))
+    scm_gnutls_error (err, FUNC_NAME);
+
+  return SCM_UNSPECIFIED;
+}
+
+#undef FUNC_NAME
+
+
+
 /* Debugging.  */
 
 static SCM log_procedure = SCM_BOOL_F;
diff --git a/guile/src/extra.c b/guile/src/extra.c
deleted file mode 100644
index 1cbbb88..0000000
--- a/guile/src/extra.c
+++ /dev/null
@@ -1,551 +0,0 @@
-/* GnuTLS-extra --- Guile bindings for GnuTLS-extra.
-   Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
-
-   GnuTLS-extra is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3 of the License, or
-   (at your option) any later version.
-
-   GnuTLS-extra is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with GnuTLS-EXTRA; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 
USA.  */
-
-/* Important note: As written above, this part of the code is ditributed
-   under the GPL, not the LGPL.  */
-
-/* Written by Ludovic Courtès <address@hidden>.  */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <gnutls/gnutls.h>
-#include <gnutls/extra.h>
-#include <gnutls/openpgp.h>
-#include <libguile.h>
-
-#include <alloca.h>
-
-#include "errors.h"
-#include "utils.h"
-#include "smobs.h"
-#include "enums.h"
-#include "extra-enums.h"
-#include "extra-smobs.h"
-
-
-
-/* SMOB and enums type definitions.  */
-
-#include "extra-smob-types.i.c"
-#include "extra-enum-map.i.c"
-
-
-/* OpenPGP keys.  */
-
-
-/* Maximum size we support for the name of OpenPGP keys.  */
-#define GUILE_GNUTLS_MAX_OPENPGP_NAME_LENGTH  2048
-
-SCM_DEFINE (scm_gnutls_import_openpgp_certificate,
-            "import-openpgp-certificate", 2, 0, 0, (SCM data, SCM format),
-            "Return a new OpenPGP certificate object resulting from the "
-            "import of @var{data} (a uniform array) according to "
-            "@var{format}.")
-#define FUNC_NAME s_scm_gnutls_import_openpgp_certificate
-{
-  int err;
-  gnutls_openpgp_crt_t c_key;
-  gnutls_openpgp_crt_fmt_t c_format;
-  gnutls_datum_t c_data_d;
-  scm_t_array_handle c_data_handle;
-  const char *c_data;
-  size_t c_data_len;
-
-  SCM_VALIDATE_ARRAY (1, data);
-  c_format = scm_to_gnutls_openpgp_certificate_format (format, 2, FUNC_NAME);
-
-  c_data = scm_gnutls_get_array (data, &c_data_handle, &c_data_len,
-                                 FUNC_NAME);
-  c_data_d.data = (unsigned char *) c_data;
-  c_data_d.size = c_data_len;
-
-  err = gnutls_openpgp_crt_init (&c_key);
-  if (EXPECT_FALSE (err))
-    {
-      scm_gnutls_release_array (&c_data_handle);
-      scm_gnutls_error (err, FUNC_NAME);
-    }
-
-  err = gnutls_openpgp_crt_import (c_key, &c_data_d, c_format);
-  scm_gnutls_release_array (&c_data_handle);
-
-  if (EXPECT_FALSE (err))
-    {
-      gnutls_openpgp_crt_deinit (c_key);
-      scm_gnutls_error (err, FUNC_NAME);
-    }
-
-  return (scm_from_gnutls_openpgp_certificate (c_key));
-}
-
-#undef FUNC_NAME
-
-SCM_DEFINE (scm_gnutls_import_openpgp_private_key,
-            "import-openpgp-private-key", 2, 1, 0, (SCM data, SCM format,
-                                                    SCM pass),
-            "Return a new OpenPGP private key object resulting from the "
-            "import of @var{data} (a uniform array) according to "
-            "@var{format}.  Optionally, a passphrase may be provided.")
-#define FUNC_NAME s_scm_gnutls_import_openpgp_private_key
-{
-  int err;
-  gnutls_openpgp_privkey_t c_key;
-  gnutls_openpgp_crt_fmt_t c_format;
-  gnutls_datum_t c_data_d;
-  scm_t_array_handle c_data_handle;
-  const char *c_data;
-  char *c_pass;
-  size_t c_data_len, c_pass_len;
-
-  SCM_VALIDATE_ARRAY (1, data);
-  c_format = scm_to_gnutls_openpgp_certificate_format (format, 2, FUNC_NAME);
-  if ((pass == SCM_UNDEFINED) || (scm_is_false (pass)))
-    c_pass = NULL;
-  else
-    {
-      c_pass_len = scm_c_string_length (pass);
-      c_pass = (char *) alloca (c_pass_len + 1);
-      (void) scm_to_locale_stringbuf (pass, c_pass, c_pass_len + 1);
-      c_pass[c_pass_len] = '\0';
-    }
-
-  c_data = scm_gnutls_get_array (data, &c_data_handle, &c_data_len,
-                                 FUNC_NAME);
-  c_data_d.data = (unsigned char *) c_data;
-  c_data_d.size = c_data_len;
-
-  err = gnutls_openpgp_privkey_init (&c_key);
-  if (EXPECT_FALSE (err))
-    {
-      scm_gnutls_release_array (&c_data_handle);
-      scm_gnutls_error (err, FUNC_NAME);
-    }
-
-  err = gnutls_openpgp_privkey_import (c_key, &c_data_d, c_format, c_pass,
-                                       0 /* currently unused */ );
-  scm_gnutls_release_array (&c_data_handle);
-
-  if (EXPECT_FALSE (err))
-    {
-      gnutls_openpgp_privkey_deinit (c_key);
-      scm_gnutls_error (err, FUNC_NAME);
-    }
-
-  return (scm_from_gnutls_openpgp_private_key (c_key));
-}
-
-#undef FUNC_NAME
-
-SCM_DEFINE (scm_gnutls_openpgp_certificate_id, "openpgp-certificate-id",
-            1, 0, 0,
-            (SCM key),
-            "Return the ID (an 8-element u8vector) of certificate "
-            "@var{key}.")
-#define FUNC_NAME s_scm_gnutls_openpgp_certificate_id
-{
-  int err;
-  unsigned char *c_id;
-  gnutls_openpgp_crt_t c_key;
-
-  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
-
-  c_id = (unsigned char *) malloc (8);
-  if (c_id == NULL)
-    scm_gnutls_error (GNUTLS_E_MEMORY_ERROR, FUNC_NAME);
-
-  err = gnutls_openpgp_crt_get_key_id (c_key, c_id);
-  if (EXPECT_FALSE (err))
-    scm_gnutls_error (err, FUNC_NAME);
-
-  return (scm_take_u8vector (c_id, 8));
-}
-
-#undef FUNC_NAME
-
-SCM_DEFINE (scm_gnutls_openpgp_certificate_id_x, "openpgp-certificate-id!",
-            2, 0, 0,
-            (SCM key, SCM id),
-            "Store the ID (an 8 byte sequence) of certificate "
-            "@var{key} in @var{id} (a u8vector).")
-#define FUNC_NAME s_scm_gnutls_openpgp_certificate_id_x
-{
-  int err;
-  char *c_id;
-  scm_t_array_handle c_id_handle;
-  size_t c_id_size;
-  gnutls_openpgp_crt_t c_key;
-
-  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
-  c_id = scm_gnutls_get_writable_array (id, &c_id_handle, &c_id_size,
-                                        FUNC_NAME);
-
-  if (EXPECT_FALSE (c_id_size < 8))
-    {
-      scm_gnutls_release_array (&c_id_handle);
-      scm_misc_error (FUNC_NAME, "ID vector too small: ~A", scm_list_1 (id));
-    }
-
-  err = gnutls_openpgp_crt_get_key_id (c_key, (unsigned char *) c_id);
-  scm_gnutls_release_array (&c_id_handle);
-
-  if (EXPECT_FALSE (err))
-    scm_gnutls_error (err, FUNC_NAME);
-
-  return SCM_UNSPECIFIED;
-}
-
-#undef FUNC_NAME
-
-SCM_DEFINE (scm_gnutls_openpgp_certificate_fingerpint_x,
-            "openpgp-certificate-fingerprint!",
-            2, 0, 0,
-            (SCM key, SCM fpr),
-            "Store in @var{fpr} (a u8vector) the fingerprint of @var{key}.  "
-            "Return the number of bytes stored in @var{fpr}.")
-#define FUNC_NAME s_scm_gnutls_openpgp_certificate_fingerpint_x
-{
-  int err;
-  gnutls_openpgp_crt_t c_key;
-  char *c_fpr;
-  scm_t_array_handle c_fpr_handle;
-  size_t c_fpr_len, c_actual_len = 0;
-
-  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
-  SCM_VALIDATE_ARRAY (2, fpr);
-
-  c_fpr = scm_gnutls_get_writable_array (fpr, &c_fpr_handle, &c_fpr_len,
-                                         FUNC_NAME);
-
-  err = gnutls_openpgp_crt_get_fingerprint (c_key, c_fpr, &c_actual_len);
-  scm_gnutls_release_array (&c_fpr_handle);
-
-  if (EXPECT_FALSE (err))
-    scm_gnutls_error (err, FUNC_NAME);
-
-  return (scm_from_size_t (c_actual_len));
-}
-
-#undef FUNC_NAME
-
-SCM_DEFINE (scm_gnutls_openpgp_certificate_fingerprint,
-            "openpgp-certificate-fingerprint",
-            1, 0, 0,
-            (SCM key),
-            "Return a new u8vector denoting the fingerprint of " "@var{key}.")
-#define FUNC_NAME s_scm_gnutls_openpgp_certificate_fingerprint
-{
-  int err;
-  gnutls_openpgp_crt_t c_key;
-  unsigned char *c_fpr;
-  size_t c_fpr_len, c_actual_len;
-
-  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
-
-  /* V4 fingerprints are 160-bit SHA-1 hashes (see RFC2440).  */
-  c_fpr_len = 20;
-  c_fpr = (unsigned char *) malloc (c_fpr_len);
-  if (EXPECT_FALSE (c_fpr == NULL))
-    scm_gnutls_error (GNUTLS_E_MEMORY_ERROR, FUNC_NAME);
-
-  do
-    {
-      c_actual_len = 0;
-      err = gnutls_openpgp_crt_get_fingerprint (c_key, c_fpr, &c_actual_len);
-      if (err == GNUTLS_E_SHORT_MEMORY_BUFFER)
-        {
-          /* Grow C_FPR.  */
-          unsigned char *c_new;
-
-          c_new = (unsigned char *) realloc (c_fpr, c_fpr_len * 2);
-          if (EXPECT_FALSE (c_new == NULL))
-            {
-              free (c_fpr);
-              scm_gnutls_error (GNUTLS_E_MEMORY_ERROR, FUNC_NAME);
-            }
-          else
-            {
-              c_fpr_len *= 2;
-              c_fpr = c_new;
-            }
-        }
-    }
-  while (err == GNUTLS_E_SHORT_MEMORY_BUFFER);
-
-  if (EXPECT_FALSE (err))
-    {
-      free (c_fpr);
-      scm_gnutls_error (err, FUNC_NAME);
-    }
-
-  if (c_actual_len < c_fpr_len)
-    /* Shrink C_FPR.  */
-    c_fpr = realloc (c_fpr, c_actual_len);
-
-  return (scm_take_u8vector (c_fpr, c_actual_len));
-}
-
-#undef FUNC_NAME
-
-SCM_DEFINE (scm_gnutls_openpgp_certificate_name, "openpgp-certificate-name",
-            2, 0, 0,
-            (SCM key, SCM index),
-            "Return the @var{index}th name of @var{key}.")
-#define FUNC_NAME s_scm_gnutls_openpgp_certificate_name
-{
-  int err;
-  gnutls_openpgp_crt_t c_key;
-  int c_index;
-  char c_name[GUILE_GNUTLS_MAX_OPENPGP_NAME_LENGTH];
-  size_t c_name_len = sizeof (c_name);
-
-  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
-  c_index = scm_to_int (index);
-
-  err = gnutls_openpgp_crt_get_name (c_key, c_index, c_name, &c_name_len);
-  if (EXPECT_FALSE (err))
-    scm_gnutls_error (err, FUNC_NAME);
-
-  /* XXX: The name is really UTF-8.  */
-  return (scm_from_locale_string (c_name));
-}
-
-#undef FUNC_NAME
-
-SCM_DEFINE (scm_gnutls_openpgp_certificate_names, "openpgp-certificate-names",
-            1, 0, 0, (SCM key), "Return the list of names for @var{key}.")
-#define FUNC_NAME s_scm_gnutls_openpgp_certificate_names
-{
-  int err;
-  SCM result = SCM_EOL;
-  gnutls_openpgp_crt_t c_key;
-  int c_index = 0;
-  char c_name[GUILE_GNUTLS_MAX_OPENPGP_NAME_LENGTH];
-  size_t c_name_len = sizeof (c_name);
-
-  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
-
-  do
-    {
-      err = gnutls_openpgp_crt_get_name (c_key, c_index, c_name, &c_name_len);
-      if (!err)
-        {
-          result = scm_cons (scm_from_locale_string (c_name), result);
-          c_index++;
-        }
-    }
-  while (!err);
-
-  if (EXPECT_FALSE (err != GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE))
-    scm_gnutls_error (err, FUNC_NAME);
-
-  return (scm_reverse_x (result, SCM_EOL));
-}
-
-#undef FUNC_NAME
-
-SCM_DEFINE (scm_gnutls_openpgp_certificate_algorithm,
-            "openpgp-certificate-algorithm",
-            1, 0, 0,
-            (SCM key),
-            "Return two values: the certificate algorithm used by "
-            "@var{key} and the number of bits used.")
-#define FUNC_NAME s_scm_gnutls_openpgp_certificate_algorithm
-{
-  gnutls_openpgp_crt_t c_key;
-  unsigned int c_bits;
-  gnutls_pk_algorithm_t c_algo;
-
-  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
-  c_algo = gnutls_openpgp_crt_get_pk_algorithm (c_key, &c_bits);
-
-  return (scm_values (scm_list_2 (scm_from_gnutls_pk_algorithm (c_algo),
-                                  scm_from_uint (c_bits))));
-}
-
-#undef FUNC_NAME
-
-SCM_DEFINE (scm_gnutls_openpgp_certificate_version,
-            "openpgp-certificate-version",
-            1, 0, 0,
-            (SCM key),
-            "Return the version of the OpenPGP message format (RFC2440) "
-            "honored by @var{key}.")
-#define FUNC_NAME s_scm_gnutls_openpgp_certificate_version
-{
-  int c_version;
-  gnutls_openpgp_crt_t c_key;
-
-  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
-  c_version = gnutls_openpgp_crt_get_version (c_key);
-
-  return (scm_from_int (c_version));
-}
-
-#undef FUNC_NAME
-
-SCM_DEFINE (scm_gnutls_openpgp_certificate_usage, "openpgp-certificate-usage",
-            1, 0, 0,
-            (SCM key),
-            "Return a list of values denoting the key usage of @var{key}.")
-#define FUNC_NAME s_scm_gnutls_openpgp_certificate_usage
-{
-  int err;
-  unsigned int c_usage = 0;
-  gnutls_openpgp_crt_t c_key;
-
-  c_key = scm_to_gnutls_openpgp_certificate (key, 1, FUNC_NAME);
-
-  err = gnutls_openpgp_crt_get_key_usage (c_key, &c_usage);
-  if (EXPECT_FALSE (err))
-    scm_gnutls_error (err, FUNC_NAME);
-
-  return (scm_from_gnutls_key_usage_flags (c_usage));
-}
-
-#undef FUNC_NAME
-
-
-
-/* OpenPGP keyrings.  */
-
-SCM_DEFINE (scm_gnutls_import_openpgp_keyring, "import-openpgp-keyring",
-            2, 0, 0,
-            (SCM data, SCM format),
-            "Import @var{data} (a u8vector) according to @var{format} "
-            "and return the imported keyring.")
-#define FUNC_NAME s_scm_gnutls_import_openpgp_keyring
-{
-  int err;
-  gnutls_openpgp_keyring_t c_keyring;
-  gnutls_openpgp_crt_fmt_t c_format;
-  gnutls_datum_t c_data_d;
-  scm_t_array_handle c_data_handle;
-  const char *c_data;
-  size_t c_data_len;
-
-  SCM_VALIDATE_ARRAY (1, data);
-  c_format = scm_to_gnutls_openpgp_certificate_format (format, 2, FUNC_NAME);
-
-  c_data = scm_gnutls_get_array (data, &c_data_handle, &c_data_len,
-                                 FUNC_NAME);
-
-  c_data_d.data = (unsigned char *) c_data;
-  c_data_d.size = c_data_len;
-
-  err = gnutls_openpgp_keyring_init (&c_keyring);
-  if (EXPECT_FALSE (err))
-    {
-      scm_gnutls_release_array (&c_data_handle);
-      scm_gnutls_error (err, FUNC_NAME);
-    }
-
-  err = gnutls_openpgp_keyring_import (c_keyring, &c_data_d, c_format);
-  scm_gnutls_release_array (&c_data_handle);
-
-  if (EXPECT_FALSE (err))
-    {
-      gnutls_openpgp_keyring_deinit (c_keyring);
-      scm_gnutls_error (err, FUNC_NAME);
-    }
-
-  return (scm_from_gnutls_openpgp_keyring (c_keyring));
-}
-
-#undef FUNC_NAME
-
-SCM_DEFINE (scm_gnutls_openpgp_keyring_contains_key_id_p,
-            "openpgp-keyring-contains-key-id?",
-            2, 0, 0,
-            (SCM keyring, SCM id),
-            "Return @code{#f} if key ID @var{id} is in @var{keyring}, "
-            "@code{#f} otherwise.")
-#define FUNC_NAME s_scm_gnutls_openpgp_keyring_contains_key_id_p
-{
-  int c_result;
-  gnutls_openpgp_keyring_t c_keyring;
-  scm_t_array_handle c_id_handle;
-  const char *c_id;
-  size_t c_id_len;
-
-  c_keyring = scm_to_gnutls_openpgp_keyring (keyring, 1, FUNC_NAME);
-  SCM_VALIDATE_ARRAY (1, id);
-
-  c_id = scm_gnutls_get_array (id, &c_id_handle, &c_id_len, FUNC_NAME);
-  if (EXPECT_FALSE (c_id_len != 8))
-    {
-      scm_gnutls_release_array (&c_id_handle);
-      scm_wrong_type_arg (FUNC_NAME, 1, id);
-    }
-
-  c_result = gnutls_openpgp_keyring_check_id (c_keyring,
-                                              (unsigned char *) c_id,
-                                              0 /* unused */ );
-
-  scm_gnutls_release_array (&c_id_handle);
-
-  return (scm_from_bool (c_result == 0));
-}
-
-#undef FUNC_NAME
-
-
-/* Certificates.  */
-
-SCM_DEFINE (scm_gnutls_set_certificate_credentials_openpgp_keys_x,
-            "set-certificate-credentials-openpgp-keys!",
-            3, 0, 0,
-            (SCM cred, SCM pub, SCM sec),
-            "Use certificate @var{pub} and secret key @var{sec} in "
-            "certificate credentials @var{cred}.")
-#define FUNC_NAME s_scm_gnutls_set_certificate_credentials_openpgp_keys_x
-{
-  int err;
-  gnutls_certificate_credentials_t c_cred;
-  gnutls_openpgp_crt_t c_pub;
-  gnutls_openpgp_privkey_t c_sec;
-
-  c_cred = scm_to_gnutls_certificate_credentials (cred, 1, FUNC_NAME);
-  c_pub = scm_to_gnutls_openpgp_certificate (pub, 2, FUNC_NAME);
-  c_sec = scm_to_gnutls_openpgp_private_key (sec, 3, FUNC_NAME);
-
-  err = gnutls_certificate_set_openpgp_key (c_cred, c_pub, c_sec);
-  if (EXPECT_FALSE (err))
-    scm_gnutls_error (err, FUNC_NAME);
-
-  return SCM_UNSPECIFIED;
-}
-
-#undef FUNC_NAME
-
-
-/* Initialization.  */
-
-void
-scm_init_gnutls_extra (void)
-{
-#include "extra.x"
-
-  (void) gnutls_global_init_extra ();
-
-  scm_gnutls_define_enums ();
-}
-
-/* arch-tag: 655f308d-5643-4bc7-9db4-1f84bd902bef
- */
diff --git a/guile/src/make-enum-header.scm b/guile/src/make-enum-header.scm
index e9085c6..908cc14 100644
--- a/guile/src/make-enum-header.scm
+++ b/guile/src/make-enum-header.scm
@@ -1,7 +1,7 @@
 ;;; Help produce Guile wrappers for GnuTLS types.
 ;;;
 ;;; GnuTLS --- Guile bindings for GnuTLS.
-;;; Copyright (C) 2007, 2008, 2010 Free Software Foundation, Inc.
+;;; Copyright (C) 2007, 2008, 2010, 2011 Free Software Foundation, Inc.
 ;;;
 ;;; GnuTLS is free software; you can redistribute it and/or
 ;;; modify it under the terms of the GNU Lesser General Public
@@ -28,28 +28,18 @@
 ;;;
 
 (define (main . args)
-  (define extra? (not (null? args)))
-
   (let ((port (current-output-port))
-        (enums (if (not extra?)
-                   %gnutls-enums
-                   %gnutls-extra-enums)))
+        (enums %gnutls-enums))
     (format port "/* Automatically generated, do not edit.  */~%~%")
-    (format port "#ifndef GUILE_GNUTLS_~aENUMS_H~%"
-            (if extra? "EXTRA_" ""))
-    (format port "#define GUILE_GNUTLS_~aENUMS_H~%"
-            (if extra? "EXTRA_" ""))
+    (format port "#ifndef GUILE_GNUTLS_ENUMS_H~%")
+    (format port "#define GUILE_GNUTLS_ENUMS_H~%")
 
     (format port "#ifdef HAVE_CONFIG_H~%")
     (format port "# include <config.h>~%")
     (format port "#endif~%~%")
     (format port "#include <gnutls/gnutls.h>~%")
     (format port "#include <gnutls/x509.h>~%")
-
-    (if extra?
-        (begin
-          (format port "#include <gnutls/extra.h>~%")
-          (format port "#include <gnutls/openpgp.h>~%")))
+    (format port "#include <gnutls/openpgp.h>~%")
 
     (for-each (lambda (enum)
                 (output-enum-declarations enum port)
diff --git a/guile/src/make-enum-map.scm b/guile/src/make-enum-map.scm
index 0e4b7a7..99cb9cf 100644
--- a/guile/src/make-enum-map.scm
+++ b/guile/src/make-enum-map.scm
@@ -1,7 +1,7 @@
 ;;; Help produce Guile wrappers for GnuTLS types.
 ;;;
 ;;; GnuTLS --- Guile bindings for GnuTLS.
-;;; Copyright (C) 2007, 2010 Free Software Foundation, Inc.
+;;; Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
 ;;;
 ;;; GnuTLS is free software; you can redistribute it and/or
 ;;; modify it under the terms of the GNU Lesser General Public
@@ -29,9 +29,7 @@
 
 (define (main . args)
   (let ((port (current-output-port))
-        (enums (if (null? args)
-                   %gnutls-enums
-                   %gnutls-extra-enums)))
+        (enums %gnutls-enums))
     (for-each (lambda (enum)
                 (output-enum-smob-definitions enum port))
               enums)
diff --git a/guile/src/make-smob-header.scm b/guile/src/make-smob-header.scm
index 24d554d..9103af6 100644
--- a/guile/src/make-smob-header.scm
+++ b/guile/src/make-smob-header.scm
@@ -1,7 +1,7 @@
 ;;; Help produce Guile wrappers for GnuTLS types.
 ;;;
 ;;; GnuTLS --- Guile bindings for GnuTLS.
-;;; Copyright (C) 2007, 2010 Free Software Foundation, Inc.
+;;; Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
 ;;;
 ;;; GnuTLS is free software; you can redistribute it and/or
 ;;; modify it under the terms of the GNU Lesser General Public
@@ -28,17 +28,11 @@
 ;;;
 
 (define (main . args)
-  (define extra? (not (null? args)))
-
   (let ((port (current-output-port))
-        (enums (if (not extra?)
-                   %gnutls-smobs
-                   %gnutls-extra-smobs)))
+        (enums %gnutls-smobs))
     (format port "/* Automatically generated, do not edit.  */~%~%")
-    (format port "#ifndef GUILE_GNUTLS_~aSMOBS_H~%"
-            (if extra? "EXTRA_" ""))
-    (format port "#define GUILE_GNUTLS_~aSMOBS_H~%"
-            (if extra? "EXTRA_" ""))
+    (format port "#ifndef GUILE_GNUTLS_SMOBS_H~%")
+    (format port "#define GUILE_GNUTLS_SMOBS_H~%")
     (for-each (lambda (type)
                 (output-smob-type-declaration type port)
                 (output-c->smob-converter type port)
diff --git a/guile/src/make-smob-types.scm b/guile/src/make-smob-types.scm
index 0256d9a..117168d 100644
--- a/guile/src/make-smob-types.scm
+++ b/guile/src/make-smob-types.scm
@@ -1,7 +1,7 @@
 ;;; Help produce Guile wrappers for GnuTLS types.
 ;;;
 ;;; GnuTLS --- Guile bindings for GnuTLS.
-;;; Copyright (C) 2007, 2010 Free Software Foundation, Inc.
+;;; Copyright (C) 2007, 2010, 2011 Free Software Foundation, Inc.
 ;;;
 ;;; GnuTLS is free software; you can redistribute it and/or
 ;;; modify it under the terms of the GNU Lesser General Public
@@ -32,9 +32,7 @@
     (for-each (lambda (type)
                 (output-smob-type-definition type port)
                 (output-smob-type-predicate type port))
-              (if (null? args)
-                  %gnutls-smobs
-                  %gnutls-extra-smobs))))
+              %gnutls-smobs)))
 
 (apply main (cdr (command-line)))
 
diff --git a/guile/tests/openpgp-auth.scm b/guile/tests/openpgp-auth.scm
index 9e3a3e4..412a686 100644
--- a/guile/tests/openpgp-auth.scm
+++ b/guile/tests/openpgp-auth.scm
@@ -24,7 +24,6 @@
 ;;;
 
 (use-modules (gnutls)
-             (gnutls extra)
              (gnutls build tests)
              (srfi srfi-4))
 
diff --git a/guile/tests/openpgp-keyring.scm b/guile/tests/openpgp-keyring.scm
index 576a9db..e04e545 100644
--- a/guile/tests/openpgp-keyring.scm
+++ b/guile/tests/openpgp-keyring.scm
@@ -23,7 +23,7 @@
 ;;; Exercise the OpenPGP keyring API part of GnuTLS-extra.
 ;;;
 
-(use-modules (gnutls extra) (gnutls)
+(use-modules (gnutls)
              (gnutls build tests)
              (srfi srfi-1)
              (srfi srfi-4))
diff --git a/guile/tests/openpgp-keys.scm b/guile/tests/openpgp-keys.scm
index 2ded32d..3dfc6d4 100644
--- a/guile/tests/openpgp-keys.scm
+++ b/guile/tests/openpgp-keys.scm
@@ -24,7 +24,6 @@
 ;;;
 
 (use-modules (gnutls)
-             (gnutls extra)
              (gnutls build tests)
              (srfi srfi-1)
              (srfi srfi-4)
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 5a92dba..74258b5 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -30,9 +30,14 @@ localedir = $(datadir)/locale
 AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
 AM_CPPFLAGS = \
        -DLOCALEDIR=\"$(localedir)\"            \
-       -I$(srcdir)/../gl                               \
+       -I$(srcdir)/../gl                       \
+       -I$(builddir)/../gl                     \
+       -I$(builddir)/includes                  \
+       -I$(builddir)/x509                      \
        -I$(srcdir)/includes                    \
-       -I$(srcdir)/x509
+       -I$(builddir)/includes                  \
+       -I$(srcdir)/x509                        \
+       $(P11_KIT_CFLAGS)
 
 if ENABLE_OPENPGP
 SUBDIRS += opencdk
@@ -77,8 +82,6 @@ endif
 
 if ENABLE_NETTLE
 SUBDIRS += nettle
-else
-SUBDIRS += gcrypt
 endif
 
 HFILES = abstract_int.h debug.h gnutls_compress.h gnutls_cipher.h      \
@@ -112,7 +115,7 @@ libgnutls_la_LIBADD = ../gl/libgnu.la 
x509/libgnutls_x509.la \
        accelerated/libaccelerated.la ext/libgnutls_ext.la \
        auth/libgnutls_auth.la algorithms/libgnutls_alg.la \
        $(LTLIBZ)  $(LTLIBINTL) $(LIBSOCKET) $(LTLIBDL) \
-       $(LTLIBPTHREAD)
+       $(LTLIBPTHREAD) $(P11_KIT_LIBS)
 
 if ENABLE_OPENPGP
 libgnutls_la_LIBADD += openpgp/libgnutls_openpgp.la
@@ -134,9 +137,6 @@ endif
 if ENABLE_NETTLE
 libgnutls_la_LDFLAGS += $(LTLIBNETTLE)
 libgnutls_la_LIBADD += nettle/libcrypto.la
-else
-libgnutls_la_LDFLAGS += $(LTLIBGCRYPT)
-libgnutls_la_LIBADD += gcrypt/libcrypto.la
 endif
 
 if HAVE_LD_OUTPUT_DEF
@@ -151,7 +151,9 @@ endif
 if ENABLE_CXX
 libgnutlsxx_la_CPPFLAGS = -I$(top_srcdir)/includes -I$(top_builddir)/includes 
-I$(srcdir)/includes
 
-AM_CXXFLAGS = -I$(srcdir)/includes
+AM_CXXFLAGS = \
+       -I$(srcdir)/includes    \
+       -I$(builddir)/includes  
 
 lib_LTLIBRARIES += libgnutlsxx.la
 
diff --git a/lib/accelerated/Makefile.am b/lib/accelerated/Makefile.am
index e9426d0..37acd47 100644
--- a/lib/accelerated/Makefile.am
+++ b/lib/accelerated/Makefile.am
@@ -22,7 +22,9 @@ AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
 SUBDIRS = 
 AM_CPPFLAGS = \
        -I$(srcdir)/../../gl            \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/../includes         \
+       -I$(builddir)/../../gl          \
        -I$(builddir)/../includes       \
        -I$(srcdir)/..
 
@@ -32,18 +34,20 @@ endif
 
 noinst_LTLIBRARIES = libaccelerated.la
 
-EXTRA_DIST = x86.h accelerated.h cryptodev.h
+EXTRA_DIST = accelerated.h cryptodev.h
 libaccelerated_la_SOURCES = accelerated.c cryptodev.c
 libaccelerated_la_LIBADD =
 
-if ASM_X86_64
-SUBDIRS += intel
-AM_CFLAGS += -DASM_X86_64
-libaccelerated_la_LIBADD += intel/libintel.la
+if ASM_X86
+SUBDIRS += x86
+AM_CFLAGS += -DASM_X86
+libaccelerated_la_LIBADD += x86/libx86.la
 endif
 
 if ASM_X86_32
-SUBDIRS += intel
 AM_CFLAGS += -DASM_X86_32
-libaccelerated_la_LIBADD += intel/libintel.la
+endif
+
+if ASM_X86_64
+AM_CFLAGS += -DASM_X86_64
 endif
diff --git a/lib/accelerated/accelerated.c b/lib/accelerated/accelerated.c
index 8a89e3d..8d138f0 100644
--- a/lib/accelerated/accelerated.c
+++ b/lib/accelerated/accelerated.c
@@ -20,16 +20,16 @@
  *
  */
 
+#include <config.h>
 #include <accelerated.h>
-#if defined(ASM_X86_32) || defined(ASM_X86_64)
-# include <intel/aes-x86.h>
-# include <x86.h>
+#if defined(ASM_X86)
+# include <x86/aes-x86.h>
+# include <x86/x86.h>
 #endif
 
 void _gnutls_register_accel_crypto(void)
 {
-
-#if defined(ASM_X86_32) || defined(ASM_X86_64)
+#if defined(ASM_X86)
   if (_gnutls_have_cpuid() != 0)
     {
       register_x86_crypto ();
diff --git a/lib/accelerated/intel/Makefile.am 
b/lib/accelerated/intel/Makefile.am
deleted file mode 100644
index 0882929..0000000
--- a/lib/accelerated/intel/Makefile.am
+++ /dev/null
@@ -1,45 +0,0 @@
-## Process this file with automake to produce Makefile.in
-# Copyright (C) 2011 Free Software Foundation, Inc.
-#
-# Author: Nikos Mavrogiannopoulos
-#
-# This file is part of GNUTLS.
-#
-# The GNUTLS library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public License
-# as published by the Free Software Foundation; either version 3 of
-# the License, or (at your option) any later version.
-#
-# The GNUTLS library is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>
-
-AM_LIBTOOLFLAGS=--tag=CC
-AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
-AM_CPPFLAGS = \
-       -I$(srcdir)/../../../gl         \
-       -I$(srcdir)/../../includes      \
-       -I$(srcdir)/../../ \
-       -I$(srcdir)/../
-
-if ENABLE_MINITASN1
-AM_CPPFLAGS += -I$(srcdir)/../../minitasn1
-endif
-
-EXTRA_DIST = README license.txt
-
-noinst_LTLIBRARIES = libintel.la
-
-libintel_la_SOURCES = aes-x86.c aes-padlock.c aes-gcm-padlock.c aes-padlock.h 
aes-x86.h
-
-if ASM_X86_64
-AM_CPPFLAGS += -DASM_X86_64
-libintel_la_SOURCES += asm/appro-aes-x86-64.s asm/appro-aes-gcm-x86-64.s 
aes-gcm-x86.c asm/padlock-x86-64.s asm/cpuid-x86-64.s
-else
-libintel_la_SOURCES += asm/appro-aes-x86.s asm/padlock-x86.s asm/cpuid-x86.s
-endif
-
diff --git a/lib/accelerated/intel/README b/lib/accelerated/intel/README
deleted file mode 100644
index dc1f43f..0000000
--- a/lib/accelerated/intel/README
+++ /dev/null
@@ -1,3 +0,0 @@
-The AES-NI implementation by Andy Polyakov is not part of the GnuTLS library, 
but is 
-used with GnuTLS. Its license is included in license.txt.
-
diff --git a/lib/accelerated/intel/aes-gcm-padlock.c 
b/lib/accelerated/intel/aes-gcm-padlock.c
deleted file mode 100644
index 28292ad..0000000
--- a/lib/accelerated/intel/aes-gcm-padlock.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright (C) 2011 Free Software Foundation, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS.
- *
- * The GnuTLS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-/*
- * The following code is an implementation of the AES-128-CBC cipher
- * using intel's AES instruction set. It is based on Intel reference
- * code.
- */
-
-#include <gnutls_errors.h>
-#include <gnutls_int.h>
-
-#ifdef HAVE_LIBNETTLE
-
-#include <gnutls/crypto.h>
-#include <gnutls_errors.h>
-#include <aes-x86.h>
-#include <x86.h>
-#include <byteswap.h>
-#include <nettle/gcm.h>
-#include <aes-padlock.h>
-
-#define GCM_BLOCK_SIZE 16
-
-/* GCM mode 
- * Actually padlock doesn't include GCM mode. We just use
- * the ECB part of padlock and nettle for everything else.
- */
-
-struct gcm_padlock_aes_ctx GCM_CTX(struct padlock_ctx);
-
-static void padlock_aes_encrypt(void *_ctx,
-                                unsigned length, uint8_t *dst,
-                                const uint8_t *src)
-{
-    struct padlock_ctx *ctx = _ctx;
-    struct padlock_cipher_data *pce;
-
-    pce = ALIGN16(&ctx->expanded_key);
-
-    padlock_ecb_encrypt(dst, src, pce, length);
-}
-
-static void padlock_aes_set_encrypt_key(struct padlock_ctx *_ctx,
-                                        unsigned length, const uint8_t *key)
-{
-  padlock_aes_cipher_setkey(_ctx, key, length);
-}
-
-static void
-aes_gcm_deinit (void *_ctx)
-{
-  gnutls_free (_ctx);
-}
-
-static int
-aes_gcm_cipher_init (gnutls_cipher_algorithm_t algorithm, void **_ctx, int enc)
-{
-  /* we use key size to distinguish */
-  if (algorithm != GNUTLS_CIPHER_AES_128_GCM &&
-      algorithm != GNUTLS_CIPHER_AES_256_GCM)
-    return GNUTLS_E_INVALID_REQUEST;
-
-  *_ctx = gnutls_calloc (1, sizeof (struct gcm_padlock_aes_ctx));
-  if (*_ctx == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  return 0;
-}
-
-static int
-aes_gcm_cipher_setkey (void *_ctx, const void *userkey, size_t keysize)
-{
-  struct gcm_padlock_aes_ctx *ctx = _ctx;
-
-  GCM_SET_KEY(ctx, padlock_aes_set_encrypt_key, padlock_aes_encrypt, keysize, 
userkey);
-
-  return 0;
-}
-
-static int
-aes_gcm_setiv (void *_ctx, const void *iv, size_t iv_size)
-{
-  struct gcm_padlock_aes_ctx *ctx = _ctx;
-
-  if (iv_size != GCM_BLOCK_SIZE - 4)
-    return GNUTLS_E_INVALID_REQUEST;
-  
-  GCM_SET_IV(ctx, iv_size, iv);
-
-  return 0;
-}
-
-static int
-aes_gcm_encrypt (void *_ctx, const void *src, size_t src_size,
-                 void *dst, size_t length)
-{
-  struct gcm_padlock_aes_ctx *ctx = _ctx;
-
-  GCM_ENCRYPT(ctx, padlock_aes_encrypt, src_size, dst, src);
-
-  return 0;
-}
-
-static int
-aes_gcm_decrypt (void *_ctx, const void *src, size_t src_size,
-                 void *dst, size_t dst_size)
-{
-  struct gcm_padlock_aes_ctx *ctx = _ctx;
-
-  GCM_DECRYPT(ctx, padlock_aes_encrypt, src_size, dst, src);
-  return 0;
-}
-
-static int
-aes_gcm_auth (void *_ctx, const void *src, size_t src_size)
-{
-  struct gcm_padlock_aes_ctx *ctx = _ctx;
-
-  GCM_UPDATE(ctx, src_size, src);
-
-  return 0;
-}
-
-static void
-aes_gcm_tag (void *_ctx, void *tag, size_t tagsize)
-{
-  struct gcm_padlock_aes_ctx *ctx = _ctx;
-  
-  GCM_DIGEST(ctx, padlock_aes_encrypt, tagsize, tag);
-}
-
-const gnutls_crypto_cipher_st aes_gcm_padlock_struct = {
-  .init = aes_gcm_cipher_init,
-  .setkey = aes_gcm_cipher_setkey,
-  .setiv = aes_gcm_setiv,
-  .encrypt = aes_gcm_encrypt,
-  .decrypt = aes_gcm_decrypt,
-  .deinit = aes_gcm_deinit,
-  .tag = aes_gcm_tag,
-  .auth = aes_gcm_auth,
-};
-
-#endif
diff --git a/lib/accelerated/intel/aes-padlock.c 
b/lib/accelerated/intel/aes-padlock.c
deleted file mode 100644
index 2d9e042..0000000
--- a/lib/accelerated/intel/aes-padlock.c
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Copyright (C) 2011 Free Software Foundation, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS.
- *
- * The GnuTLS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-/*
- * The following code is an implementation of the AES-128-CBC cipher
- * using VIA Padlock instruction set. 
- */
-
-#include <gnutls_errors.h>
-#include <gnutls_int.h>
-#include <gnutls/crypto.h>
-#include <gnutls_errors.h>
-#include <aes-x86.h>
-#include <x86.h>
-#ifdef HAVE_LIBNETTLE
-#include <nettle/aes.h>         /* for key generation in 192 and 256 bits */
-#endif
-#include <aes-padlock.h>
-
-static int
-aes_cipher_init(gnutls_cipher_algorithm_t algorithm, void **_ctx, int enc)
-{
-    /* we use key size to distinguish */
-    if (algorithm != GNUTLS_CIPHER_AES_128_CBC
-        && algorithm != GNUTLS_CIPHER_AES_192_CBC
-        && algorithm != GNUTLS_CIPHER_AES_256_CBC)
-        return GNUTLS_E_INVALID_REQUEST;
-
-    *_ctx = gnutls_calloc(1, sizeof(struct padlock_ctx));
-    if (*_ctx == NULL) {
-        gnutls_assert();
-        return GNUTLS_E_MEMORY_ERROR;
-    }
-
-    ((struct padlock_ctx *) (*_ctx))->enc = enc;
-    return 0;
-}
-
-int padlock_aes_cipher_setkey(void *_ctx, const void *userkey, size_t keysize)
-{
-    struct padlock_ctx *ctx = _ctx;
-    struct padlock_cipher_data *pce;
-#ifdef HAVE_LIBNETTLE
-    struct aes_ctx nc;
-#endif
-
-    memset(_ctx, 0, sizeof(struct padlock_cipher_data));
-
-    pce = ALIGN16(&ctx->expanded_key);
-
-    pce->cword.b.encdec = (ctx->enc == 0);
-
-    switch (keysize) {
-    case 16:
-        pce->cword.b.ksize = 0;
-        pce->cword.b.rounds = 10;
-        memcpy(pce->ks.rd_key, userkey, 16);
-        pce->cword.b.keygen = 0;
-        break;
-#ifdef HAVE_LIBNETTLE
-    case 24:
-        pce->cword.b.ksize = 1;
-        pce->cword.b.rounds = 12;
-        goto common_24_32;
-    case 32:
-        pce->cword.b.ksize = 2;
-        pce->cword.b.rounds = 14;
-      common_24_32:
-        /* expand key using nettle */
-        if (ctx->enc)
-            aes_set_encrypt_key(&nc, keysize, userkey);
-        else
-            aes_set_decrypt_key(&nc, keysize, userkey);
-
-        memcpy(pce->ks.rd_key, nc.keys, sizeof(nc.keys));
-        pce->ks.rounds = nc.nrounds;
-
-        pce->cword.b.keygen = 1;
-        break;
-#endif
-    default:
-        return gnutls_assert_val(GNUTLS_E_ENCRYPTION_FAILED);
-    }
-
-    padlock_reload_key();
-
-    return 0;
-}
-
-static int aes_setiv(void *_ctx, const void *iv, size_t iv_size)
-{
-    struct padlock_ctx *ctx = _ctx;
-    struct padlock_cipher_data *pce;
-
-    pce = ALIGN16(&ctx->expanded_key);
-
-    memcpy(pce->iv, iv, 16);
-    return 0;
-}
-
-static int
-padlock_aes_encrypt(void *_ctx, const void *src, size_t src_size,
-                    void *dst, size_t dst_size)
-{
-    struct padlock_ctx *ctx = _ctx;
-    struct padlock_cipher_data *pce;
-
-    pce = ALIGN16(&ctx->expanded_key);
-
-    padlock_cbc_encrypt(dst, src, pce, src_size);
-
-    return 0;
-}
-
-
-static int
-padlock_aes_decrypt(void *_ctx, const void *src, size_t src_size,
-                    void *dst, size_t dst_size)
-{
-    struct padlock_ctx *ctx = _ctx;
-    struct padlock_cipher_data *pcd;
-
-    pcd = ALIGN16(&ctx->expanded_key);
-
-    padlock_cbc_encrypt(dst, src, pcd, src_size);
-
-    return 0;
-}
-
-static void aes_deinit(void *_ctx)
-{
-    gnutls_free(_ctx);
-}
-
-static const gnutls_crypto_cipher_st aes_padlock_struct = {
-    .init = aes_cipher_init,
-    .setkey = padlock_aes_cipher_setkey,
-    .setiv = aes_setiv,
-    .encrypt = padlock_aes_encrypt,
-    .decrypt = padlock_aes_decrypt,
-    .deinit = aes_deinit,
-};
-
-static int check_padlock(void)
-{
-    unsigned int edx = padlock_capability();
-
-    return ((edx & (0x3 << 6)) == (0x3 << 6));
-}
-
-#ifdef ENABLE_VIA
-static unsigned check_via(void)
-{
-    unsigned int a, b, c, d;
-    _gnutls_cpuid(0, &a, &b, &c, &d);
-
-    if ((memcmp(&b, "VIA ", 4) == 0 &&
-         memcmp(&d, "VIA ", 4) == 0 && memcmp(&c, "VIA ", 4) == 0)) {
-        return 1;
-    }
-
-    return 0;
-}
-#endif
-
-void register_padlock_crypto(void)
-{
-    int ret;
-
-    /* Only enable the 32-bit padlock variant, until
-     * the 64-bit code is tested.
-     */
-#ifndef ENABLE_VIA
-    return;
-#else
-    if (check_via() == 0)
-        return;
-#endif
-
-    if (check_padlock()) {
-        _gnutls_debug_log("Padlock AES accelerator was detected\n");
-        ret =
-            gnutls_crypto_single_cipher_register(GNUTLS_CIPHER_AES_128_CBC,
-                                                 80, &aes_padlock_struct);
-        if (ret < 0) {
-            gnutls_assert();
-        }
-
-        /* register GCM ciphers */
-        ret =
-            gnutls_crypto_single_cipher_register(GNUTLS_CIPHER_AES_128_GCM,
-                                                 80,
-                                                 &aes_gcm_padlock_struct);
-        if (ret < 0) {
-            gnutls_assert();
-        }
-    }
-#ifdef HAVE_LIBNETTLE
-    ret =
-        gnutls_crypto_single_cipher_register(GNUTLS_CIPHER_AES_192_CBC,
-                                             80, &aes_padlock_struct);
-    if (ret < 0) {
-        gnutls_assert();
-    }
-
-    ret =
-        gnutls_crypto_single_cipher_register(GNUTLS_CIPHER_AES_256_CBC,
-                                             80, &aes_padlock_struct);
-    if (ret < 0) {
-        gnutls_assert();
-    }
-
-    ret =
-        gnutls_crypto_single_cipher_register(GNUTLS_CIPHER_AES_256_GCM,
-                                             80, &aes_gcm_padlock_struct);
-    if (ret < 0) {
-        gnutls_assert();
-    }
-#endif
-
-    return;
-}
diff --git a/lib/accelerated/intel/aes-padlock.h 
b/lib/accelerated/intel/aes-padlock.h
deleted file mode 100644
index d15a6b9..0000000
--- a/lib/accelerated/intel/aes-padlock.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef AES_PADLOCK_H
-# define AES_PADLOCK_H
-
-#include <gnutls_int.h>
-
-struct padlock_cipher_data {
-    unsigned char iv[16];       /* Initialization vector */
-    union {
-        unsigned int pad[4];
-        struct {
-            int rounds:4;
-            int dgst:1;         /* n/a in C3 */
-            int align:1;        /* n/a in C3 */
-            int ciphr:1;        /* n/a in C3 */
-            unsigned int keygen:1;
-            int interm:1;
-            unsigned int encdec:1;
-            int ksize:2;
-        } b;
-    } cword;                    /* Control word */
-    AES_KEY ks;                 /* Encryption key */
-};
-
-struct padlock_ctx {
-    struct padlock_cipher_data expanded_key;
-    int enc;
-};
-
-extern const gnutls_crypto_cipher_st aes_gcm_padlock_struct;
-
-int padlock_aes_cipher_setkey(void *_ctx, const void *userkey, size_t keysize);
-
-/* asm */
-unsigned int padlock_capability(void);
-void padlock_reload_key(void);
-int padlock_ecb_encrypt(void *out, const void *inp,
-                        struct padlock_cipher_data *ctx, size_t len);
-int padlock_cbc_encrypt(void *out, const void *inp,
-                        struct padlock_cipher_data *ctx, size_t len);
-void padlock_sha1_oneshot(void *ctx, const void *inp, size_t len);
-void padlock_sha256_oneshot(void *ctx, const void *inp, size_t len);
-
-#endif
diff --git a/lib/accelerated/intel/asm/appro-aes-gcm-x86-64.s 
b/lib/accelerated/intel/asm/appro-aes-gcm-x86-64.s
deleted file mode 100644
index 7e3c407..0000000
--- a/lib/accelerated/intel/asm/appro-aes-gcm-x86-64.s
+++ /dev/null
@@ -1,1068 +0,0 @@
-# Copyright (c) 2011, Andy Polyakov by <address@hidden>
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 
-#     * Redistributions of source code must retain copyright notices,
-#      this list of conditions and the following disclaimer.
-#
-#     * Redistributions in binary form must reproduce the above
-#      copyright notice, this list of conditions and the following
-#      disclaimer in the documentation and/or other materials
-#      provided with the distribution.
-#
-#     * Neither the name of the Andy Polyakov nor the names of its
-#      copyright holder and contributors may be used to endorse or
-#      promote products derived from this software without specific
-#      prior written permission.
-#
-# ALTERNATIVELY, provided that this notice is retained in full, this
-# product may be distributed under the terms of the GNU General Public
-# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
-# those given above.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-.text  
-
-.globl gcm_gmult_4bit
-.type  gcm_gmult_4bit,@function
-.align 16
-gcm_gmult_4bit:
-       pushq   %rbx
-       pushq   %rbp
-       pushq   %r12
-.Lgmult_prologue:
-
-       movzbq  15(%rdi),%r8
-       leaq    .Lrem_4bit(%rip),%r11
-       xorq    %rax,%rax
-       xorq    %rbx,%rbx
-       movb    %r8b,%al
-       movb    %r8b,%bl
-       shlb    $4,%al
-       movq    $14,%rcx
-       movq    8(%rsi,%rax,1),%r8
-       movq    (%rsi,%rax,1),%r9
-       andb    $240,%bl
-       movq    %r8,%rdx
-       jmp     .Loop1
-
-.align 16
-.Loop1:
-       shrq    $4,%r8
-       andq    $15,%rdx
-       movq    %r9,%r10
-       movb    (%rdi,%rcx,1),%al
-       shrq    $4,%r9
-       xorq    8(%rsi,%rbx,1),%r8
-       shlq    $60,%r10
-       xorq    (%rsi,%rbx,1),%r9
-       movb    %al,%bl
-       xorq    (%r11,%rdx,8),%r9
-       movq    %r8,%rdx
-       shlb    $4,%al
-       xorq    %r10,%r8
-       decq    %rcx
-       js      .Lbreak1
-
-       shrq    $4,%r8
-       andq    $15,%rdx
-       movq    %r9,%r10
-       shrq    $4,%r9
-       xorq    8(%rsi,%rax,1),%r8
-       shlq    $60,%r10
-       xorq    (%rsi,%rax,1),%r9
-       andb    $240,%bl
-       xorq    (%r11,%rdx,8),%r9
-       movq    %r8,%rdx
-       xorq    %r10,%r8
-       jmp     .Loop1
-
-.align 16
-.Lbreak1:
-       shrq    $4,%r8
-       andq    $15,%rdx
-       movq    %r9,%r10
-       shrq    $4,%r9
-       xorq    8(%rsi,%rax,1),%r8
-       shlq    $60,%r10
-       xorq    (%rsi,%rax,1),%r9
-       andb    $240,%bl
-       xorq    (%r11,%rdx,8),%r9
-       movq    %r8,%rdx
-       xorq    %r10,%r8
-
-       shrq    $4,%r8
-       andq    $15,%rdx
-       movq    %r9,%r10
-       shrq    $4,%r9
-       xorq    8(%rsi,%rbx,1),%r8
-       shlq    $60,%r10
-       xorq    (%rsi,%rbx,1),%r9
-       xorq    %r10,%r8
-       xorq    (%r11,%rdx,8),%r9
-
-       bswapq  %r8
-       bswapq  %r9
-       movq    %r8,8(%rdi)
-       movq    %r9,(%rdi)
-
-       movq    16(%rsp),%rbx
-       leaq    24(%rsp),%rsp
-.Lgmult_epilogue:
-       .byte   0xf3,0xc3
-.size  gcm_gmult_4bit,.-gcm_gmult_4bit
-.globl gcm_ghash_4bit
-.type  gcm_ghash_4bit,@function
-.align 16
-gcm_ghash_4bit:
-       pushq   %rbx
-       pushq   %rbp
-       pushq   %r12
-       pushq   %r13
-       pushq   %r14
-       pushq   %r15
-       subq    $280,%rsp
-.Lghash_prologue:
-       movq    %rdx,%r14
-       movq    %rcx,%r15
-       subq    $-128,%rsi
-       leaq    16+128(%rsp),%rbp
-       xorl    %edx,%edx
-       movq    0+0-128(%rsi),%r8
-       movq    0+8-128(%rsi),%rax
-       movb    %al,%dl
-       shrq    $4,%rax
-       movq    %r8,%r10
-       shrq    $4,%r8
-       movq    16+0-128(%rsi),%r9
-       shlb    $4,%dl
-       movq    16+8-128(%rsi),%rbx
-       shlq    $60,%r10
-       movb    %dl,0(%rsp)
-       orq     %r10,%rax
-       movb    %bl,%dl
-       shrq    $4,%rbx
-       movq    %r9,%r10
-       shrq    $4,%r9
-       movq    %r8,0(%rbp)
-       movq    32+0-128(%rsi),%r8
-       shlb    $4,%dl
-       movq    %rax,0-128(%rbp)
-       movq    32+8-128(%rsi),%rax
-       shlq    $60,%r10
-       movb    %dl,1(%rsp)
-       orq     %r10,%rbx
-       movb    %al,%dl
-       shrq    $4,%rax
-       movq    %r8,%r10
-       shrq    $4,%r8
-       movq    %r9,8(%rbp)
-       movq    48+0-128(%rsi),%r9
-       shlb    $4,%dl
-       movq    %rbx,8-128(%rbp)
-       movq    48+8-128(%rsi),%rbx
-       shlq    $60,%r10
-       movb    %dl,2(%rsp)
-       orq     %r10,%rax
-       movb    %bl,%dl
-       shrq    $4,%rbx
-       movq    %r9,%r10
-       shrq    $4,%r9
-       movq    %r8,16(%rbp)
-       movq    64+0-128(%rsi),%r8
-       shlb    $4,%dl
-       movq    %rax,16-128(%rbp)
-       movq    64+8-128(%rsi),%rax
-       shlq    $60,%r10
-       movb    %dl,3(%rsp)
-       orq     %r10,%rbx
-       movb    %al,%dl
-       shrq    $4,%rax
-       movq    %r8,%r10
-       shrq    $4,%r8
-       movq    %r9,24(%rbp)
-       movq    80+0-128(%rsi),%r9
-       shlb    $4,%dl
-       movq    %rbx,24-128(%rbp)
-       movq    80+8-128(%rsi),%rbx
-       shlq    $60,%r10
-       movb    %dl,4(%rsp)
-       orq     %r10,%rax
-       movb    %bl,%dl
-       shrq    $4,%rbx
-       movq    %r9,%r10
-       shrq    $4,%r9
-       movq    %r8,32(%rbp)
-       movq    96+0-128(%rsi),%r8
-       shlb    $4,%dl
-       movq    %rax,32-128(%rbp)
-       movq    96+8-128(%rsi),%rax
-       shlq    $60,%r10
-       movb    %dl,5(%rsp)
-       orq     %r10,%rbx
-       movb    %al,%dl
-       shrq    $4,%rax
-       movq    %r8,%r10
-       shrq    $4,%r8
-       movq    %r9,40(%rbp)
-       movq    112+0-128(%rsi),%r9
-       shlb    $4,%dl
-       movq    %rbx,40-128(%rbp)
-       movq    112+8-128(%rsi),%rbx
-       shlq    $60,%r10
-       movb    %dl,6(%rsp)
-       orq     %r10,%rax
-       movb    %bl,%dl
-       shrq    $4,%rbx
-       movq    %r9,%r10
-       shrq    $4,%r9
-       movq    %r8,48(%rbp)
-       movq    128+0-128(%rsi),%r8
-       shlb    $4,%dl
-       movq    %rax,48-128(%rbp)
-       movq    128+8-128(%rsi),%rax
-       shlq    $60,%r10
-       movb    %dl,7(%rsp)
-       orq     %r10,%rbx
-       movb    %al,%dl
-       shrq    $4,%rax
-       movq    %r8,%r10
-       shrq    $4,%r8
-       movq    %r9,56(%rbp)
-       movq    144+0-128(%rsi),%r9
-       shlb    $4,%dl
-       movq    %rbx,56-128(%rbp)
-       movq    144+8-128(%rsi),%rbx
-       shlq    $60,%r10
-       movb    %dl,8(%rsp)
-       orq     %r10,%rax
-       movb    %bl,%dl
-       shrq    $4,%rbx
-       movq    %r9,%r10
-       shrq    $4,%r9
-       movq    %r8,64(%rbp)
-       movq    160+0-128(%rsi),%r8
-       shlb    $4,%dl
-       movq    %rax,64-128(%rbp)
-       movq    160+8-128(%rsi),%rax
-       shlq    $60,%r10
-       movb    %dl,9(%rsp)
-       orq     %r10,%rbx
-       movb    %al,%dl
-       shrq    $4,%rax
-       movq    %r8,%r10
-       shrq    $4,%r8
-       movq    %r9,72(%rbp)
-       movq    176+0-128(%rsi),%r9
-       shlb    $4,%dl
-       movq    %rbx,72-128(%rbp)
-       movq    176+8-128(%rsi),%rbx
-       shlq    $60,%r10
-       movb    %dl,10(%rsp)
-       orq     %r10,%rax
-       movb    %bl,%dl
-       shrq    $4,%rbx
-       movq    %r9,%r10
-       shrq    $4,%r9
-       movq    %r8,80(%rbp)
-       movq    192+0-128(%rsi),%r8
-       shlb    $4,%dl
-       movq    %rax,80-128(%rbp)
-       movq    192+8-128(%rsi),%rax
-       shlq    $60,%r10
-       movb    %dl,11(%rsp)
-       orq     %r10,%rbx
-       movb    %al,%dl
-       shrq    $4,%rax
-       movq    %r8,%r10
-       shrq    $4,%r8
-       movq    %r9,88(%rbp)
-       movq    208+0-128(%rsi),%r9
-       shlb    $4,%dl
-       movq    %rbx,88-128(%rbp)
-       movq    208+8-128(%rsi),%rbx
-       shlq    $60,%r10
-       movb    %dl,12(%rsp)
-       orq     %r10,%rax
-       movb    %bl,%dl
-       shrq    $4,%rbx
-       movq    %r9,%r10
-       shrq    $4,%r9
-       movq    %r8,96(%rbp)
-       movq    224+0-128(%rsi),%r8
-       shlb    $4,%dl
-       movq    %rax,96-128(%rbp)
-       movq    224+8-128(%rsi),%rax
-       shlq    $60,%r10
-       movb    %dl,13(%rsp)
-       orq     %r10,%rbx
-       movb    %al,%dl
-       shrq    $4,%rax
-       movq    %r8,%r10
-       shrq    $4,%r8
-       movq    %r9,104(%rbp)
-       movq    240+0-128(%rsi),%r9
-       shlb    $4,%dl
-       movq    %rbx,104-128(%rbp)
-       movq    240+8-128(%rsi),%rbx
-       shlq    $60,%r10
-       movb    %dl,14(%rsp)
-       orq     %r10,%rax
-       movb    %bl,%dl
-       shrq    $4,%rbx
-       movq    %r9,%r10
-       shrq    $4,%r9
-       movq    %r8,112(%rbp)
-       shlb    $4,%dl
-       movq    %rax,112-128(%rbp)
-       shlq    $60,%r10
-       movb    %dl,15(%rsp)
-       orq     %r10,%rbx
-       movq    %r9,120(%rbp)
-       movq    %rbx,120-128(%rbp)
-       addq    $-128,%rsi
-       movq    8(%rdi),%r8
-       movq    0(%rdi),%r9
-       addq    %r14,%r15
-       leaq    .Lrem_8bit(%rip),%r11
-       jmp     .Louter_loop
-.align 16
-.Louter_loop:
-       xorq    (%r14),%r9
-       movq    8(%r14),%rdx
-       leaq    16(%r14),%r14
-       xorq    %r8,%rdx
-       movq    %r9,(%rdi)
-       movq    %rdx,8(%rdi)
-       shrq    $32,%rdx
-       xorq    %rax,%rax
-       roll    $8,%edx
-       movb    %dl,%al
-       movzbl  %dl,%ebx
-       shlb    $4,%al
-       shrl    $4,%ebx
-       roll    $8,%edx
-       movq    8(%rsi,%rax,1),%r8
-       movq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       movzbl  %dl,%ecx
-       shlb    $4,%al
-       movzbq  (%rsp,%rbx,1),%r12
-       shrl    $4,%ecx
-       xorq    %r8,%r12
-       movq    %r9,%r10
-       shrq    $8,%r8
-       movzbq  %r12b,%r12
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rbx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rbx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r12,2),%r12
-       movzbl  %dl,%ebx
-       shlb    $4,%al
-       movzbq  (%rsp,%rcx,1),%r13
-       shrl    $4,%ebx
-       shlq    $48,%r12
-       xorq    %r8,%r13
-       movq    %r9,%r10
-       xorq    %r12,%r9
-       shrq    $8,%r8
-       movzbq  %r13b,%r13
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rcx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rcx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r13,2),%r13
-       movzbl  %dl,%ecx
-       shlb    $4,%al
-       movzbq  (%rsp,%rbx,1),%r12
-       shrl    $4,%ecx
-       shlq    $48,%r13
-       xorq    %r8,%r12
-       movq    %r9,%r10
-       xorq    %r13,%r9
-       shrq    $8,%r8
-       movzbq  %r12b,%r12
-       movl    8(%rdi),%edx
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rbx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rbx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r12,2),%r12
-       movzbl  %dl,%ebx
-       shlb    $4,%al
-       movzbq  (%rsp,%rcx,1),%r13
-       shrl    $4,%ebx
-       shlq    $48,%r12
-       xorq    %r8,%r13
-       movq    %r9,%r10
-       xorq    %r12,%r9
-       shrq    $8,%r8
-       movzbq  %r13b,%r13
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rcx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rcx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r13,2),%r13
-       movzbl  %dl,%ecx
-       shlb    $4,%al
-       movzbq  (%rsp,%rbx,1),%r12
-       shrl    $4,%ecx
-       shlq    $48,%r13
-       xorq    %r8,%r12
-       movq    %r9,%r10
-       xorq    %r13,%r9
-       shrq    $8,%r8
-       movzbq  %r12b,%r12
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rbx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rbx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r12,2),%r12
-       movzbl  %dl,%ebx
-       shlb    $4,%al
-       movzbq  (%rsp,%rcx,1),%r13
-       shrl    $4,%ebx
-       shlq    $48,%r12
-       xorq    %r8,%r13
-       movq    %r9,%r10
-       xorq    %r12,%r9
-       shrq    $8,%r8
-       movzbq  %r13b,%r13
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rcx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rcx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r13,2),%r13
-       movzbl  %dl,%ecx
-       shlb    $4,%al
-       movzbq  (%rsp,%rbx,1),%r12
-       shrl    $4,%ecx
-       shlq    $48,%r13
-       xorq    %r8,%r12
-       movq    %r9,%r10
-       xorq    %r13,%r9
-       shrq    $8,%r8
-       movzbq  %r12b,%r12
-       movl    4(%rdi),%edx
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rbx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rbx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r12,2),%r12
-       movzbl  %dl,%ebx
-       shlb    $4,%al
-       movzbq  (%rsp,%rcx,1),%r13
-       shrl    $4,%ebx
-       shlq    $48,%r12
-       xorq    %r8,%r13
-       movq    %r9,%r10
-       xorq    %r12,%r9
-       shrq    $8,%r8
-       movzbq  %r13b,%r13
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rcx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rcx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r13,2),%r13
-       movzbl  %dl,%ecx
-       shlb    $4,%al
-       movzbq  (%rsp,%rbx,1),%r12
-       shrl    $4,%ecx
-       shlq    $48,%r13
-       xorq    %r8,%r12
-       movq    %r9,%r10
-       xorq    %r13,%r9
-       shrq    $8,%r8
-       movzbq  %r12b,%r12
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rbx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rbx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r12,2),%r12
-       movzbl  %dl,%ebx
-       shlb    $4,%al
-       movzbq  (%rsp,%rcx,1),%r13
-       shrl    $4,%ebx
-       shlq    $48,%r12
-       xorq    %r8,%r13
-       movq    %r9,%r10
-       xorq    %r12,%r9
-       shrq    $8,%r8
-       movzbq  %r13b,%r13
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rcx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rcx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r13,2),%r13
-       movzbl  %dl,%ecx
-       shlb    $4,%al
-       movzbq  (%rsp,%rbx,1),%r12
-       shrl    $4,%ecx
-       shlq    $48,%r13
-       xorq    %r8,%r12
-       movq    %r9,%r10
-       xorq    %r13,%r9
-       shrq    $8,%r8
-       movzbq  %r12b,%r12
-       movl    0(%rdi),%edx
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rbx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rbx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r12,2),%r12
-       movzbl  %dl,%ebx
-       shlb    $4,%al
-       movzbq  (%rsp,%rcx,1),%r13
-       shrl    $4,%ebx
-       shlq    $48,%r12
-       xorq    %r8,%r13
-       movq    %r9,%r10
-       xorq    %r12,%r9
-       shrq    $8,%r8
-       movzbq  %r13b,%r13
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rcx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rcx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r13,2),%r13
-       movzbl  %dl,%ecx
-       shlb    $4,%al
-       movzbq  (%rsp,%rbx,1),%r12
-       shrl    $4,%ecx
-       shlq    $48,%r13
-       xorq    %r8,%r12
-       movq    %r9,%r10
-       xorq    %r13,%r9
-       shrq    $8,%r8
-       movzbq  %r12b,%r12
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rbx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rbx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r12,2),%r12
-       movzbl  %dl,%ebx
-       shlb    $4,%al
-       movzbq  (%rsp,%rcx,1),%r13
-       shrl    $4,%ebx
-       shlq    $48,%r12
-       xorq    %r8,%r13
-       movq    %r9,%r10
-       xorq    %r12,%r9
-       shrq    $8,%r8
-       movzbq  %r13b,%r13
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rcx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rcx,8),%r9
-       roll    $8,%edx
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       movb    %dl,%al
-       xorq    %r10,%r8
-       movzwq  (%r11,%r13,2),%r13
-       movzbl  %dl,%ecx
-       shlb    $4,%al
-       movzbq  (%rsp,%rbx,1),%r12
-       andl    $240,%ecx
-       shlq    $48,%r13
-       xorq    %r8,%r12
-       movq    %r9,%r10
-       xorq    %r13,%r9
-       shrq    $8,%r8
-       movzbq  %r12b,%r12
-       movl    -4(%rdi),%edx
-       shrq    $8,%r9
-       xorq    -128(%rbp,%rbx,8),%r8
-       shlq    $56,%r10
-       xorq    (%rbp,%rbx,8),%r9
-       movzwq  (%r11,%r12,2),%r12
-       xorq    8(%rsi,%rax,1),%r8
-       xorq    (%rsi,%rax,1),%r9
-       shlq    $48,%r12
-       xorq    %r10,%r8
-       xorq    %r12,%r9
-       movzbq  %r8b,%r13
-       shrq    $4,%r8
-       movq    %r9,%r10
-       shlb    $4,%r13b
-       shrq    $4,%r9
-       xorq    8(%rsi,%rcx,1),%r8
-       movzwq  (%r11,%r13,2),%r13
-       shlq    $60,%r10
-       xorq    (%rsi,%rcx,1),%r9
-       xorq    %r10,%r8
-       shlq    $48,%r13
-       bswapq  %r8
-       xorq    %r13,%r9
-       bswapq  %r9
-       cmpq    %r15,%r14
-       jb      .Louter_loop
-       movq    %r8,8(%rdi)
-       movq    %r9,(%rdi)
-
-       leaq    280(%rsp),%rsi
-       movq    0(%rsi),%r15
-       movq    8(%rsi),%r14
-       movq    16(%rsi),%r13
-       movq    24(%rsi),%r12
-       movq    32(%rsi),%rbp
-       movq    40(%rsi),%rbx
-       leaq    48(%rsi),%rsp
-.Lghash_epilogue:
-       .byte   0xf3,0xc3
-.size  gcm_ghash_4bit,.-gcm_ghash_4bit
-.globl gcm_init_clmul
-.type  gcm_init_clmul,@function
-.align 16
-gcm_init_clmul:
-       movdqu  (%rsi),%xmm2
-       pshufd  $78,%xmm2,%xmm2
-
-
-       pshufd  $255,%xmm2,%xmm4
-       movdqa  %xmm2,%xmm3
-       psllq   $1,%xmm2
-       pxor    %xmm5,%xmm5
-       psrlq   $63,%xmm3
-       pcmpgtd %xmm4,%xmm5
-       pslldq  $8,%xmm3
-       por     %xmm3,%xmm2
-
-
-       pand    .L0x1c2_polynomial(%rip),%xmm5
-       pxor    %xmm5,%xmm2
-
-
-       movdqa  %xmm2,%xmm0
-       movdqa  %xmm0,%xmm1
-       pshufd  $78,%xmm0,%xmm3
-       pshufd  $78,%xmm2,%xmm4
-       pxor    %xmm0,%xmm3
-       pxor    %xmm2,%xmm4
-.byte  102,15,58,68,194,0
-.byte  102,15,58,68,202,17
-.byte  102,15,58,68,220,0
-       pxor    %xmm0,%xmm3
-       pxor    %xmm1,%xmm3
-
-       movdqa  %xmm3,%xmm4
-       psrldq  $8,%xmm3
-       pslldq  $8,%xmm4
-       pxor    %xmm3,%xmm1
-       pxor    %xmm4,%xmm0
-
-       movdqa  %xmm0,%xmm3
-       psllq   $1,%xmm0
-       pxor    %xmm3,%xmm0
-       psllq   $5,%xmm0
-       pxor    %xmm3,%xmm0
-       psllq   $57,%xmm0
-       movdqa  %xmm0,%xmm4
-       pslldq  $8,%xmm0
-       psrldq  $8,%xmm4
-       pxor    %xmm3,%xmm0
-       pxor    %xmm4,%xmm1
-
-
-       movdqa  %xmm0,%xmm4
-       psrlq   $5,%xmm0
-       pxor    %xmm4,%xmm0
-       psrlq   $1,%xmm0
-       pxor    %xmm4,%xmm0
-       pxor    %xmm1,%xmm4
-       psrlq   $1,%xmm0
-       pxor    %xmm4,%xmm0
-       movdqu  %xmm2,(%rdi)
-       movdqu  %xmm0,16(%rdi)
-       .byte   0xf3,0xc3
-.size  gcm_init_clmul,.-gcm_init_clmul
-.globl gcm_gmult_clmul
-.type  gcm_gmult_clmul,@function
-.align 16
-gcm_gmult_clmul:
-       movdqu  (%rdi),%xmm0
-       movdqa  .Lbswap_mask(%rip),%xmm5
-       movdqu  (%rsi),%xmm2
-.byte  102,15,56,0,197
-       movdqa  %xmm0,%xmm1
-       pshufd  $78,%xmm0,%xmm3
-       pshufd  $78,%xmm2,%xmm4
-       pxor    %xmm0,%xmm3
-       pxor    %xmm2,%xmm4
-.byte  102,15,58,68,194,0
-.byte  102,15,58,68,202,17
-.byte  102,15,58,68,220,0
-       pxor    %xmm0,%xmm3
-       pxor    %xmm1,%xmm3
-
-       movdqa  %xmm3,%xmm4
-       psrldq  $8,%xmm3
-       pslldq  $8,%xmm4
-       pxor    %xmm3,%xmm1
-       pxor    %xmm4,%xmm0
-
-       movdqa  %xmm0,%xmm3
-       psllq   $1,%xmm0
-       pxor    %xmm3,%xmm0
-       psllq   $5,%xmm0
-       pxor    %xmm3,%xmm0
-       psllq   $57,%xmm0
-       movdqa  %xmm0,%xmm4
-       pslldq  $8,%xmm0
-       psrldq  $8,%xmm4
-       pxor    %xmm3,%xmm0
-       pxor    %xmm4,%xmm1
-
-
-       movdqa  %xmm0,%xmm4
-       psrlq   $5,%xmm0
-       pxor    %xmm4,%xmm0
-       psrlq   $1,%xmm0
-       pxor    %xmm4,%xmm0
-       pxor    %xmm1,%xmm4
-       psrlq   $1,%xmm0
-       pxor    %xmm4,%xmm0
-.byte  102,15,56,0,197
-       movdqu  %xmm0,(%rdi)
-       .byte   0xf3,0xc3
-.size  gcm_gmult_clmul,.-gcm_gmult_clmul
-.globl gcm_ghash_clmul
-.type  gcm_ghash_clmul,@function
-.align 16
-gcm_ghash_clmul:
-       movdqa  .Lbswap_mask(%rip),%xmm5
-
-       movdqu  (%rdi),%xmm0
-       movdqu  (%rsi),%xmm2
-.byte  102,15,56,0,197
-
-       subq    $16,%rcx
-       jz      .Lodd_tail
-
-       movdqu  16(%rsi),%xmm8
-
-
-
-
-
-       movdqu  (%rdx),%xmm3
-       movdqu  16(%rdx),%xmm6
-.byte  102,15,56,0,221
-.byte  102,15,56,0,245
-       pxor    %xmm3,%xmm0
-       movdqa  %xmm6,%xmm7
-       pshufd  $78,%xmm6,%xmm3
-       pshufd  $78,%xmm2,%xmm4
-       pxor    %xmm6,%xmm3
-       pxor    %xmm2,%xmm4
-.byte  102,15,58,68,242,0
-.byte  102,15,58,68,250,17
-.byte  102,15,58,68,220,0
-       pxor    %xmm6,%xmm3
-       pxor    %xmm7,%xmm3
-
-       movdqa  %xmm3,%xmm4
-       psrldq  $8,%xmm3
-       pslldq  $8,%xmm4
-       pxor    %xmm3,%xmm7
-       pxor    %xmm4,%xmm6
-       movdqa  %xmm0,%xmm1
-       pshufd  $78,%xmm0,%xmm3
-       pshufd  $78,%xmm8,%xmm4
-       pxor    %xmm0,%xmm3
-       pxor    %xmm8,%xmm4
-
-       leaq    32(%rdx),%rdx
-       subq    $32,%rcx
-       jbe     .Leven_tail
-
-.Lmod_loop:
-.byte  102,65,15,58,68,192,0
-.byte  102,65,15,58,68,200,17
-.byte  102,15,58,68,220,0
-       pxor    %xmm0,%xmm3
-       pxor    %xmm1,%xmm3
-
-       movdqa  %xmm3,%xmm4
-       psrldq  $8,%xmm3
-       pslldq  $8,%xmm4
-       pxor    %xmm3,%xmm1
-       pxor    %xmm4,%xmm0
-       movdqu  (%rdx),%xmm3
-       pxor    %xmm6,%xmm0
-       pxor    %xmm7,%xmm1
-
-       movdqu  16(%rdx),%xmm6
-.byte  102,15,56,0,221
-.byte  102,15,56,0,245
-
-       movdqa  %xmm6,%xmm7
-       pshufd  $78,%xmm6,%xmm9
-       pshufd  $78,%xmm2,%xmm10
-       pxor    %xmm6,%xmm9
-       pxor    %xmm2,%xmm10
-       pxor    %xmm3,%xmm1
-
-       movdqa  %xmm0,%xmm3
-       psllq   $1,%xmm0
-       pxor    %xmm3,%xmm0
-       psllq   $5,%xmm0
-       pxor    %xmm3,%xmm0
-.byte  102,15,58,68,242,0
-       psllq   $57,%xmm0
-       movdqa  %xmm0,%xmm4
-       pslldq  $8,%xmm0
-       psrldq  $8,%xmm4
-       pxor    %xmm3,%xmm0
-       pxor    %xmm4,%xmm1
-
-.byte  102,15,58,68,250,17
-       movdqa  %xmm0,%xmm4
-       psrlq   $5,%xmm0
-       pxor    %xmm4,%xmm0
-       psrlq   $1,%xmm0
-       pxor    %xmm4,%xmm0
-       pxor    %xmm1,%xmm4
-       psrlq   $1,%xmm0
-       pxor    %xmm4,%xmm0
-
-.byte  102,69,15,58,68,202,0
-       movdqa  %xmm0,%xmm1
-       pshufd  $78,%xmm0,%xmm3
-       pshufd  $78,%xmm8,%xmm4
-       pxor    %xmm0,%xmm3
-       pxor    %xmm8,%xmm4
-
-       pxor    %xmm6,%xmm9
-       pxor    %xmm7,%xmm9
-       movdqa  %xmm9,%xmm10
-       psrldq  $8,%xmm9
-       pslldq  $8,%xmm10
-       pxor    %xmm9,%xmm7
-       pxor    %xmm10,%xmm6
-
-       leaq    32(%rdx),%rdx
-       subq    $32,%rcx
-       ja      .Lmod_loop
-
-.Leven_tail:
-.byte  102,65,15,58,68,192,0
-.byte  102,65,15,58,68,200,17
-.byte  102,15,58,68,220,0
-       pxor    %xmm0,%xmm3
-       pxor    %xmm1,%xmm3
-
-       movdqa  %xmm3,%xmm4
-       psrldq  $8,%xmm3
-       pslldq  $8,%xmm4
-       pxor    %xmm3,%xmm1
-       pxor    %xmm4,%xmm0
-       pxor    %xmm6,%xmm0
-       pxor    %xmm7,%xmm1
-
-       movdqa  %xmm0,%xmm3
-       psllq   $1,%xmm0
-       pxor    %xmm3,%xmm0
-       psllq   $5,%xmm0
-       pxor    %xmm3,%xmm0
-       psllq   $57,%xmm0
-       movdqa  %xmm0,%xmm4
-       pslldq  $8,%xmm0
-       psrldq  $8,%xmm4
-       pxor    %xmm3,%xmm0
-       pxor    %xmm4,%xmm1
-
-
-       movdqa  %xmm0,%xmm4
-       psrlq   $5,%xmm0
-       pxor    %xmm4,%xmm0
-       psrlq   $1,%xmm0
-       pxor    %xmm4,%xmm0
-       pxor    %xmm1,%xmm4
-       psrlq   $1,%xmm0
-       pxor    %xmm4,%xmm0
-       testq   %rcx,%rcx
-       jnz     .Ldone
-
-.Lodd_tail:
-       movdqu  (%rdx),%xmm3
-.byte  102,15,56,0,221
-       pxor    %xmm3,%xmm0
-       movdqa  %xmm0,%xmm1
-       pshufd  $78,%xmm0,%xmm3
-       pshufd  $78,%xmm2,%xmm4
-       pxor    %xmm0,%xmm3
-       pxor    %xmm2,%xmm4
-.byte  102,15,58,68,194,0
-.byte  102,15,58,68,202,17
-.byte  102,15,58,68,220,0
-       pxor    %xmm0,%xmm3
-       pxor    %xmm1,%xmm3
-
-       movdqa  %xmm3,%xmm4
-       psrldq  $8,%xmm3
-       pslldq  $8,%xmm4
-       pxor    %xmm3,%xmm1
-       pxor    %xmm4,%xmm0
-
-       movdqa  %xmm0,%xmm3
-       psllq   $1,%xmm0
-       pxor    %xmm3,%xmm0
-       psllq   $5,%xmm0
-       pxor    %xmm3,%xmm0
-       psllq   $57,%xmm0
-       movdqa  %xmm0,%xmm4
-       pslldq  $8,%xmm0
-       psrldq  $8,%xmm4
-       pxor    %xmm3,%xmm0
-       pxor    %xmm4,%xmm1
-
-
-       movdqa  %xmm0,%xmm4
-       psrlq   $5,%xmm0
-       pxor    %xmm4,%xmm0
-       psrlq   $1,%xmm0
-       pxor    %xmm4,%xmm0
-       pxor    %xmm1,%xmm4
-       psrlq   $1,%xmm0
-       pxor    %xmm4,%xmm0
-.Ldone:
-.byte  102,15,56,0,197
-       movdqu  %xmm0,(%rdi)
-       .byte   0xf3,0xc3
-.LSEH_end_gcm_ghash_clmul:
-.size  gcm_ghash_clmul,.-gcm_ghash_clmul
-.align 64
-.Lbswap_mask:
-.byte  15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
-.L0x1c2_polynomial:
-.byte  1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xc2
-.align 64
-.type  .Lrem_4bit,@object
-.Lrem_4bit:
-.long  0,0,0,471859200,0,943718400,0,610271232
-.long  0,1887436800,0,1822425088,0,1220542464,0,1423966208
-.long  0,3774873600,0,4246732800,0,3644850176,0,3311403008
-.long  0,2441084928,0,2376073216,0,2847932416,0,3051356160
-.type  .Lrem_8bit,@object
-.Lrem_8bit:
-.value 0x0000,0x01C2,0x0384,0x0246,0x0708,0x06CA,0x048C,0x054E
-.value 0x0E10,0x0FD2,0x0D94,0x0C56,0x0918,0x08DA,0x0A9C,0x0B5E
-.value 0x1C20,0x1DE2,0x1FA4,0x1E66,0x1B28,0x1AEA,0x18AC,0x196E
-.value 0x1230,0x13F2,0x11B4,0x1076,0x1538,0x14FA,0x16BC,0x177E
-.value 0x3840,0x3982,0x3BC4,0x3A06,0x3F48,0x3E8A,0x3CCC,0x3D0E
-.value 0x3650,0x3792,0x35D4,0x3416,0x3158,0x309A,0x32DC,0x331E
-.value 0x2460,0x25A2,0x27E4,0x2626,0x2368,0x22AA,0x20EC,0x212E
-.value 0x2A70,0x2BB2,0x29F4,0x2836,0x2D78,0x2CBA,0x2EFC,0x2F3E
-.value 0x7080,0x7142,0x7304,0x72C6,0x7788,0x764A,0x740C,0x75CE
-.value 0x7E90,0x7F52,0x7D14,0x7CD6,0x7998,0x785A,0x7A1C,0x7BDE
-.value 0x6CA0,0x6D62,0x6F24,0x6EE6,0x6BA8,0x6A6A,0x682C,0x69EE
-.value 0x62B0,0x6372,0x6134,0x60F6,0x65B8,0x647A,0x663C,0x67FE
-.value 0x48C0,0x4902,0x4B44,0x4A86,0x4FC8,0x4E0A,0x4C4C,0x4D8E
-.value 0x46D0,0x4712,0x4554,0x4496,0x41D8,0x401A,0x425C,0x439E
-.value 0x54E0,0x5522,0x5764,0x56A6,0x53E8,0x522A,0x506C,0x51AE
-.value 0x5AF0,0x5B32,0x5974,0x58B6,0x5DF8,0x5C3A,0x5E7C,0x5FBE
-.value 0xE100,0xE0C2,0xE284,0xE346,0xE608,0xE7CA,0xE58C,0xE44E
-.value 0xEF10,0xEED2,0xEC94,0xED56,0xE818,0xE9DA,0xEB9C,0xEA5E
-.value 0xFD20,0xFCE2,0xFEA4,0xFF66,0xFA28,0xFBEA,0xF9AC,0xF86E
-.value 0xF330,0xF2F2,0xF0B4,0xF176,0xF438,0xF5FA,0xF7BC,0xF67E
-.value 0xD940,0xD882,0xDAC4,0xDB06,0xDE48,0xDF8A,0xDDCC,0xDC0E
-.value 0xD750,0xD692,0xD4D4,0xD516,0xD058,0xD19A,0xD3DC,0xD21E
-.value 0xC560,0xC4A2,0xC6E4,0xC726,0xC268,0xC3AA,0xC1EC,0xC02E
-.value 0xCB70,0xCAB2,0xC8F4,0xC936,0xCC78,0xCDBA,0xCFFC,0xCE3E
-.value 0x9180,0x9042,0x9204,0x93C6,0x9688,0x974A,0x950C,0x94CE
-.value 0x9F90,0x9E52,0x9C14,0x9DD6,0x9898,0x995A,0x9B1C,0x9ADE
-.value 0x8DA0,0x8C62,0x8E24,0x8FE6,0x8AA8,0x8B6A,0x892C,0x88EE
-.value 0x83B0,0x8272,0x8034,0x81F6,0x84B8,0x857A,0x873C,0x86FE
-.value 0xA9C0,0xA802,0xAA44,0xAB86,0xAEC8,0xAF0A,0xAD4C,0xAC8E
-.value 0xA7D0,0xA612,0xA454,0xA596,0xA0D8,0xA11A,0xA35C,0xA29E
-.value 0xB5E0,0xB422,0xB664,0xB7A6,0xB2E8,0xB32A,0xB16C,0xB0AE
-.value 0xBBF0,0xBA32,0xB874,0xB9B6,0xBCF8,0xBD3A,0xBF7C,0xBEBE
-
-.byte  
71,72,65,83,72,32,102,111,114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
-.align 64
-
-#if defined(__linux__) && defined(__ELF__)
-.section .note.GNU-stack,"",%progbits
-#endif
diff --git a/lib/accelerated/intel/asm/appro-aes-x86-64.s 
b/lib/accelerated/intel/asm/appro-aes-x86-64.s
deleted file mode 100644
index 675e112..0000000
--- a/lib/accelerated/intel/asm/appro-aes-x86-64.s
+++ /dev/null
@@ -1,2578 +0,0 @@
-# Copyright (c) 2011, Andy Polyakov by <address@hidden>
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 
-#     * Redistributions of source code must retain copyright notices,
-#      this list of conditions and the following disclaimer.
-#
-#     * Redistributions in binary form must reproduce the above
-#      copyright notice, this list of conditions and the following
-#      disclaimer in the documentation and/or other materials
-#      provided with the distribution.
-#
-#     * Neither the name of the Andy Polyakov nor the names of its
-#      copyright holder and contributors may be used to endorse or
-#      promote products derived from this software without specific
-#      prior written permission.
-#
-# ALTERNATIVELY, provided that this notice is retained in full, this
-# product may be distributed under the terms of the GNU General Public
-# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
-# those given above.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-.text  
-.globl aesni_encrypt
-.type  aesni_encrypt,@function
-.align 16
-aesni_encrypt:
-       movups  (%rdi),%xmm2
-       movl    240(%rdx),%eax
-       movups  (%rdx),%xmm0
-       movups  16(%rdx),%xmm1
-       leaq    32(%rdx),%rdx
-       xorps   %xmm0,%xmm2
-.Loop_enc1_1:
-.byte  102,15,56,220,209
-       decl    %eax
-       movups  (%rdx),%xmm1
-       leaq    16(%rdx),%rdx
-       jnz     .Loop_enc1_1    
-.byte  102,15,56,221,209
-       movups  %xmm2,(%rsi)
-       .byte   0xf3,0xc3
-.size  aesni_encrypt,.-aesni_encrypt
-
-.globl aesni_decrypt
-.type  aesni_decrypt,@function
-.align 16
-aesni_decrypt:
-       movups  (%rdi),%xmm2
-       movl    240(%rdx),%eax
-       movups  (%rdx),%xmm0
-       movups  16(%rdx),%xmm1
-       leaq    32(%rdx),%rdx
-       xorps   %xmm0,%xmm2
-.Loop_dec1_2:
-.byte  102,15,56,222,209
-       decl    %eax
-       movups  (%rdx),%xmm1
-       leaq    16(%rdx),%rdx
-       jnz     .Loop_dec1_2    
-.byte  102,15,56,223,209
-       movups  %xmm2,(%rsi)
-       .byte   0xf3,0xc3
-.size  aesni_decrypt, .-aesni_decrypt
-.type  _aesni_encrypt3,@function
-.align 16
-_aesni_encrypt3:
-       movups  (%rcx),%xmm0
-       shrl    $1,%eax
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-       xorps   %xmm0,%xmm3
-       xorps   %xmm0,%xmm4
-       movups  (%rcx),%xmm0
-
-.Lenc_loop3:
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-       decl    %eax
-.byte  102,15,56,220,225
-       movups  16(%rcx),%xmm1
-.byte  102,15,56,220,208
-.byte  102,15,56,220,216
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,220,224
-       movups  (%rcx),%xmm0
-       jnz     .Lenc_loop3
-
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-.byte  102,15,56,220,225
-.byte  102,15,56,221,208
-.byte  102,15,56,221,216
-.byte  102,15,56,221,224
-       .byte   0xf3,0xc3
-.size  _aesni_encrypt3,.-_aesni_encrypt3
-.type  _aesni_decrypt3,@function
-.align 16
-_aesni_decrypt3:
-       movups  (%rcx),%xmm0
-       shrl    $1,%eax
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-       xorps   %xmm0,%xmm3
-       xorps   %xmm0,%xmm4
-       movups  (%rcx),%xmm0
-
-.Ldec_loop3:
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-       decl    %eax
-.byte  102,15,56,222,225
-       movups  16(%rcx),%xmm1
-.byte  102,15,56,222,208
-.byte  102,15,56,222,216
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,222,224
-       movups  (%rcx),%xmm0
-       jnz     .Ldec_loop3
-
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-.byte  102,15,56,222,225
-.byte  102,15,56,223,208
-.byte  102,15,56,223,216
-.byte  102,15,56,223,224
-       .byte   0xf3,0xc3
-.size  _aesni_decrypt3,.-_aesni_decrypt3
-.type  _aesni_encrypt4,@function
-.align 16
-_aesni_encrypt4:
-       movups  (%rcx),%xmm0
-       shrl    $1,%eax
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-       xorps   %xmm0,%xmm3
-       xorps   %xmm0,%xmm4
-       xorps   %xmm0,%xmm5
-       movups  (%rcx),%xmm0
-
-.Lenc_loop4:
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-       decl    %eax
-.byte  102,15,56,220,225
-.byte  102,15,56,220,233
-       movups  16(%rcx),%xmm1
-.byte  102,15,56,220,208
-.byte  102,15,56,220,216
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,220,224
-.byte  102,15,56,220,232
-       movups  (%rcx),%xmm0
-       jnz     .Lenc_loop4
-
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-.byte  102,15,56,220,225
-.byte  102,15,56,220,233
-.byte  102,15,56,221,208
-.byte  102,15,56,221,216
-.byte  102,15,56,221,224
-.byte  102,15,56,221,232
-       .byte   0xf3,0xc3
-.size  _aesni_encrypt4,.-_aesni_encrypt4
-.type  _aesni_decrypt4,@function
-.align 16
-_aesni_decrypt4:
-       movups  (%rcx),%xmm0
-       shrl    $1,%eax
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-       xorps   %xmm0,%xmm3
-       xorps   %xmm0,%xmm4
-       xorps   %xmm0,%xmm5
-       movups  (%rcx),%xmm0
-
-.Ldec_loop4:
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-       decl    %eax
-.byte  102,15,56,222,225
-.byte  102,15,56,222,233
-       movups  16(%rcx),%xmm1
-.byte  102,15,56,222,208
-.byte  102,15,56,222,216
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,222,224
-.byte  102,15,56,222,232
-       movups  (%rcx),%xmm0
-       jnz     .Ldec_loop4
-
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-.byte  102,15,56,222,225
-.byte  102,15,56,222,233
-.byte  102,15,56,223,208
-.byte  102,15,56,223,216
-.byte  102,15,56,223,224
-.byte  102,15,56,223,232
-       .byte   0xf3,0xc3
-.size  _aesni_decrypt4,.-_aesni_decrypt4
-.type  _aesni_encrypt6,@function
-.align 16
-_aesni_encrypt6:
-       movups  (%rcx),%xmm0
-       shrl    $1,%eax
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-       pxor    %xmm0,%xmm3
-.byte  102,15,56,220,209
-       pxor    %xmm0,%xmm4
-.byte  102,15,56,220,217
-       pxor    %xmm0,%xmm5
-.byte  102,15,56,220,225
-       pxor    %xmm0,%xmm6
-.byte  102,15,56,220,233
-       pxor    %xmm0,%xmm7
-       decl    %eax
-.byte  102,15,56,220,241
-       movups  (%rcx),%xmm0
-.byte  102,15,56,220,249
-       jmp     .Lenc_loop6_enter
-.align 16
-.Lenc_loop6:
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-       decl    %eax
-.byte  102,15,56,220,225
-.byte  102,15,56,220,233
-.byte  102,15,56,220,241
-.byte  102,15,56,220,249
-.Lenc_loop6_enter:
-       movups  16(%rcx),%xmm1
-.byte  102,15,56,220,208
-.byte  102,15,56,220,216
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,220,224
-.byte  102,15,56,220,232
-.byte  102,15,56,220,240
-.byte  102,15,56,220,248
-       movups  (%rcx),%xmm0
-       jnz     .Lenc_loop6
-
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-.byte  102,15,56,220,225
-.byte  102,15,56,220,233
-.byte  102,15,56,220,241
-.byte  102,15,56,220,249
-.byte  102,15,56,221,208
-.byte  102,15,56,221,216
-.byte  102,15,56,221,224
-.byte  102,15,56,221,232
-.byte  102,15,56,221,240
-.byte  102,15,56,221,248
-       .byte   0xf3,0xc3
-.size  _aesni_encrypt6,.-_aesni_encrypt6
-.type  _aesni_decrypt6,@function
-.align 16
-_aesni_decrypt6:
-       movups  (%rcx),%xmm0
-       shrl    $1,%eax
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-       pxor    %xmm0,%xmm3
-.byte  102,15,56,222,209
-       pxor    %xmm0,%xmm4
-.byte  102,15,56,222,217
-       pxor    %xmm0,%xmm5
-.byte  102,15,56,222,225
-       pxor    %xmm0,%xmm6
-.byte  102,15,56,222,233
-       pxor    %xmm0,%xmm7
-       decl    %eax
-.byte  102,15,56,222,241
-       movups  (%rcx),%xmm0
-.byte  102,15,56,222,249
-       jmp     .Ldec_loop6_enter
-.align 16
-.Ldec_loop6:
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-       decl    %eax
-.byte  102,15,56,222,225
-.byte  102,15,56,222,233
-.byte  102,15,56,222,241
-.byte  102,15,56,222,249
-.Ldec_loop6_enter:
-       movups  16(%rcx),%xmm1
-.byte  102,15,56,222,208
-.byte  102,15,56,222,216
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,222,224
-.byte  102,15,56,222,232
-.byte  102,15,56,222,240
-.byte  102,15,56,222,248
-       movups  (%rcx),%xmm0
-       jnz     .Ldec_loop6
-
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-.byte  102,15,56,222,225
-.byte  102,15,56,222,233
-.byte  102,15,56,222,241
-.byte  102,15,56,222,249
-.byte  102,15,56,223,208
-.byte  102,15,56,223,216
-.byte  102,15,56,223,224
-.byte  102,15,56,223,232
-.byte  102,15,56,223,240
-.byte  102,15,56,223,248
-       .byte   0xf3,0xc3
-.size  _aesni_decrypt6,.-_aesni_decrypt6
-.type  _aesni_encrypt8,@function
-.align 16
-_aesni_encrypt8:
-       movups  (%rcx),%xmm0
-       shrl    $1,%eax
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-       xorps   %xmm0,%xmm3
-.byte  102,15,56,220,209
-       pxor    %xmm0,%xmm4
-.byte  102,15,56,220,217
-       pxor    %xmm0,%xmm5
-.byte  102,15,56,220,225
-       pxor    %xmm0,%xmm6
-.byte  102,15,56,220,233
-       pxor    %xmm0,%xmm7
-       decl    %eax
-.byte  102,15,56,220,241
-       pxor    %xmm0,%xmm8
-.byte  102,15,56,220,249
-       pxor    %xmm0,%xmm9
-       movups  (%rcx),%xmm0
-.byte  102,68,15,56,220,193
-.byte  102,68,15,56,220,201
-       movups  16(%rcx),%xmm1
-       jmp     .Lenc_loop8_enter
-.align 16
-.Lenc_loop8:
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-       decl    %eax
-.byte  102,15,56,220,225
-.byte  102,15,56,220,233
-.byte  102,15,56,220,241
-.byte  102,15,56,220,249
-.byte  102,68,15,56,220,193
-.byte  102,68,15,56,220,201
-       movups  16(%rcx),%xmm1
-.Lenc_loop8_enter:
-.byte  102,15,56,220,208
-.byte  102,15,56,220,216
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,220,224
-.byte  102,15,56,220,232
-.byte  102,15,56,220,240
-.byte  102,15,56,220,248
-.byte  102,68,15,56,220,192
-.byte  102,68,15,56,220,200
-       movups  (%rcx),%xmm0
-       jnz     .Lenc_loop8
-
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-.byte  102,15,56,220,225
-.byte  102,15,56,220,233
-.byte  102,15,56,220,241
-.byte  102,15,56,220,249
-.byte  102,68,15,56,220,193
-.byte  102,68,15,56,220,201
-.byte  102,15,56,221,208
-.byte  102,15,56,221,216
-.byte  102,15,56,221,224
-.byte  102,15,56,221,232
-.byte  102,15,56,221,240
-.byte  102,15,56,221,248
-.byte  102,68,15,56,221,192
-.byte  102,68,15,56,221,200
-       .byte   0xf3,0xc3
-.size  _aesni_encrypt8,.-_aesni_encrypt8
-.type  _aesni_decrypt8,@function
-.align 16
-_aesni_decrypt8:
-       movups  (%rcx),%xmm0
-       shrl    $1,%eax
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-       xorps   %xmm0,%xmm3
-.byte  102,15,56,222,209
-       pxor    %xmm0,%xmm4
-.byte  102,15,56,222,217
-       pxor    %xmm0,%xmm5
-.byte  102,15,56,222,225
-       pxor    %xmm0,%xmm6
-.byte  102,15,56,222,233
-       pxor    %xmm0,%xmm7
-       decl    %eax
-.byte  102,15,56,222,241
-       pxor    %xmm0,%xmm8
-.byte  102,15,56,222,249
-       pxor    %xmm0,%xmm9
-       movups  (%rcx),%xmm0
-.byte  102,68,15,56,222,193
-.byte  102,68,15,56,222,201
-       movups  16(%rcx),%xmm1
-       jmp     .Ldec_loop8_enter
-.align 16
-.Ldec_loop8:
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-       decl    %eax
-.byte  102,15,56,222,225
-.byte  102,15,56,222,233
-.byte  102,15,56,222,241
-.byte  102,15,56,222,249
-.byte  102,68,15,56,222,193
-.byte  102,68,15,56,222,201
-       movups  16(%rcx),%xmm1
-.Ldec_loop8_enter:
-.byte  102,15,56,222,208
-.byte  102,15,56,222,216
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,222,224
-.byte  102,15,56,222,232
-.byte  102,15,56,222,240
-.byte  102,15,56,222,248
-.byte  102,68,15,56,222,192
-.byte  102,68,15,56,222,200
-       movups  (%rcx),%xmm0
-       jnz     .Ldec_loop8
-
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-.byte  102,15,56,222,225
-.byte  102,15,56,222,233
-.byte  102,15,56,222,241
-.byte  102,15,56,222,249
-.byte  102,68,15,56,222,193
-.byte  102,68,15,56,222,201
-.byte  102,15,56,223,208
-.byte  102,15,56,223,216
-.byte  102,15,56,223,224
-.byte  102,15,56,223,232
-.byte  102,15,56,223,240
-.byte  102,15,56,223,248
-.byte  102,68,15,56,223,192
-.byte  102,68,15,56,223,200
-       .byte   0xf3,0xc3
-.size  _aesni_decrypt8,.-_aesni_decrypt8
-.globl aesni_ecb_encrypt
-.type  aesni_ecb_encrypt,@function
-.align 16
-aesni_ecb_encrypt:
-       andq    $-16,%rdx
-       jz      .Lecb_ret
-
-       movl    240(%rcx),%eax
-       movups  (%rcx),%xmm0
-       movq    %rcx,%r11
-       movl    %eax,%r10d
-       testl   %r8d,%r8d
-       jz      .Lecb_decrypt
-
-       cmpq    $128,%rdx
-       jb      .Lecb_enc_tail
-
-       movdqu  (%rdi),%xmm2
-       movdqu  16(%rdi),%xmm3
-       movdqu  32(%rdi),%xmm4
-       movdqu  48(%rdi),%xmm5
-       movdqu  64(%rdi),%xmm6
-       movdqu  80(%rdi),%xmm7
-       movdqu  96(%rdi),%xmm8
-       movdqu  112(%rdi),%xmm9
-       leaq    128(%rdi),%rdi
-       subq    $128,%rdx
-       jmp     .Lecb_enc_loop8_enter
-.align 16
-.Lecb_enc_loop8:
-       movups  %xmm2,(%rsi)
-       movq    %r11,%rcx
-       movdqu  (%rdi),%xmm2
-       movl    %r10d,%eax
-       movups  %xmm3,16(%rsi)
-       movdqu  16(%rdi),%xmm3
-       movups  %xmm4,32(%rsi)
-       movdqu  32(%rdi),%xmm4
-       movups  %xmm5,48(%rsi)
-       movdqu  48(%rdi),%xmm5
-       movups  %xmm6,64(%rsi)
-       movdqu  64(%rdi),%xmm6
-       movups  %xmm7,80(%rsi)
-       movdqu  80(%rdi),%xmm7
-       movups  %xmm8,96(%rsi)
-       movdqu  96(%rdi),%xmm8
-       movups  %xmm9,112(%rsi)
-       leaq    128(%rsi),%rsi
-       movdqu  112(%rdi),%xmm9
-       leaq    128(%rdi),%rdi
-.Lecb_enc_loop8_enter:
-
-       call    _aesni_encrypt8
-
-       subq    $128,%rdx
-       jnc     .Lecb_enc_loop8
-
-       movups  %xmm2,(%rsi)
-       movq    %r11,%rcx
-       movups  %xmm3,16(%rsi)
-       movl    %r10d,%eax
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       movups  %xmm6,64(%rsi)
-       movups  %xmm7,80(%rsi)
-       movups  %xmm8,96(%rsi)
-       movups  %xmm9,112(%rsi)
-       leaq    128(%rsi),%rsi
-       addq    $128,%rdx
-       jz      .Lecb_ret
-
-.Lecb_enc_tail:
-       movups  (%rdi),%xmm2
-       cmpq    $32,%rdx
-       jb      .Lecb_enc_one
-       movups  16(%rdi),%xmm3
-       je      .Lecb_enc_two
-       movups  32(%rdi),%xmm4
-       cmpq    $64,%rdx
-       jb      .Lecb_enc_three
-       movups  48(%rdi),%xmm5
-       je      .Lecb_enc_four
-       movups  64(%rdi),%xmm6
-       cmpq    $96,%rdx
-       jb      .Lecb_enc_five
-       movups  80(%rdi),%xmm7
-       je      .Lecb_enc_six
-       movdqu  96(%rdi),%xmm8
-       call    _aesni_encrypt8
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       movups  %xmm6,64(%rsi)
-       movups  %xmm7,80(%rsi)
-       movups  %xmm8,96(%rsi)
-       jmp     .Lecb_ret
-.align 16
-.Lecb_enc_one:
-       movups  (%rcx),%xmm0
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-.Loop_enc1_3:
-.byte  102,15,56,220,209
-       decl    %eax
-       movups  (%rcx),%xmm1
-       leaq    16(%rcx),%rcx
-       jnz     .Loop_enc1_3    
-.byte  102,15,56,221,209
-       movups  %xmm2,(%rsi)
-       jmp     .Lecb_ret
-.align 16
-.Lecb_enc_two:
-       xorps   %xmm4,%xmm4
-       call    _aesni_encrypt3
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       jmp     .Lecb_ret
-.align 16
-.Lecb_enc_three:
-       call    _aesni_encrypt3
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       jmp     .Lecb_ret
-.align 16
-.Lecb_enc_four:
-       call    _aesni_encrypt4
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       jmp     .Lecb_ret
-.align 16
-.Lecb_enc_five:
-       xorps   %xmm7,%xmm7
-       call    _aesni_encrypt6
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       movups  %xmm6,64(%rsi)
-       jmp     .Lecb_ret
-.align 16
-.Lecb_enc_six:
-       call    _aesni_encrypt6
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       movups  %xmm6,64(%rsi)
-       movups  %xmm7,80(%rsi)
-       jmp     .Lecb_ret
-
-.align 16
-.Lecb_decrypt:
-       cmpq    $128,%rdx
-       jb      .Lecb_dec_tail
-
-       movdqu  (%rdi),%xmm2
-       movdqu  16(%rdi),%xmm3
-       movdqu  32(%rdi),%xmm4
-       movdqu  48(%rdi),%xmm5
-       movdqu  64(%rdi),%xmm6
-       movdqu  80(%rdi),%xmm7
-       movdqu  96(%rdi),%xmm8
-       movdqu  112(%rdi),%xmm9
-       leaq    128(%rdi),%rdi
-       subq    $128,%rdx
-       jmp     .Lecb_dec_loop8_enter
-.align 16
-.Lecb_dec_loop8:
-       movups  %xmm2,(%rsi)
-       movq    %r11,%rcx
-       movdqu  (%rdi),%xmm2
-       movl    %r10d,%eax
-       movups  %xmm3,16(%rsi)
-       movdqu  16(%rdi),%xmm3
-       movups  %xmm4,32(%rsi)
-       movdqu  32(%rdi),%xmm4
-       movups  %xmm5,48(%rsi)
-       movdqu  48(%rdi),%xmm5
-       movups  %xmm6,64(%rsi)
-       movdqu  64(%rdi),%xmm6
-       movups  %xmm7,80(%rsi)
-       movdqu  80(%rdi),%xmm7
-       movups  %xmm8,96(%rsi)
-       movdqu  96(%rdi),%xmm8
-       movups  %xmm9,112(%rsi)
-       leaq    128(%rsi),%rsi
-       movdqu  112(%rdi),%xmm9
-       leaq    128(%rdi),%rdi
-.Lecb_dec_loop8_enter:
-
-       call    _aesni_decrypt8
-
-       movups  (%r11),%xmm0
-       subq    $128,%rdx
-       jnc     .Lecb_dec_loop8
-
-       movups  %xmm2,(%rsi)
-       movq    %r11,%rcx
-       movups  %xmm3,16(%rsi)
-       movl    %r10d,%eax
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       movups  %xmm6,64(%rsi)
-       movups  %xmm7,80(%rsi)
-       movups  %xmm8,96(%rsi)
-       movups  %xmm9,112(%rsi)
-       leaq    128(%rsi),%rsi
-       addq    $128,%rdx
-       jz      .Lecb_ret
-
-.Lecb_dec_tail:
-       movups  (%rdi),%xmm2
-       cmpq    $32,%rdx
-       jb      .Lecb_dec_one
-       movups  16(%rdi),%xmm3
-       je      .Lecb_dec_two
-       movups  32(%rdi),%xmm4
-       cmpq    $64,%rdx
-       jb      .Lecb_dec_three
-       movups  48(%rdi),%xmm5
-       je      .Lecb_dec_four
-       movups  64(%rdi),%xmm6
-       cmpq    $96,%rdx
-       jb      .Lecb_dec_five
-       movups  80(%rdi),%xmm7
-       je      .Lecb_dec_six
-       movups  96(%rdi),%xmm8
-       movups  (%rcx),%xmm0
-       call    _aesni_decrypt8
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       movups  %xmm6,64(%rsi)
-       movups  %xmm7,80(%rsi)
-       movups  %xmm8,96(%rsi)
-       jmp     .Lecb_ret
-.align 16
-.Lecb_dec_one:
-       movups  (%rcx),%xmm0
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-.Loop_dec1_4:
-.byte  102,15,56,222,209
-       decl    %eax
-       movups  (%rcx),%xmm1
-       leaq    16(%rcx),%rcx
-       jnz     .Loop_dec1_4    
-.byte  102,15,56,223,209
-       movups  %xmm2,(%rsi)
-       jmp     .Lecb_ret
-.align 16
-.Lecb_dec_two:
-       xorps   %xmm4,%xmm4
-       call    _aesni_decrypt3
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       jmp     .Lecb_ret
-.align 16
-.Lecb_dec_three:
-       call    _aesni_decrypt3
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       jmp     .Lecb_ret
-.align 16
-.Lecb_dec_four:
-       call    _aesni_decrypt4
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       jmp     .Lecb_ret
-.align 16
-.Lecb_dec_five:
-       xorps   %xmm7,%xmm7
-       call    _aesni_decrypt6
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       movups  %xmm6,64(%rsi)
-       jmp     .Lecb_ret
-.align 16
-.Lecb_dec_six:
-       call    _aesni_decrypt6
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       movups  %xmm6,64(%rsi)
-       movups  %xmm7,80(%rsi)
-
-.Lecb_ret:
-       .byte   0xf3,0xc3
-.size  aesni_ecb_encrypt,.-aesni_ecb_encrypt
-.globl aesni_ccm64_encrypt_blocks
-.type  aesni_ccm64_encrypt_blocks,@function
-.align 16
-aesni_ccm64_encrypt_blocks:
-       movl    240(%rcx),%eax
-       movdqu  (%r8),%xmm9
-       movdqa  .Lincrement64(%rip),%xmm6
-       movdqa  .Lbswap_mask(%rip),%xmm7
-
-       shrl    $1,%eax
-       leaq    0(%rcx),%r11
-       movdqu  (%r9),%xmm3
-       movdqa  %xmm9,%xmm2
-       movl    %eax,%r10d
-       jmp     .Lccm64_enc_outer
-.align 16
-.Lccm64_enc_outer:
-       movups  (%r11),%xmm0
-       movl    %r10d,%eax
-       movups  (%rdi),%xmm8
-
-       xorps   %xmm0,%xmm2
-       movups  16(%r11),%xmm1
-       xorps   %xmm8,%xmm0
-       leaq    32(%r11),%rcx
-       xorps   %xmm0,%xmm3
-       movups  (%rcx),%xmm0
-
-.Lccm64_enc2_loop:
-.byte  102,15,56,220,209
-       decl    %eax
-.byte  102,15,56,220,217
-       movups  16(%rcx),%xmm1
-.byte  102,15,56,220,208
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,220,216
-       movups  0(%rcx),%xmm0
-       jnz     .Lccm64_enc2_loop
-.byte  102,68,15,56,0,207
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-       paddq   %xmm6,%xmm9
-.byte  102,15,56,221,208
-.byte  102,15,56,221,216
-
-       decq    %rdx
-       leaq    16(%rdi),%rdi
-       xorps   %xmm2,%xmm8
-       movdqa  %xmm9,%xmm2
-       movups  %xmm8,(%rsi)
-       leaq    16(%rsi),%rsi
-.byte  102,68,15,56,0,207
-       jnz     .Lccm64_enc_outer
-
-       movups  %xmm3,(%r9)
-       .byte   0xf3,0xc3
-.size  aesni_ccm64_encrypt_blocks,.-aesni_ccm64_encrypt_blocks
-.globl aesni_ccm64_decrypt_blocks
-.type  aesni_ccm64_decrypt_blocks,@function
-.align 16
-aesni_ccm64_decrypt_blocks:
-       movl    240(%rcx),%eax
-       movups  (%r8),%xmm9
-       movdqu  (%r9),%xmm3
-       movdqa  .Lincrement64(%rip),%xmm6
-       movdqa  .Lbswap_mask(%rip),%xmm7
-
-       movaps  %xmm9,%xmm2
-       movl    %eax,%r10d
-       movq    %rcx,%r11
-.byte  102,68,15,56,0,207
-       movups  (%rcx),%xmm0
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-.Loop_enc1_5:
-.byte  102,15,56,220,209
-       decl    %eax
-       movups  (%rcx),%xmm1
-       leaq    16(%rcx),%rcx
-       jnz     .Loop_enc1_5    
-.byte  102,15,56,221,209
-       movups  (%rdi),%xmm8
-       paddq   %xmm6,%xmm9
-.byte  102,68,15,56,0,207
-       leaq    16(%rdi),%rdi
-       jmp     .Lccm64_dec_outer
-.align 16
-.Lccm64_dec_outer:
-       xorps   %xmm2,%xmm8
-       movdqa  %xmm9,%xmm2
-       movl    %r10d,%eax
-       movups  %xmm8,(%rsi)
-       leaq    16(%rsi),%rsi
-
-       subq    $1,%rdx
-       jz      .Lccm64_dec_break
-
-       movups  (%r11),%xmm0
-       shrl    $1,%eax
-       movups  16(%r11),%xmm1
-       xorps   %xmm0,%xmm8
-       leaq    32(%r11),%rcx
-       xorps   %xmm0,%xmm2
-       xorps   %xmm8,%xmm3
-       movups  (%rcx),%xmm0
-
-.Lccm64_dec2_loop:
-.byte  102,15,56,220,209
-       decl    %eax
-.byte  102,15,56,220,217
-       movups  16(%rcx),%xmm1
-.byte  102,15,56,220,208
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,220,216
-       movups  0(%rcx),%xmm0
-       jnz     .Lccm64_dec2_loop
-       movups  (%rdi),%xmm8
-       paddq   %xmm6,%xmm9
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-.byte  102,68,15,56,0,207
-       leaq    16(%rdi),%rdi
-.byte  102,15,56,221,208
-.byte  102,15,56,221,216
-       jmp     .Lccm64_dec_outer
-
-.align 16
-.Lccm64_dec_break:
-
-       movups  (%r11),%xmm0
-       movups  16(%r11),%xmm1
-       xorps   %xmm0,%xmm8
-       leaq    32(%r11),%r11
-       xorps   %xmm8,%xmm3
-.Loop_enc1_6:
-.byte  102,15,56,220,217
-       decl    %eax
-       movups  (%r11),%xmm1
-       leaq    16(%r11),%r11
-       jnz     .Loop_enc1_6    
-.byte  102,15,56,221,217
-       movups  %xmm3,(%r9)
-       .byte   0xf3,0xc3
-.size  aesni_ccm64_decrypt_blocks,.-aesni_ccm64_decrypt_blocks
-.globl aesni_ctr32_encrypt_blocks
-.type  aesni_ctr32_encrypt_blocks,@function
-.align 16
-aesni_ctr32_encrypt_blocks:
-       cmpq    $1,%rdx
-       je      .Lctr32_one_shortcut
-
-       movdqu  (%r8),%xmm14
-       movdqa  .Lbswap_mask(%rip),%xmm15
-       xorl    %eax,%eax
-.byte  102,69,15,58,22,242,3
-.byte  102,68,15,58,34,240,3
-
-       movl    240(%rcx),%eax
-       bswapl  %r10d
-       pxor    %xmm12,%xmm12
-       pxor    %xmm13,%xmm13
-.byte  102,69,15,58,34,226,0
-       leaq    3(%r10),%r11
-.byte  102,69,15,58,34,235,0
-       incl    %r10d
-.byte  102,69,15,58,34,226,1
-       incq    %r11
-.byte  102,69,15,58,34,235,1
-       incl    %r10d
-.byte  102,69,15,58,34,226,2
-       incq    %r11
-.byte  102,69,15,58,34,235,2
-       movdqa  %xmm12,-40(%rsp)
-.byte  102,69,15,56,0,231
-       movdqa  %xmm13,-24(%rsp)
-.byte  102,69,15,56,0,239
-
-       pshufd  $192,%xmm12,%xmm2
-       pshufd  $128,%xmm12,%xmm3
-       pshufd  $64,%xmm12,%xmm4
-       cmpq    $6,%rdx
-       jb      .Lctr32_tail
-       shrl    $1,%eax
-       movq    %rcx,%r11
-       movl    %eax,%r10d
-       subq    $6,%rdx
-       jmp     .Lctr32_loop6
-
-.align 16
-.Lctr32_loop6:
-       pshufd  $192,%xmm13,%xmm5
-       por     %xmm14,%xmm2
-       movups  (%r11),%xmm0
-       pshufd  $128,%xmm13,%xmm6
-       por     %xmm14,%xmm3
-       movups  16(%r11),%xmm1
-       pshufd  $64,%xmm13,%xmm7
-       por     %xmm14,%xmm4
-       por     %xmm14,%xmm5
-       xorps   %xmm0,%xmm2
-       por     %xmm14,%xmm6
-       por     %xmm14,%xmm7
-
-
-
-
-       pxor    %xmm0,%xmm3
-.byte  102,15,56,220,209
-       leaq    32(%r11),%rcx
-       pxor    %xmm0,%xmm4
-.byte  102,15,56,220,217
-       movdqa  .Lincrement32(%rip),%xmm13
-       pxor    %xmm0,%xmm5
-.byte  102,15,56,220,225
-       movdqa  -40(%rsp),%xmm12
-       pxor    %xmm0,%xmm6
-.byte  102,15,56,220,233
-       pxor    %xmm0,%xmm7
-       movups  (%rcx),%xmm0
-       decl    %eax
-.byte  102,15,56,220,241
-.byte  102,15,56,220,249
-       jmp     .Lctr32_enc_loop6_enter
-.align 16
-.Lctr32_enc_loop6:
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-       decl    %eax
-.byte  102,15,56,220,225
-.byte  102,15,56,220,233
-.byte  102,15,56,220,241
-.byte  102,15,56,220,249
-.Lctr32_enc_loop6_enter:
-       movups  16(%rcx),%xmm1
-.byte  102,15,56,220,208
-.byte  102,15,56,220,216
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,220,224
-.byte  102,15,56,220,232
-.byte  102,15,56,220,240
-.byte  102,15,56,220,248
-       movups  (%rcx),%xmm0
-       jnz     .Lctr32_enc_loop6
-
-.byte  102,15,56,220,209
-       paddd   %xmm13,%xmm12
-.byte  102,15,56,220,217
-       paddd   -24(%rsp),%xmm13
-.byte  102,15,56,220,225
-       movdqa  %xmm12,-40(%rsp)
-.byte  102,15,56,220,233
-       movdqa  %xmm13,-24(%rsp)
-.byte  102,15,56,220,241
-.byte  102,69,15,56,0,231
-.byte  102,15,56,220,249
-.byte  102,69,15,56,0,239
-
-.byte  102,15,56,221,208
-       movups  (%rdi),%xmm8
-.byte  102,15,56,221,216
-       movups  16(%rdi),%xmm9
-.byte  102,15,56,221,224
-       movups  32(%rdi),%xmm10
-.byte  102,15,56,221,232
-       movups  48(%rdi),%xmm11
-.byte  102,15,56,221,240
-       movups  64(%rdi),%xmm1
-.byte  102,15,56,221,248
-       movups  80(%rdi),%xmm0
-       leaq    96(%rdi),%rdi
-
-       xorps   %xmm2,%xmm8
-       pshufd  $192,%xmm12,%xmm2
-       xorps   %xmm3,%xmm9
-       pshufd  $128,%xmm12,%xmm3
-       movups  %xmm8,(%rsi)
-       xorps   %xmm4,%xmm10
-       pshufd  $64,%xmm12,%xmm4
-       movups  %xmm9,16(%rsi)
-       xorps   %xmm5,%xmm11
-       movups  %xmm10,32(%rsi)
-       xorps   %xmm6,%xmm1
-       movups  %xmm11,48(%rsi)
-       xorps   %xmm7,%xmm0
-       movups  %xmm1,64(%rsi)
-       movups  %xmm0,80(%rsi)
-       leaq    96(%rsi),%rsi
-       movl    %r10d,%eax
-       subq    $6,%rdx
-       jnc     .Lctr32_loop6
-
-       addq    $6,%rdx
-       jz      .Lctr32_done
-       movq    %r11,%rcx
-       leal    1(%rax,%rax,1),%eax
-
-.Lctr32_tail:
-       por     %xmm14,%xmm2
-       movups  (%rdi),%xmm8
-       cmpq    $2,%rdx
-       jb      .Lctr32_one
-
-       por     %xmm14,%xmm3
-       movups  16(%rdi),%xmm9
-       je      .Lctr32_two
-
-       pshufd  $192,%xmm13,%xmm5
-       por     %xmm14,%xmm4
-       movups  32(%rdi),%xmm10
-       cmpq    $4,%rdx
-       jb      .Lctr32_three
-
-       pshufd  $128,%xmm13,%xmm6
-       por     %xmm14,%xmm5
-       movups  48(%rdi),%xmm11
-       je      .Lctr32_four
-
-       por     %xmm14,%xmm6
-       xorps   %xmm7,%xmm7
-
-       call    _aesni_encrypt6
-
-       movups  64(%rdi),%xmm1
-       xorps   %xmm2,%xmm8
-       xorps   %xmm3,%xmm9
-       movups  %xmm8,(%rsi)
-       xorps   %xmm4,%xmm10
-       movups  %xmm9,16(%rsi)
-       xorps   %xmm5,%xmm11
-       movups  %xmm10,32(%rsi)
-       xorps   %xmm6,%xmm1
-       movups  %xmm11,48(%rsi)
-       movups  %xmm1,64(%rsi)
-       jmp     .Lctr32_done
-
-.align 16
-.Lctr32_one_shortcut:
-       movups  (%r8),%xmm2
-       movups  (%rdi),%xmm8
-       movl    240(%rcx),%eax
-.Lctr32_one:
-       movups  (%rcx),%xmm0
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-.Loop_enc1_7:
-.byte  102,15,56,220,209
-       decl    %eax
-       movups  (%rcx),%xmm1
-       leaq    16(%rcx),%rcx
-       jnz     .Loop_enc1_7    
-.byte  102,15,56,221,209
-       xorps   %xmm2,%xmm8
-       movups  %xmm8,(%rsi)
-       jmp     .Lctr32_done
-
-.align 16
-.Lctr32_two:
-       xorps   %xmm4,%xmm4
-       call    _aesni_encrypt3
-       xorps   %xmm2,%xmm8
-       xorps   %xmm3,%xmm9
-       movups  %xmm8,(%rsi)
-       movups  %xmm9,16(%rsi)
-       jmp     .Lctr32_done
-
-.align 16
-.Lctr32_three:
-       call    _aesni_encrypt3
-       xorps   %xmm2,%xmm8
-       xorps   %xmm3,%xmm9
-       movups  %xmm8,(%rsi)
-       xorps   %xmm4,%xmm10
-       movups  %xmm9,16(%rsi)
-       movups  %xmm10,32(%rsi)
-       jmp     .Lctr32_done
-
-.align 16
-.Lctr32_four:
-       call    _aesni_encrypt4
-       xorps   %xmm2,%xmm8
-       xorps   %xmm3,%xmm9
-       movups  %xmm8,(%rsi)
-       xorps   %xmm4,%xmm10
-       movups  %xmm9,16(%rsi)
-       xorps   %xmm5,%xmm11
-       movups  %xmm10,32(%rsi)
-       movups  %xmm11,48(%rsi)
-
-.Lctr32_done:
-       .byte   0xf3,0xc3
-.size  aesni_ctr32_encrypt_blocks,.-aesni_ctr32_encrypt_blocks
-.globl aesni_xts_encrypt
-.type  aesni_xts_encrypt,@function
-.align 16
-aesni_xts_encrypt:
-       leaq    -104(%rsp),%rsp
-       movups  (%r9),%xmm15
-       movl    240(%r8),%eax
-       movl    240(%rcx),%r10d
-       movups  (%r8),%xmm0
-       movups  16(%r8),%xmm1
-       leaq    32(%r8),%r8
-       xorps   %xmm0,%xmm15
-.Loop_enc1_8:
-.byte  102,68,15,56,220,249
-       decl    %eax
-       movups  (%r8),%xmm1
-       leaq    16(%r8),%r8
-       jnz     .Loop_enc1_8    
-.byte  102,68,15,56,221,249
-       movq    %rcx,%r11
-       movl    %r10d,%eax
-       movq    %rdx,%r9
-       andq    $-16,%rdx
-
-       movdqa  .Lxts_magic(%rip),%xmm8
-       pxor    %xmm14,%xmm14
-       pcmpgtd %xmm15,%xmm14
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm10
-       paddq   %xmm15,%xmm15
-       pand    %xmm8,%xmm9
-       pcmpgtd %xmm15,%xmm14
-       pxor    %xmm9,%xmm15
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm11
-       paddq   %xmm15,%xmm15
-       pand    %xmm8,%xmm9
-       pcmpgtd %xmm15,%xmm14
-       pxor    %xmm9,%xmm15
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm12
-       paddq   %xmm15,%xmm15
-       pand    %xmm8,%xmm9
-       pcmpgtd %xmm15,%xmm14
-       pxor    %xmm9,%xmm15
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm13
-       paddq   %xmm15,%xmm15
-       pand    %xmm8,%xmm9
-       pcmpgtd %xmm15,%xmm14
-       pxor    %xmm9,%xmm15
-       subq    $96,%rdx
-       jc      .Lxts_enc_short
-
-       shrl    $1,%eax
-       subl    $1,%eax
-       movl    %eax,%r10d
-       jmp     .Lxts_enc_grandloop
-
-.align 16
-.Lxts_enc_grandloop:
-       pshufd  $19,%xmm14,%xmm9
-       movdqa  %xmm15,%xmm14
-       paddq   %xmm15,%xmm15
-       movdqu  0(%rdi),%xmm2
-       pand    %xmm8,%xmm9
-       movdqu  16(%rdi),%xmm3
-       pxor    %xmm9,%xmm15
-
-       movdqu  32(%rdi),%xmm4
-       pxor    %xmm10,%xmm2
-       movdqu  48(%rdi),%xmm5
-       pxor    %xmm11,%xmm3
-       movdqu  64(%rdi),%xmm6
-       pxor    %xmm12,%xmm4
-       movdqu  80(%rdi),%xmm7
-       leaq    96(%rdi),%rdi
-       pxor    %xmm13,%xmm5
-       movups  (%r11),%xmm0
-       pxor    %xmm14,%xmm6
-       pxor    %xmm15,%xmm7
-
-
-
-       movups  16(%r11),%xmm1
-       pxor    %xmm0,%xmm2
-       pxor    %xmm0,%xmm3
-       movdqa  %xmm10,0(%rsp)
-.byte  102,15,56,220,209
-       leaq    32(%r11),%rcx
-       pxor    %xmm0,%xmm4
-       movdqa  %xmm11,16(%rsp)
-.byte  102,15,56,220,217
-       pxor    %xmm0,%xmm5
-       movdqa  %xmm12,32(%rsp)
-.byte  102,15,56,220,225
-       pxor    %xmm0,%xmm6
-       movdqa  %xmm13,48(%rsp)
-.byte  102,15,56,220,233
-       pxor    %xmm0,%xmm7
-       movups  (%rcx),%xmm0
-       decl    %eax
-       movdqa  %xmm14,64(%rsp)
-.byte  102,15,56,220,241
-       movdqa  %xmm15,80(%rsp)
-.byte  102,15,56,220,249
-       pxor    %xmm14,%xmm14
-       pcmpgtd %xmm15,%xmm14
-       jmp     .Lxts_enc_loop6_enter
-
-.align 16
-.Lxts_enc_loop6:
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-       decl    %eax
-.byte  102,15,56,220,225
-.byte  102,15,56,220,233
-.byte  102,15,56,220,241
-.byte  102,15,56,220,249
-.Lxts_enc_loop6_enter:
-       movups  16(%rcx),%xmm1
-.byte  102,15,56,220,208
-.byte  102,15,56,220,216
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,220,224
-.byte  102,15,56,220,232
-.byte  102,15,56,220,240
-.byte  102,15,56,220,248
-       movups  (%rcx),%xmm0
-       jnz     .Lxts_enc_loop6
-
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       paddq   %xmm15,%xmm15
-.byte  102,15,56,220,209
-       pand    %xmm8,%xmm9
-.byte  102,15,56,220,217
-       pcmpgtd %xmm15,%xmm14
-.byte  102,15,56,220,225
-       pxor    %xmm9,%xmm15
-.byte  102,15,56,220,233
-.byte  102,15,56,220,241
-.byte  102,15,56,220,249
-       movups  16(%rcx),%xmm1
-
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm10
-       paddq   %xmm15,%xmm15
-.byte  102,15,56,220,208
-       pand    %xmm8,%xmm9
-.byte  102,15,56,220,216
-       pcmpgtd %xmm15,%xmm14
-.byte  102,15,56,220,224
-       pxor    %xmm9,%xmm15
-.byte  102,15,56,220,232
-.byte  102,15,56,220,240
-.byte  102,15,56,220,248
-       movups  32(%rcx),%xmm0
-
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm11
-       paddq   %xmm15,%xmm15
-.byte  102,15,56,220,209
-       pand    %xmm8,%xmm9
-.byte  102,15,56,220,217
-       pcmpgtd %xmm15,%xmm14
-.byte  102,15,56,220,225
-       pxor    %xmm9,%xmm15
-.byte  102,15,56,220,233
-.byte  102,15,56,220,241
-.byte  102,15,56,220,249
-
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm12
-       paddq   %xmm15,%xmm15
-.byte  102,15,56,221,208
-       pand    %xmm8,%xmm9
-.byte  102,15,56,221,216
-       pcmpgtd %xmm15,%xmm14
-.byte  102,15,56,221,224
-       pxor    %xmm9,%xmm15
-.byte  102,15,56,221,232
-.byte  102,15,56,221,240
-.byte  102,15,56,221,248
-
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm13
-       paddq   %xmm15,%xmm15
-       xorps   0(%rsp),%xmm2
-       pand    %xmm8,%xmm9
-       xorps   16(%rsp),%xmm3
-       pcmpgtd %xmm15,%xmm14
-       pxor    %xmm9,%xmm15
-
-       xorps   32(%rsp),%xmm4
-       movups  %xmm2,0(%rsi)
-       xorps   48(%rsp),%xmm5
-       movups  %xmm3,16(%rsi)
-       xorps   64(%rsp),%xmm6
-       movups  %xmm4,32(%rsi)
-       xorps   80(%rsp),%xmm7
-       movups  %xmm5,48(%rsi)
-       movl    %r10d,%eax
-       movups  %xmm6,64(%rsi)
-       movups  %xmm7,80(%rsi)
-       leaq    96(%rsi),%rsi
-       subq    $96,%rdx
-       jnc     .Lxts_enc_grandloop
-
-       leal    3(%rax,%rax,1),%eax
-       movq    %r11,%rcx
-       movl    %eax,%r10d
-
-.Lxts_enc_short:
-       addq    $96,%rdx
-       jz      .Lxts_enc_done
-
-       cmpq    $32,%rdx
-       jb      .Lxts_enc_one
-       je      .Lxts_enc_two
-
-       cmpq    $64,%rdx
-       jb      .Lxts_enc_three
-       je      .Lxts_enc_four
-
-       pshufd  $19,%xmm14,%xmm9
-       movdqa  %xmm15,%xmm14
-       paddq   %xmm15,%xmm15
-       movdqu  (%rdi),%xmm2
-       pand    %xmm8,%xmm9
-       movdqu  16(%rdi),%xmm3
-       pxor    %xmm9,%xmm15
-
-       movdqu  32(%rdi),%xmm4
-       pxor    %xmm10,%xmm2
-       movdqu  48(%rdi),%xmm5
-       pxor    %xmm11,%xmm3
-       movdqu  64(%rdi),%xmm6
-       leaq    80(%rdi),%rdi
-       pxor    %xmm12,%xmm4
-       pxor    %xmm13,%xmm5
-       pxor    %xmm14,%xmm6
-
-       call    _aesni_encrypt6
-
-       xorps   %xmm10,%xmm2
-       movdqa  %xmm15,%xmm10
-       xorps   %xmm11,%xmm3
-       xorps   %xmm12,%xmm4
-       movdqu  %xmm2,(%rsi)
-       xorps   %xmm13,%xmm5
-       movdqu  %xmm3,16(%rsi)
-       xorps   %xmm14,%xmm6
-       movdqu  %xmm4,32(%rsi)
-       movdqu  %xmm5,48(%rsi)
-       movdqu  %xmm6,64(%rsi)
-       leaq    80(%rsi),%rsi
-       jmp     .Lxts_enc_done
-
-.align 16
-.Lxts_enc_one:
-       movups  (%rdi),%xmm2
-       leaq    16(%rdi),%rdi
-       xorps   %xmm10,%xmm2
-       movups  (%rcx),%xmm0
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-.Loop_enc1_9:
-.byte  102,15,56,220,209
-       decl    %eax
-       movups  (%rcx),%xmm1
-       leaq    16(%rcx),%rcx
-       jnz     .Loop_enc1_9    
-.byte  102,15,56,221,209
-       xorps   %xmm10,%xmm2
-       movdqa  %xmm11,%xmm10
-       movups  %xmm2,(%rsi)
-       leaq    16(%rsi),%rsi
-       jmp     .Lxts_enc_done
-
-.align 16
-.Lxts_enc_two:
-       movups  (%rdi),%xmm2
-       movups  16(%rdi),%xmm3
-       leaq    32(%rdi),%rdi
-       xorps   %xmm10,%xmm2
-       xorps   %xmm11,%xmm3
-
-       call    _aesni_encrypt3
-
-       xorps   %xmm10,%xmm2
-       movdqa  %xmm12,%xmm10
-       xorps   %xmm11,%xmm3
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       leaq    32(%rsi),%rsi
-       jmp     .Lxts_enc_done
-
-.align 16
-.Lxts_enc_three:
-       movups  (%rdi),%xmm2
-       movups  16(%rdi),%xmm3
-       movups  32(%rdi),%xmm4
-       leaq    48(%rdi),%rdi
-       xorps   %xmm10,%xmm2
-       xorps   %xmm11,%xmm3
-       xorps   %xmm12,%xmm4
-
-       call    _aesni_encrypt3
-
-       xorps   %xmm10,%xmm2
-       movdqa  %xmm13,%xmm10
-       xorps   %xmm11,%xmm3
-       xorps   %xmm12,%xmm4
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       leaq    48(%rsi),%rsi
-       jmp     .Lxts_enc_done
-
-.align 16
-.Lxts_enc_four:
-       movups  (%rdi),%xmm2
-       movups  16(%rdi),%xmm3
-       movups  32(%rdi),%xmm4
-       xorps   %xmm10,%xmm2
-       movups  48(%rdi),%xmm5
-       leaq    64(%rdi),%rdi
-       xorps   %xmm11,%xmm3
-       xorps   %xmm12,%xmm4
-       xorps   %xmm13,%xmm5
-
-       call    _aesni_encrypt4
-
-       xorps   %xmm10,%xmm2
-       movdqa  %xmm15,%xmm10
-       xorps   %xmm11,%xmm3
-       xorps   %xmm12,%xmm4
-       movups  %xmm2,(%rsi)
-       xorps   %xmm13,%xmm5
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       leaq    64(%rsi),%rsi
-       jmp     .Lxts_enc_done
-
-.align 16
-.Lxts_enc_done:
-       andq    $15,%r9
-       jz      .Lxts_enc_ret
-       movq    %r9,%rdx
-
-.Lxts_enc_steal:
-       movzbl  (%rdi),%eax
-       movzbl  -16(%rsi),%ecx
-       leaq    1(%rdi),%rdi
-       movb    %al,-16(%rsi)
-       movb    %cl,0(%rsi)
-       leaq    1(%rsi),%rsi
-       subq    $1,%rdx
-       jnz     .Lxts_enc_steal
-
-       subq    %r9,%rsi
-       movq    %r11,%rcx
-       movl    %r10d,%eax
-
-       movups  -16(%rsi),%xmm2
-       xorps   %xmm10,%xmm2
-       movups  (%rcx),%xmm0
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-.Loop_enc1_10:
-.byte  102,15,56,220,209
-       decl    %eax
-       movups  (%rcx),%xmm1
-       leaq    16(%rcx),%rcx
-       jnz     .Loop_enc1_10   
-.byte  102,15,56,221,209
-       xorps   %xmm10,%xmm2
-       movups  %xmm2,-16(%rsi)
-
-.Lxts_enc_ret:
-       leaq    104(%rsp),%rsp
-.Lxts_enc_epilogue:
-       .byte   0xf3,0xc3
-.size  aesni_xts_encrypt,.-aesni_xts_encrypt
-.globl aesni_xts_decrypt
-.type  aesni_xts_decrypt,@function
-.align 16
-aesni_xts_decrypt:
-       leaq    -104(%rsp),%rsp
-       movups  (%r9),%xmm15
-       movl    240(%r8),%eax
-       movl    240(%rcx),%r10d
-       movups  (%r8),%xmm0
-       movups  16(%r8),%xmm1
-       leaq    32(%r8),%r8
-       xorps   %xmm0,%xmm15
-.Loop_enc1_11:
-.byte  102,68,15,56,220,249
-       decl    %eax
-       movups  (%r8),%xmm1
-       leaq    16(%r8),%r8
-       jnz     .Loop_enc1_11   
-.byte  102,68,15,56,221,249
-       xorl    %eax,%eax
-       testq   $15,%rdx
-       setnz   %al
-       shlq    $4,%rax
-       subq    %rax,%rdx
-
-       movq    %rcx,%r11
-       movl    %r10d,%eax
-       movq    %rdx,%r9
-       andq    $-16,%rdx
-
-       movdqa  .Lxts_magic(%rip),%xmm8
-       pxor    %xmm14,%xmm14
-       pcmpgtd %xmm15,%xmm14
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm10
-       paddq   %xmm15,%xmm15
-       pand    %xmm8,%xmm9
-       pcmpgtd %xmm15,%xmm14
-       pxor    %xmm9,%xmm15
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm11
-       paddq   %xmm15,%xmm15
-       pand    %xmm8,%xmm9
-       pcmpgtd %xmm15,%xmm14
-       pxor    %xmm9,%xmm15
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm12
-       paddq   %xmm15,%xmm15
-       pand    %xmm8,%xmm9
-       pcmpgtd %xmm15,%xmm14
-       pxor    %xmm9,%xmm15
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm13
-       paddq   %xmm15,%xmm15
-       pand    %xmm8,%xmm9
-       pcmpgtd %xmm15,%xmm14
-       pxor    %xmm9,%xmm15
-       subq    $96,%rdx
-       jc      .Lxts_dec_short
-
-       shrl    $1,%eax
-       subl    $1,%eax
-       movl    %eax,%r10d
-       jmp     .Lxts_dec_grandloop
-
-.align 16
-.Lxts_dec_grandloop:
-       pshufd  $19,%xmm14,%xmm9
-       movdqa  %xmm15,%xmm14
-       paddq   %xmm15,%xmm15
-       movdqu  0(%rdi),%xmm2
-       pand    %xmm8,%xmm9
-       movdqu  16(%rdi),%xmm3
-       pxor    %xmm9,%xmm15
-
-       movdqu  32(%rdi),%xmm4
-       pxor    %xmm10,%xmm2
-       movdqu  48(%rdi),%xmm5
-       pxor    %xmm11,%xmm3
-       movdqu  64(%rdi),%xmm6
-       pxor    %xmm12,%xmm4
-       movdqu  80(%rdi),%xmm7
-       leaq    96(%rdi),%rdi
-       pxor    %xmm13,%xmm5
-       movups  (%r11),%xmm0
-       pxor    %xmm14,%xmm6
-       pxor    %xmm15,%xmm7
-
-
-
-       movups  16(%r11),%xmm1
-       pxor    %xmm0,%xmm2
-       pxor    %xmm0,%xmm3
-       movdqa  %xmm10,0(%rsp)
-.byte  102,15,56,222,209
-       leaq    32(%r11),%rcx
-       pxor    %xmm0,%xmm4
-       movdqa  %xmm11,16(%rsp)
-.byte  102,15,56,222,217
-       pxor    %xmm0,%xmm5
-       movdqa  %xmm12,32(%rsp)
-.byte  102,15,56,222,225
-       pxor    %xmm0,%xmm6
-       movdqa  %xmm13,48(%rsp)
-.byte  102,15,56,222,233
-       pxor    %xmm0,%xmm7
-       movups  (%rcx),%xmm0
-       decl    %eax
-       movdqa  %xmm14,64(%rsp)
-.byte  102,15,56,222,241
-       movdqa  %xmm15,80(%rsp)
-.byte  102,15,56,222,249
-       pxor    %xmm14,%xmm14
-       pcmpgtd %xmm15,%xmm14
-       jmp     .Lxts_dec_loop6_enter
-
-.align 16
-.Lxts_dec_loop6:
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-       decl    %eax
-.byte  102,15,56,222,225
-.byte  102,15,56,222,233
-.byte  102,15,56,222,241
-.byte  102,15,56,222,249
-.Lxts_dec_loop6_enter:
-       movups  16(%rcx),%xmm1
-.byte  102,15,56,222,208
-.byte  102,15,56,222,216
-       leaq    32(%rcx),%rcx
-.byte  102,15,56,222,224
-.byte  102,15,56,222,232
-.byte  102,15,56,222,240
-.byte  102,15,56,222,248
-       movups  (%rcx),%xmm0
-       jnz     .Lxts_dec_loop6
-
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       paddq   %xmm15,%xmm15
-.byte  102,15,56,222,209
-       pand    %xmm8,%xmm9
-.byte  102,15,56,222,217
-       pcmpgtd %xmm15,%xmm14
-.byte  102,15,56,222,225
-       pxor    %xmm9,%xmm15
-.byte  102,15,56,222,233
-.byte  102,15,56,222,241
-.byte  102,15,56,222,249
-       movups  16(%rcx),%xmm1
-
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm10
-       paddq   %xmm15,%xmm15
-.byte  102,15,56,222,208
-       pand    %xmm8,%xmm9
-.byte  102,15,56,222,216
-       pcmpgtd %xmm15,%xmm14
-.byte  102,15,56,222,224
-       pxor    %xmm9,%xmm15
-.byte  102,15,56,222,232
-.byte  102,15,56,222,240
-.byte  102,15,56,222,248
-       movups  32(%rcx),%xmm0
-
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm11
-       paddq   %xmm15,%xmm15
-.byte  102,15,56,222,209
-       pand    %xmm8,%xmm9
-.byte  102,15,56,222,217
-       pcmpgtd %xmm15,%xmm14
-.byte  102,15,56,222,225
-       pxor    %xmm9,%xmm15
-.byte  102,15,56,222,233
-.byte  102,15,56,222,241
-.byte  102,15,56,222,249
-
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm12
-       paddq   %xmm15,%xmm15
-.byte  102,15,56,223,208
-       pand    %xmm8,%xmm9
-.byte  102,15,56,223,216
-       pcmpgtd %xmm15,%xmm14
-.byte  102,15,56,223,224
-       pxor    %xmm9,%xmm15
-.byte  102,15,56,223,232
-.byte  102,15,56,223,240
-.byte  102,15,56,223,248
-
-       pshufd  $19,%xmm14,%xmm9
-       pxor    %xmm14,%xmm14
-       movdqa  %xmm15,%xmm13
-       paddq   %xmm15,%xmm15
-       xorps   0(%rsp),%xmm2
-       pand    %xmm8,%xmm9
-       xorps   16(%rsp),%xmm3
-       pcmpgtd %xmm15,%xmm14
-       pxor    %xmm9,%xmm15
-
-       xorps   32(%rsp),%xmm4
-       movups  %xmm2,0(%rsi)
-       xorps   48(%rsp),%xmm5
-       movups  %xmm3,16(%rsi)
-       xorps   64(%rsp),%xmm6
-       movups  %xmm4,32(%rsi)
-       xorps   80(%rsp),%xmm7
-       movups  %xmm5,48(%rsi)
-       movl    %r10d,%eax
-       movups  %xmm6,64(%rsi)
-       movups  %xmm7,80(%rsi)
-       leaq    96(%rsi),%rsi
-       subq    $96,%rdx
-       jnc     .Lxts_dec_grandloop
-
-       leal    3(%rax,%rax,1),%eax
-       movq    %r11,%rcx
-       movl    %eax,%r10d
-
-.Lxts_dec_short:
-       addq    $96,%rdx
-       jz      .Lxts_dec_done
-
-       cmpq    $32,%rdx
-       jb      .Lxts_dec_one
-       je      .Lxts_dec_two
-
-       cmpq    $64,%rdx
-       jb      .Lxts_dec_three
-       je      .Lxts_dec_four
-
-       pshufd  $19,%xmm14,%xmm9
-       movdqa  %xmm15,%xmm14
-       paddq   %xmm15,%xmm15
-       movdqu  (%rdi),%xmm2
-       pand    %xmm8,%xmm9
-       movdqu  16(%rdi),%xmm3
-       pxor    %xmm9,%xmm15
-
-       movdqu  32(%rdi),%xmm4
-       pxor    %xmm10,%xmm2
-       movdqu  48(%rdi),%xmm5
-       pxor    %xmm11,%xmm3
-       movdqu  64(%rdi),%xmm6
-       leaq    80(%rdi),%rdi
-       pxor    %xmm12,%xmm4
-       pxor    %xmm13,%xmm5
-       pxor    %xmm14,%xmm6
-
-       call    _aesni_decrypt6
-
-       xorps   %xmm10,%xmm2
-       xorps   %xmm11,%xmm3
-       xorps   %xmm12,%xmm4
-       movdqu  %xmm2,(%rsi)
-       xorps   %xmm13,%xmm5
-       movdqu  %xmm3,16(%rsi)
-       xorps   %xmm14,%xmm6
-       movdqu  %xmm4,32(%rsi)
-       pxor    %xmm14,%xmm14
-       movdqu  %xmm5,48(%rsi)
-       pcmpgtd %xmm15,%xmm14
-       movdqu  %xmm6,64(%rsi)
-       leaq    80(%rsi),%rsi
-       pshufd  $19,%xmm14,%xmm11
-       andq    $15,%r9
-       jz      .Lxts_dec_ret
-
-       movdqa  %xmm15,%xmm10
-       paddq   %xmm15,%xmm15
-       pand    %xmm8,%xmm11
-       pxor    %xmm15,%xmm11
-       jmp     .Lxts_dec_done2
-
-.align 16
-.Lxts_dec_one:
-       movups  (%rdi),%xmm2
-       leaq    16(%rdi),%rdi
-       xorps   %xmm10,%xmm2
-       movups  (%rcx),%xmm0
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-.Loop_dec1_12:
-.byte  102,15,56,222,209
-       decl    %eax
-       movups  (%rcx),%xmm1
-       leaq    16(%rcx),%rcx
-       jnz     .Loop_dec1_12   
-.byte  102,15,56,223,209
-       xorps   %xmm10,%xmm2
-       movdqa  %xmm11,%xmm10
-       movups  %xmm2,(%rsi)
-       movdqa  %xmm12,%xmm11
-       leaq    16(%rsi),%rsi
-       jmp     .Lxts_dec_done
-
-.align 16
-.Lxts_dec_two:
-       movups  (%rdi),%xmm2
-       movups  16(%rdi),%xmm3
-       leaq    32(%rdi),%rdi
-       xorps   %xmm10,%xmm2
-       xorps   %xmm11,%xmm3
-
-       call    _aesni_decrypt3
-
-       xorps   %xmm10,%xmm2
-       movdqa  %xmm12,%xmm10
-       xorps   %xmm11,%xmm3
-       movdqa  %xmm13,%xmm11
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       leaq    32(%rsi),%rsi
-       jmp     .Lxts_dec_done
-
-.align 16
-.Lxts_dec_three:
-       movups  (%rdi),%xmm2
-       movups  16(%rdi),%xmm3
-       movups  32(%rdi),%xmm4
-       leaq    48(%rdi),%rdi
-       xorps   %xmm10,%xmm2
-       xorps   %xmm11,%xmm3
-       xorps   %xmm12,%xmm4
-
-       call    _aesni_decrypt3
-
-       xorps   %xmm10,%xmm2
-       movdqa  %xmm13,%xmm10
-       xorps   %xmm11,%xmm3
-       movdqa  %xmm15,%xmm11
-       xorps   %xmm12,%xmm4
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       leaq    48(%rsi),%rsi
-       jmp     .Lxts_dec_done
-
-.align 16
-.Lxts_dec_four:
-       pshufd  $19,%xmm14,%xmm9
-       movdqa  %xmm15,%xmm14
-       paddq   %xmm15,%xmm15
-       movups  (%rdi),%xmm2
-       pand    %xmm8,%xmm9
-       movups  16(%rdi),%xmm3
-       pxor    %xmm9,%xmm15
-
-       movups  32(%rdi),%xmm4
-       xorps   %xmm10,%xmm2
-       movups  48(%rdi),%xmm5
-       leaq    64(%rdi),%rdi
-       xorps   %xmm11,%xmm3
-       xorps   %xmm12,%xmm4
-       xorps   %xmm13,%xmm5
-
-       call    _aesni_decrypt4
-
-       xorps   %xmm10,%xmm2
-       movdqa  %xmm14,%xmm10
-       xorps   %xmm11,%xmm3
-       movdqa  %xmm15,%xmm11
-       xorps   %xmm12,%xmm4
-       movups  %xmm2,(%rsi)
-       xorps   %xmm13,%xmm5
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       leaq    64(%rsi),%rsi
-       jmp     .Lxts_dec_done
-
-.align 16
-.Lxts_dec_done:
-       andq    $15,%r9
-       jz      .Lxts_dec_ret
-.Lxts_dec_done2:
-       movq    %r9,%rdx
-       movq    %r11,%rcx
-       movl    %r10d,%eax
-
-       movups  (%rdi),%xmm2
-       xorps   %xmm11,%xmm2
-       movups  (%rcx),%xmm0
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-.Loop_dec1_13:
-.byte  102,15,56,222,209
-       decl    %eax
-       movups  (%rcx),%xmm1
-       leaq    16(%rcx),%rcx
-       jnz     .Loop_dec1_13   
-.byte  102,15,56,223,209
-       xorps   %xmm11,%xmm2
-       movups  %xmm2,(%rsi)
-
-.Lxts_dec_steal:
-       movzbl  16(%rdi),%eax
-       movzbl  (%rsi),%ecx
-       leaq    1(%rdi),%rdi
-       movb    %al,(%rsi)
-       movb    %cl,16(%rsi)
-       leaq    1(%rsi),%rsi
-       subq    $1,%rdx
-       jnz     .Lxts_dec_steal
-
-       subq    %r9,%rsi
-       movq    %r11,%rcx
-       movl    %r10d,%eax
-
-       movups  (%rsi),%xmm2
-       xorps   %xmm10,%xmm2
-       movups  (%rcx),%xmm0
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-.Loop_dec1_14:
-.byte  102,15,56,222,209
-       decl    %eax
-       movups  (%rcx),%xmm1
-       leaq    16(%rcx),%rcx
-       jnz     .Loop_dec1_14   
-.byte  102,15,56,223,209
-       xorps   %xmm10,%xmm2
-       movups  %xmm2,(%rsi)
-
-.Lxts_dec_ret:
-       leaq    104(%rsp),%rsp
-.Lxts_dec_epilogue:
-       .byte   0xf3,0xc3
-.size  aesni_xts_decrypt,.-aesni_xts_decrypt
-.globl aesni_cbc_encrypt
-.type  aesni_cbc_encrypt,@function
-.align 16
-aesni_cbc_encrypt:
-       testq   %rdx,%rdx
-       jz      .Lcbc_ret
-
-       movl    240(%rcx),%r10d
-       movq    %rcx,%r11
-       testl   %r9d,%r9d
-       jz      .Lcbc_decrypt
-
-       movups  (%r8),%xmm2
-       movl    %r10d,%eax
-       cmpq    $16,%rdx
-       jb      .Lcbc_enc_tail
-       subq    $16,%rdx
-       jmp     .Lcbc_enc_loop
-.align 16
-.Lcbc_enc_loop:
-       movups  (%rdi),%xmm3
-       leaq    16(%rdi),%rdi
-
-       movups  (%rcx),%xmm0
-       movups  16(%rcx),%xmm1
-       xorps   %xmm0,%xmm3
-       leaq    32(%rcx),%rcx
-       xorps   %xmm3,%xmm2
-.Loop_enc1_15:
-.byte  102,15,56,220,209
-       decl    %eax
-       movups  (%rcx),%xmm1
-       leaq    16(%rcx),%rcx
-       jnz     .Loop_enc1_15   
-.byte  102,15,56,221,209
-       movl    %r10d,%eax
-       movq    %r11,%rcx
-       movups  %xmm2,0(%rsi)
-       leaq    16(%rsi),%rsi
-       subq    $16,%rdx
-       jnc     .Lcbc_enc_loop
-       addq    $16,%rdx
-       jnz     .Lcbc_enc_tail
-       movups  %xmm2,(%r8)
-       jmp     .Lcbc_ret
-
-.Lcbc_enc_tail:
-       movq    %rdx,%rcx
-       xchgq   %rdi,%rsi
-.long  0x9066A4F3      
-       movl    $16,%ecx
-       subq    %rdx,%rcx
-       xorl    %eax,%eax
-.long  0x9066AAF3      
-       leaq    -16(%rdi),%rdi
-       movl    %r10d,%eax
-       movq    %rdi,%rsi
-       movq    %r11,%rcx
-       xorq    %rdx,%rdx
-       jmp     .Lcbc_enc_loop  
-
-.align 16
-.Lcbc_decrypt:
-       movups  (%r8),%xmm9
-       movl    %r10d,%eax
-       cmpq    $112,%rdx
-       jbe     .Lcbc_dec_tail
-       shrl    $1,%r10d
-       subq    $112,%rdx
-       movl    %r10d,%eax
-       movaps  %xmm9,-24(%rsp)
-       jmp     .Lcbc_dec_loop8_enter
-.align 16
-.Lcbc_dec_loop8:
-       movaps  %xmm0,-24(%rsp)
-       movups  %xmm9,(%rsi)
-       leaq    16(%rsi),%rsi
-.Lcbc_dec_loop8_enter:
-       movups  (%rcx),%xmm0
-       movups  (%rdi),%xmm2
-       movups  16(%rdi),%xmm3
-       movups  16(%rcx),%xmm1
-
-       leaq    32(%rcx),%rcx
-       movdqu  32(%rdi),%xmm4
-       xorps   %xmm0,%xmm2
-       movdqu  48(%rdi),%xmm5
-       xorps   %xmm0,%xmm3
-       movdqu  64(%rdi),%xmm6
-.byte  102,15,56,222,209
-       pxor    %xmm0,%xmm4
-       movdqu  80(%rdi),%xmm7
-.byte  102,15,56,222,217
-       pxor    %xmm0,%xmm5
-       movdqu  96(%rdi),%xmm8
-.byte  102,15,56,222,225
-       pxor    %xmm0,%xmm6
-       movdqu  112(%rdi),%xmm9
-.byte  102,15,56,222,233
-       pxor    %xmm0,%xmm7
-       decl    %eax
-.byte  102,15,56,222,241
-       pxor    %xmm0,%xmm8
-.byte  102,15,56,222,249
-       pxor    %xmm0,%xmm9
-       movups  (%rcx),%xmm0
-.byte  102,68,15,56,222,193
-.byte  102,68,15,56,222,201
-       movups  16(%rcx),%xmm1
-
-       call    .Ldec_loop8_enter
-
-       movups  (%rdi),%xmm1
-       movups  16(%rdi),%xmm0
-       xorps   -24(%rsp),%xmm2
-       xorps   %xmm1,%xmm3
-       movups  32(%rdi),%xmm1
-       xorps   %xmm0,%xmm4
-       movups  48(%rdi),%xmm0
-       xorps   %xmm1,%xmm5
-       movups  64(%rdi),%xmm1
-       xorps   %xmm0,%xmm6
-       movups  80(%rdi),%xmm0
-       xorps   %xmm1,%xmm7
-       movups  96(%rdi),%xmm1
-       xorps   %xmm0,%xmm8
-       movups  112(%rdi),%xmm0
-       xorps   %xmm1,%xmm9
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       movl    %r10d,%eax
-       movups  %xmm6,64(%rsi)
-       movq    %r11,%rcx
-       movups  %xmm7,80(%rsi)
-       leaq    128(%rdi),%rdi
-       movups  %xmm8,96(%rsi)
-       leaq    112(%rsi),%rsi
-       subq    $128,%rdx
-       ja      .Lcbc_dec_loop8
-
-       movaps  %xmm9,%xmm2
-       movaps  %xmm0,%xmm9
-       addq    $112,%rdx
-       jle     .Lcbc_dec_tail_collected
-       movups  %xmm2,(%rsi)
-       leal    1(%r10,%r10,1),%eax
-       leaq    16(%rsi),%rsi
-.Lcbc_dec_tail:
-       movups  (%rdi),%xmm2
-       movaps  %xmm2,%xmm8
-       cmpq    $16,%rdx
-       jbe     .Lcbc_dec_one
-
-       movups  16(%rdi),%xmm3
-       movaps  %xmm3,%xmm7
-       cmpq    $32,%rdx
-       jbe     .Lcbc_dec_two
-
-       movups  32(%rdi),%xmm4
-       movaps  %xmm4,%xmm6
-       cmpq    $48,%rdx
-       jbe     .Lcbc_dec_three
-
-       movups  48(%rdi),%xmm5
-       cmpq    $64,%rdx
-       jbe     .Lcbc_dec_four
-
-       movups  64(%rdi),%xmm6
-       cmpq    $80,%rdx
-       jbe     .Lcbc_dec_five
-
-       movups  80(%rdi),%xmm7
-       cmpq    $96,%rdx
-       jbe     .Lcbc_dec_six
-
-       movups  96(%rdi),%xmm8
-       movaps  %xmm9,-24(%rsp)
-       call    _aesni_decrypt8
-       movups  (%rdi),%xmm1
-       movups  16(%rdi),%xmm0
-       xorps   -24(%rsp),%xmm2
-       xorps   %xmm1,%xmm3
-       movups  32(%rdi),%xmm1
-       xorps   %xmm0,%xmm4
-       movups  48(%rdi),%xmm0
-       xorps   %xmm1,%xmm5
-       movups  64(%rdi),%xmm1
-       xorps   %xmm0,%xmm6
-       movups  80(%rdi),%xmm0
-       xorps   %xmm1,%xmm7
-       movups  96(%rdi),%xmm9
-       xorps   %xmm0,%xmm8
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       movups  %xmm6,64(%rsi)
-       movups  %xmm7,80(%rsi)
-       leaq    96(%rsi),%rsi
-       movaps  %xmm8,%xmm2
-       subq    $112,%rdx
-       jmp     .Lcbc_dec_tail_collected
-.align 16
-.Lcbc_dec_one:
-       movups  (%rcx),%xmm0
-       movups  16(%rcx),%xmm1
-       leaq    32(%rcx),%rcx
-       xorps   %xmm0,%xmm2
-.Loop_dec1_16:
-.byte  102,15,56,222,209
-       decl    %eax
-       movups  (%rcx),%xmm1
-       leaq    16(%rcx),%rcx
-       jnz     .Loop_dec1_16   
-.byte  102,15,56,223,209
-       xorps   %xmm9,%xmm2
-       movaps  %xmm8,%xmm9
-       subq    $16,%rdx
-       jmp     .Lcbc_dec_tail_collected
-.align 16
-.Lcbc_dec_two:
-       xorps   %xmm4,%xmm4
-       call    _aesni_decrypt3
-       xorps   %xmm9,%xmm2
-       xorps   %xmm8,%xmm3
-       movups  %xmm2,(%rsi)
-       movaps  %xmm7,%xmm9
-       movaps  %xmm3,%xmm2
-       leaq    16(%rsi),%rsi
-       subq    $32,%rdx
-       jmp     .Lcbc_dec_tail_collected
-.align 16
-.Lcbc_dec_three:
-       call    _aesni_decrypt3
-       xorps   %xmm9,%xmm2
-       xorps   %xmm8,%xmm3
-       movups  %xmm2,(%rsi)
-       xorps   %xmm7,%xmm4
-       movups  %xmm3,16(%rsi)
-       movaps  %xmm6,%xmm9
-       movaps  %xmm4,%xmm2
-       leaq    32(%rsi),%rsi
-       subq    $48,%rdx
-       jmp     .Lcbc_dec_tail_collected
-.align 16
-.Lcbc_dec_four:
-       call    _aesni_decrypt4
-       xorps   %xmm9,%xmm2
-       movups  48(%rdi),%xmm9
-       xorps   %xmm8,%xmm3
-       movups  %xmm2,(%rsi)
-       xorps   %xmm7,%xmm4
-       movups  %xmm3,16(%rsi)
-       xorps   %xmm6,%xmm5
-       movups  %xmm4,32(%rsi)
-       movaps  %xmm5,%xmm2
-       leaq    48(%rsi),%rsi
-       subq    $64,%rdx
-       jmp     .Lcbc_dec_tail_collected
-.align 16
-.Lcbc_dec_five:
-       xorps   %xmm7,%xmm7
-       call    _aesni_decrypt6
-       movups  16(%rdi),%xmm1
-       movups  32(%rdi),%xmm0
-       xorps   %xmm9,%xmm2
-       xorps   %xmm8,%xmm3
-       xorps   %xmm1,%xmm4
-       movups  48(%rdi),%xmm1
-       xorps   %xmm0,%xmm5
-       movups  64(%rdi),%xmm9
-       xorps   %xmm1,%xmm6
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       leaq    64(%rsi),%rsi
-       movaps  %xmm6,%xmm2
-       subq    $80,%rdx
-       jmp     .Lcbc_dec_tail_collected
-.align 16
-.Lcbc_dec_six:
-       call    _aesni_decrypt6
-       movups  16(%rdi),%xmm1
-       movups  32(%rdi),%xmm0
-       xorps   %xmm9,%xmm2
-       xorps   %xmm8,%xmm3
-       xorps   %xmm1,%xmm4
-       movups  48(%rdi),%xmm1
-       xorps   %xmm0,%xmm5
-       movups  64(%rdi),%xmm0
-       xorps   %xmm1,%xmm6
-       movups  80(%rdi),%xmm9
-       xorps   %xmm0,%xmm7
-       movups  %xmm2,(%rsi)
-       movups  %xmm3,16(%rsi)
-       movups  %xmm4,32(%rsi)
-       movups  %xmm5,48(%rsi)
-       movups  %xmm6,64(%rsi)
-       leaq    80(%rsi),%rsi
-       movaps  %xmm7,%xmm2
-       subq    $96,%rdx
-       jmp     .Lcbc_dec_tail_collected
-.align 16
-.Lcbc_dec_tail_collected:
-       andq    $15,%rdx
-       movups  %xmm9,(%r8)
-       jnz     .Lcbc_dec_tail_partial
-       movups  %xmm2,(%rsi)
-       jmp     .Lcbc_dec_ret
-.align 16
-.Lcbc_dec_tail_partial:
-       movaps  %xmm2,-24(%rsp)
-       movq    $16,%rcx
-       movq    %rsi,%rdi
-       subq    %rdx,%rcx
-       leaq    -24(%rsp),%rsi
-.long  0x9066A4F3      
-
-.Lcbc_dec_ret:
-.Lcbc_ret:
-       .byte   0xf3,0xc3
-.size  aesni_cbc_encrypt,.-aesni_cbc_encrypt
-.globl aesni_set_decrypt_key
-.type  aesni_set_decrypt_key,@function
-.align 16
-aesni_set_decrypt_key:
-.byte  0x48,0x83,0xEC,0x08     
-       call    __aesni_set_encrypt_key
-       shll    $4,%esi
-       testl   %eax,%eax
-       jnz     .Ldec_key_ret
-       leaq    16(%rdx,%rsi,1),%rdi
-
-       movups  (%rdx),%xmm0
-       movups  (%rdi),%xmm1
-       movups  %xmm0,(%rdi)
-       movups  %xmm1,(%rdx)
-       leaq    16(%rdx),%rdx
-       leaq    -16(%rdi),%rdi
-
-.Ldec_key_inverse:
-       movups  (%rdx),%xmm0
-       movups  (%rdi),%xmm1
-.byte  102,15,56,219,192
-.byte  102,15,56,219,201
-       leaq    16(%rdx),%rdx
-       leaq    -16(%rdi),%rdi
-       movups  %xmm0,16(%rdi)
-       movups  %xmm1,-16(%rdx)
-       cmpq    %rdx,%rdi
-       ja      .Ldec_key_inverse
-
-       movups  (%rdx),%xmm0
-.byte  102,15,56,219,192
-       movups  %xmm0,(%rdi)
-.Ldec_key_ret:
-       addq    $8,%rsp
-       .byte   0xf3,0xc3
-.LSEH_end_set_decrypt_key:
-.size  aesni_set_decrypt_key,.-aesni_set_decrypt_key
-.globl aesni_set_encrypt_key
-.type  aesni_set_encrypt_key,@function
-.align 16
-aesni_set_encrypt_key:
-__aesni_set_encrypt_key:
-.byte  0x48,0x83,0xEC,0x08     
-       movq    $-1,%rax
-       testq   %rdi,%rdi
-       jz      .Lenc_key_ret
-       testq   %rdx,%rdx
-       jz      .Lenc_key_ret
-
-       movups  (%rdi),%xmm0
-       xorps   %xmm4,%xmm4
-       leaq    16(%rdx),%rax
-       cmpl    $256,%esi
-       je      .L14rounds
-       cmpl    $192,%esi
-       je      .L12rounds
-       cmpl    $128,%esi
-       jne     .Lbad_keybits
-
-.L10rounds:
-       movl    $9,%esi
-       movups  %xmm0,(%rdx)
-.byte  102,15,58,223,200,1
-       call    .Lkey_expansion_128_cold
-.byte  102,15,58,223,200,2
-       call    .Lkey_expansion_128
-.byte  102,15,58,223,200,4
-       call    .Lkey_expansion_128
-.byte  102,15,58,223,200,8
-       call    .Lkey_expansion_128
-.byte  102,15,58,223,200,16
-       call    .Lkey_expansion_128
-.byte  102,15,58,223,200,32
-       call    .Lkey_expansion_128
-.byte  102,15,58,223,200,64
-       call    .Lkey_expansion_128
-.byte  102,15,58,223,200,128
-       call    .Lkey_expansion_128
-.byte  102,15,58,223,200,27
-       call    .Lkey_expansion_128
-.byte  102,15,58,223,200,54
-       call    .Lkey_expansion_128
-       movups  %xmm0,(%rax)
-       movl    %esi,80(%rax)
-       xorl    %eax,%eax
-       jmp     .Lenc_key_ret
-
-.align 16
-.L12rounds:
-       movq    16(%rdi),%xmm2
-       movl    $11,%esi
-       movups  %xmm0,(%rdx)
-.byte  102,15,58,223,202,1
-       call    .Lkey_expansion_192a_cold
-.byte  102,15,58,223,202,2
-       call    .Lkey_expansion_192b
-.byte  102,15,58,223,202,4
-       call    .Lkey_expansion_192a
-.byte  102,15,58,223,202,8
-       call    .Lkey_expansion_192b
-.byte  102,15,58,223,202,16
-       call    .Lkey_expansion_192a
-.byte  102,15,58,223,202,32
-       call    .Lkey_expansion_192b
-.byte  102,15,58,223,202,64
-       call    .Lkey_expansion_192a
-.byte  102,15,58,223,202,128
-       call    .Lkey_expansion_192b
-       movups  %xmm0,(%rax)
-       movl    %esi,48(%rax)
-       xorq    %rax,%rax
-       jmp     .Lenc_key_ret
-
-.align 16
-.L14rounds:
-       movups  16(%rdi),%xmm2
-       movl    $13,%esi
-       leaq    16(%rax),%rax
-       movups  %xmm0,(%rdx)
-       movups  %xmm2,16(%rdx)
-.byte  102,15,58,223,202,1
-       call    .Lkey_expansion_256a_cold
-.byte  102,15,58,223,200,1
-       call    .Lkey_expansion_256b
-.byte  102,15,58,223,202,2
-       call    .Lkey_expansion_256a
-.byte  102,15,58,223,200,2
-       call    .Lkey_expansion_256b
-.byte  102,15,58,223,202,4
-       call    .Lkey_expansion_256a
-.byte  102,15,58,223,200,4
-       call    .Lkey_expansion_256b
-.byte  102,15,58,223,202,8
-       call    .Lkey_expansion_256a
-.byte  102,15,58,223,200,8
-       call    .Lkey_expansion_256b
-.byte  102,15,58,223,202,16
-       call    .Lkey_expansion_256a
-.byte  102,15,58,223,200,16
-       call    .Lkey_expansion_256b
-.byte  102,15,58,223,202,32
-       call    .Lkey_expansion_256a
-.byte  102,15,58,223,200,32
-       call    .Lkey_expansion_256b
-.byte  102,15,58,223,202,64
-       call    .Lkey_expansion_256a
-       movups  %xmm0,(%rax)
-       movl    %esi,16(%rax)
-       xorq    %rax,%rax
-       jmp     .Lenc_key_ret
-
-.align 16
-.Lbad_keybits:
-       movq    $-2,%rax
-.Lenc_key_ret:
-       addq    $8,%rsp
-       .byte   0xf3,0xc3
-.LSEH_end_set_encrypt_key:
-
-.align 16
-.Lkey_expansion_128:
-       movups  %xmm0,(%rax)
-       leaq    16(%rax),%rax
-.Lkey_expansion_128_cold:
-       shufps  $16,%xmm0,%xmm4
-       xorps   %xmm4,%xmm0
-       shufps  $140,%xmm0,%xmm4
-       xorps   %xmm4,%xmm0
-       shufps  $255,%xmm1,%xmm1
-       xorps   %xmm1,%xmm0
-       .byte   0xf3,0xc3
-
-.align 16
-.Lkey_expansion_192a:
-       movups  %xmm0,(%rax)
-       leaq    16(%rax),%rax
-.Lkey_expansion_192a_cold:
-       movaps  %xmm2,%xmm5
-.Lkey_expansion_192b_warm:
-       shufps  $16,%xmm0,%xmm4
-       movdqa  %xmm2,%xmm3
-       xorps   %xmm4,%xmm0
-       shufps  $140,%xmm0,%xmm4
-       pslldq  $4,%xmm3
-       xorps   %xmm4,%xmm0
-       pshufd  $85,%xmm1,%xmm1
-       pxor    %xmm3,%xmm2
-       pxor    %xmm1,%xmm0
-       pshufd  $255,%xmm0,%xmm3
-       pxor    %xmm3,%xmm2
-       .byte   0xf3,0xc3
-
-.align 16
-.Lkey_expansion_192b:
-       movaps  %xmm0,%xmm3
-       shufps  $68,%xmm0,%xmm5
-       movups  %xmm5,(%rax)
-       shufps  $78,%xmm2,%xmm3
-       movups  %xmm3,16(%rax)
-       leaq    32(%rax),%rax
-       jmp     .Lkey_expansion_192b_warm
-
-.align 16
-.Lkey_expansion_256a:
-       movups  %xmm2,(%rax)
-       leaq    16(%rax),%rax
-.Lkey_expansion_256a_cold:
-       shufps  $16,%xmm0,%xmm4
-       xorps   %xmm4,%xmm0
-       shufps  $140,%xmm0,%xmm4
-       xorps   %xmm4,%xmm0
-       shufps  $255,%xmm1,%xmm1
-       xorps   %xmm1,%xmm0
-       .byte   0xf3,0xc3
-
-.align 16
-.Lkey_expansion_256b:
-       movups  %xmm0,(%rax)
-       leaq    16(%rax),%rax
-
-       shufps  $16,%xmm2,%xmm4
-       xorps   %xmm4,%xmm2
-       shufps  $140,%xmm2,%xmm4
-       xorps   %xmm4,%xmm2
-       shufps  $170,%xmm1,%xmm1
-       xorps   %xmm1,%xmm2
-       .byte   0xf3,0xc3
-.size  aesni_set_encrypt_key,.-aesni_set_encrypt_key
-.size  __aesni_set_encrypt_key,.-__aesni_set_encrypt_key
-.align 64
-.Lbswap_mask:
-.byte  15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
-.Lincrement32:
-.long  6,6,6,0
-.Lincrement64:
-.long  1,0,0,0
-.Lxts_magic:
-.long  0x87,0,1,0
-
-.byte  
65,69,83,32,102,111,114,32,73,110,116,101,108,32,65,69,83,45,78,73,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
-.align 64
-
-#if defined(__linux__) && defined(__ELF__)
-.section .note.GNU-stack,"",%progbits
-#endif
-
diff --git a/lib/accelerated/intel/asm/appro-aes-x86.s 
b/lib/accelerated/intel/asm/appro-aes-x86.s
deleted file mode 100644
index f095a63..0000000
--- a/lib/accelerated/intel/asm/appro-aes-x86.s
+++ /dev/null
@@ -1,2186 +0,0 @@
-# Copyright (c) 2011, Andy Polyakov by <address@hidden>
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 
-#     * Redistributions of source code must retain copyright notices,
-#      this list of conditions and the following disclaimer.
-#
-#     * Redistributions in binary form must reproduce the above
-#      copyright notice, this list of conditions and the following
-#      disclaimer in the documentation and/or other materials
-#      provided with the distribution.
-#
-#     * Neither the name of the Andy Polyakov nor the names of its
-#      copyright holder and contributors may be used to endorse or
-#      promote products derived from this software without specific
-#      prior written permission.
-#
-# ALTERNATIVELY, provided that this notice is retained in full, this
-# product may be distributed under the terms of the GNU General Public
-# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
-# those given above.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-.file  "aesni-x86.s"
-.text
-.globl aesni_encrypt
-.type  aesni_encrypt,@function
-.align 16
-aesni_encrypt:
-.L_aesni_encrypt_begin:
-       movl    4(%esp),%eax
-       movl    12(%esp),%edx
-       movups  (%eax),%xmm2
-       movl    240(%edx),%ecx
-       movl    8(%esp),%eax
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L000enc1_loop_1:
-.byte  102,15,56,220,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L000enc1_loop_1
-.byte  102,15,56,221,209
-       movups  %xmm2,(%eax)
-       ret
-.size  aesni_encrypt,.-.L_aesni_encrypt_begin
-.globl aesni_decrypt
-.type  aesni_decrypt,@function
-.align 16
-aesni_decrypt:
-.L_aesni_decrypt_begin:
-       movl    4(%esp),%eax
-       movl    12(%esp),%edx
-       movups  (%eax),%xmm2
-       movl    240(%edx),%ecx
-       movl    8(%esp),%eax
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L001dec1_loop_2:
-.byte  102,15,56,222,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L001dec1_loop_2
-.byte  102,15,56,223,209
-       movups  %xmm2,(%eax)
-       ret
-.size  aesni_decrypt,.-.L_aesni_decrypt_begin
-.type  _aesni_encrypt3,@function
-.align 16
-_aesni_encrypt3:
-       movups  (%edx),%xmm0
-       shrl    $1,%ecx
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-       pxor    %xmm0,%xmm3
-       pxor    %xmm0,%xmm4
-       movups  (%edx),%xmm0
-.L002enc3_loop:
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-       decl    %ecx
-.byte  102,15,56,220,225
-       movups  16(%edx),%xmm1
-.byte  102,15,56,220,208
-.byte  102,15,56,220,216
-       leal    32(%edx),%edx
-.byte  102,15,56,220,224
-       movups  (%edx),%xmm0
-       jnz     .L002enc3_loop
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-.byte  102,15,56,220,225
-.byte  102,15,56,221,208
-.byte  102,15,56,221,216
-.byte  102,15,56,221,224
-       ret
-.size  _aesni_encrypt3,.-_aesni_encrypt3
-.type  _aesni_decrypt3,@function
-.align 16
-_aesni_decrypt3:
-       movups  (%edx),%xmm0
-       shrl    $1,%ecx
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-       pxor    %xmm0,%xmm3
-       pxor    %xmm0,%xmm4
-       movups  (%edx),%xmm0
-.L003dec3_loop:
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-       decl    %ecx
-.byte  102,15,56,222,225
-       movups  16(%edx),%xmm1
-.byte  102,15,56,222,208
-.byte  102,15,56,222,216
-       leal    32(%edx),%edx
-.byte  102,15,56,222,224
-       movups  (%edx),%xmm0
-       jnz     .L003dec3_loop
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-.byte  102,15,56,222,225
-.byte  102,15,56,223,208
-.byte  102,15,56,223,216
-.byte  102,15,56,223,224
-       ret
-.size  _aesni_decrypt3,.-_aesni_decrypt3
-.type  _aesni_encrypt4,@function
-.align 16
-_aesni_encrypt4:
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       shrl    $1,%ecx
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-       pxor    %xmm0,%xmm3
-       pxor    %xmm0,%xmm4
-       pxor    %xmm0,%xmm5
-       movups  (%edx),%xmm0
-.L004enc4_loop:
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-       decl    %ecx
-.byte  102,15,56,220,225
-.byte  102,15,56,220,233
-       movups  16(%edx),%xmm1
-.byte  102,15,56,220,208
-.byte  102,15,56,220,216
-       leal    32(%edx),%edx
-.byte  102,15,56,220,224
-.byte  102,15,56,220,232
-       movups  (%edx),%xmm0
-       jnz     .L004enc4_loop
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-.byte  102,15,56,220,225
-.byte  102,15,56,220,233
-.byte  102,15,56,221,208
-.byte  102,15,56,221,216
-.byte  102,15,56,221,224
-.byte  102,15,56,221,232
-       ret
-.size  _aesni_encrypt4,.-_aesni_encrypt4
-.type  _aesni_decrypt4,@function
-.align 16
-_aesni_decrypt4:
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       shrl    $1,%ecx
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-       pxor    %xmm0,%xmm3
-       pxor    %xmm0,%xmm4
-       pxor    %xmm0,%xmm5
-       movups  (%edx),%xmm0
-.L005dec4_loop:
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-       decl    %ecx
-.byte  102,15,56,222,225
-.byte  102,15,56,222,233
-       movups  16(%edx),%xmm1
-.byte  102,15,56,222,208
-.byte  102,15,56,222,216
-       leal    32(%edx),%edx
-.byte  102,15,56,222,224
-.byte  102,15,56,222,232
-       movups  (%edx),%xmm0
-       jnz     .L005dec4_loop
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-.byte  102,15,56,222,225
-.byte  102,15,56,222,233
-.byte  102,15,56,223,208
-.byte  102,15,56,223,216
-.byte  102,15,56,223,224
-.byte  102,15,56,223,232
-       ret
-.size  _aesni_decrypt4,.-_aesni_decrypt4
-.type  _aesni_encrypt6,@function
-.align 16
-_aesni_encrypt6:
-       movups  (%edx),%xmm0
-       shrl    $1,%ecx
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-       pxor    %xmm0,%xmm3
-.byte  102,15,56,220,209
-       pxor    %xmm0,%xmm4
-.byte  102,15,56,220,217
-       pxor    %xmm0,%xmm5
-       decl    %ecx
-.byte  102,15,56,220,225
-       pxor    %xmm0,%xmm6
-.byte  102,15,56,220,233
-       pxor    %xmm0,%xmm7
-.byte  102,15,56,220,241
-       movups  (%edx),%xmm0
-.byte  102,15,56,220,249
-       jmp     .L_aesni_encrypt6_enter
-.align 16
-.L006enc6_loop:
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-       decl    %ecx
-.byte  102,15,56,220,225
-.byte  102,15,56,220,233
-.byte  102,15,56,220,241
-.byte  102,15,56,220,249
-.align 16
-.L_aesni_encrypt6_enter:
-       movups  16(%edx),%xmm1
-.byte  102,15,56,220,208
-.byte  102,15,56,220,216
-       leal    32(%edx),%edx
-.byte  102,15,56,220,224
-.byte  102,15,56,220,232
-.byte  102,15,56,220,240
-.byte  102,15,56,220,248
-       movups  (%edx),%xmm0
-       jnz     .L006enc6_loop
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-.byte  102,15,56,220,225
-.byte  102,15,56,220,233
-.byte  102,15,56,220,241
-.byte  102,15,56,220,249
-.byte  102,15,56,221,208
-.byte  102,15,56,221,216
-.byte  102,15,56,221,224
-.byte  102,15,56,221,232
-.byte  102,15,56,221,240
-.byte  102,15,56,221,248
-       ret
-.size  _aesni_encrypt6,.-_aesni_encrypt6
-.type  _aesni_decrypt6,@function
-.align 16
-_aesni_decrypt6:
-       movups  (%edx),%xmm0
-       shrl    $1,%ecx
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-       pxor    %xmm0,%xmm3
-.byte  102,15,56,222,209
-       pxor    %xmm0,%xmm4
-.byte  102,15,56,222,217
-       pxor    %xmm0,%xmm5
-       decl    %ecx
-.byte  102,15,56,222,225
-       pxor    %xmm0,%xmm6
-.byte  102,15,56,222,233
-       pxor    %xmm0,%xmm7
-.byte  102,15,56,222,241
-       movups  (%edx),%xmm0
-.byte  102,15,56,222,249
-       jmp     .L_aesni_decrypt6_enter
-.align 16
-.L007dec6_loop:
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-       decl    %ecx
-.byte  102,15,56,222,225
-.byte  102,15,56,222,233
-.byte  102,15,56,222,241
-.byte  102,15,56,222,249
-.align 16
-.L_aesni_decrypt6_enter:
-       movups  16(%edx),%xmm1
-.byte  102,15,56,222,208
-.byte  102,15,56,222,216
-       leal    32(%edx),%edx
-.byte  102,15,56,222,224
-.byte  102,15,56,222,232
-.byte  102,15,56,222,240
-.byte  102,15,56,222,248
-       movups  (%edx),%xmm0
-       jnz     .L007dec6_loop
-.byte  102,15,56,222,209
-.byte  102,15,56,222,217
-.byte  102,15,56,222,225
-.byte  102,15,56,222,233
-.byte  102,15,56,222,241
-.byte  102,15,56,222,249
-.byte  102,15,56,223,208
-.byte  102,15,56,223,216
-.byte  102,15,56,223,224
-.byte  102,15,56,223,232
-.byte  102,15,56,223,240
-.byte  102,15,56,223,248
-       ret
-.size  _aesni_decrypt6,.-_aesni_decrypt6
-.globl aesni_ecb_encrypt
-.type  aesni_ecb_encrypt,@function
-.align 16
-aesni_ecb_encrypt:
-.L_aesni_ecb_encrypt_begin:
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-       movl    20(%esp),%esi
-       movl    24(%esp),%edi
-       movl    28(%esp),%eax
-       movl    32(%esp),%edx
-       movl    36(%esp),%ebx
-       andl    $-16,%eax
-       jz      .L008ecb_ret
-       movl    240(%edx),%ecx
-       testl   %ebx,%ebx
-       jz      .L009ecb_decrypt
-       movl    %edx,%ebp
-       movl    %ecx,%ebx
-       cmpl    $96,%eax
-       jb      .L010ecb_enc_tail
-       movdqu  (%esi),%xmm2
-       movdqu  16(%esi),%xmm3
-       movdqu  32(%esi),%xmm4
-       movdqu  48(%esi),%xmm5
-       movdqu  64(%esi),%xmm6
-       movdqu  80(%esi),%xmm7
-       leal    96(%esi),%esi
-       subl    $96,%eax
-       jmp     .L011ecb_enc_loop6_enter
-.align 16
-.L012ecb_enc_loop6:
-       movups  %xmm2,(%edi)
-       movdqu  (%esi),%xmm2
-       movups  %xmm3,16(%edi)
-       movdqu  16(%esi),%xmm3
-       movups  %xmm4,32(%edi)
-       movdqu  32(%esi),%xmm4
-       movups  %xmm5,48(%edi)
-       movdqu  48(%esi),%xmm5
-       movups  %xmm6,64(%edi)
-       movdqu  64(%esi),%xmm6
-       movups  %xmm7,80(%edi)
-       leal    96(%edi),%edi
-       movdqu  80(%esi),%xmm7
-       leal    96(%esi),%esi
-.L011ecb_enc_loop6_enter:
-       call    _aesni_encrypt6
-       movl    %ebp,%edx
-       movl    %ebx,%ecx
-       subl    $96,%eax
-       jnc     .L012ecb_enc_loop6
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-       movups  %xmm6,64(%edi)
-       movups  %xmm7,80(%edi)
-       leal    96(%edi),%edi
-       addl    $96,%eax
-       jz      .L008ecb_ret
-.L010ecb_enc_tail:
-       movups  (%esi),%xmm2
-       cmpl    $32,%eax
-       jb      .L013ecb_enc_one
-       movups  16(%esi),%xmm3
-       je      .L014ecb_enc_two
-       movups  32(%esi),%xmm4
-       cmpl    $64,%eax
-       jb      .L015ecb_enc_three
-       movups  48(%esi),%xmm5
-       je      .L016ecb_enc_four
-       movups  64(%esi),%xmm6
-       xorps   %xmm7,%xmm7
-       call    _aesni_encrypt6
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-       movups  %xmm6,64(%edi)
-       jmp     .L008ecb_ret
-.align 16
-.L013ecb_enc_one:
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L017enc1_loop_3:
-.byte  102,15,56,220,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L017enc1_loop_3
-.byte  102,15,56,221,209
-       movups  %xmm2,(%edi)
-       jmp     .L008ecb_ret
-.align 16
-.L014ecb_enc_two:
-       xorps   %xmm4,%xmm4
-       call    _aesni_encrypt3
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       jmp     .L008ecb_ret
-.align 16
-.L015ecb_enc_three:
-       call    _aesni_encrypt3
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       jmp     .L008ecb_ret
-.align 16
-.L016ecb_enc_four:
-       call    _aesni_encrypt4
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-       jmp     .L008ecb_ret
-.align 16
-.L009ecb_decrypt:
-       movl    %edx,%ebp
-       movl    %ecx,%ebx
-       cmpl    $96,%eax
-       jb      .L018ecb_dec_tail
-       movdqu  (%esi),%xmm2
-       movdqu  16(%esi),%xmm3
-       movdqu  32(%esi),%xmm4
-       movdqu  48(%esi),%xmm5
-       movdqu  64(%esi),%xmm6
-       movdqu  80(%esi),%xmm7
-       leal    96(%esi),%esi
-       subl    $96,%eax
-       jmp     .L019ecb_dec_loop6_enter
-.align 16
-.L020ecb_dec_loop6:
-       movups  %xmm2,(%edi)
-       movdqu  (%esi),%xmm2
-       movups  %xmm3,16(%edi)
-       movdqu  16(%esi),%xmm3
-       movups  %xmm4,32(%edi)
-       movdqu  32(%esi),%xmm4
-       movups  %xmm5,48(%edi)
-       movdqu  48(%esi),%xmm5
-       movups  %xmm6,64(%edi)
-       movdqu  64(%esi),%xmm6
-       movups  %xmm7,80(%edi)
-       leal    96(%edi),%edi
-       movdqu  80(%esi),%xmm7
-       leal    96(%esi),%esi
-.L019ecb_dec_loop6_enter:
-       call    _aesni_decrypt6
-       movl    %ebp,%edx
-       movl    %ebx,%ecx
-       subl    $96,%eax
-       jnc     .L020ecb_dec_loop6
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-       movups  %xmm6,64(%edi)
-       movups  %xmm7,80(%edi)
-       leal    96(%edi),%edi
-       addl    $96,%eax
-       jz      .L008ecb_ret
-.L018ecb_dec_tail:
-       movups  (%esi),%xmm2
-       cmpl    $32,%eax
-       jb      .L021ecb_dec_one
-       movups  16(%esi),%xmm3
-       je      .L022ecb_dec_two
-       movups  32(%esi),%xmm4
-       cmpl    $64,%eax
-       jb      .L023ecb_dec_three
-       movups  48(%esi),%xmm5
-       je      .L024ecb_dec_four
-       movups  64(%esi),%xmm6
-       xorps   %xmm7,%xmm7
-       call    _aesni_decrypt6
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-       movups  %xmm6,64(%edi)
-       jmp     .L008ecb_ret
-.align 16
-.L021ecb_dec_one:
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L025dec1_loop_4:
-.byte  102,15,56,222,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L025dec1_loop_4
-.byte  102,15,56,223,209
-       movups  %xmm2,(%edi)
-       jmp     .L008ecb_ret
-.align 16
-.L022ecb_dec_two:
-       xorps   %xmm4,%xmm4
-       call    _aesni_decrypt3
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       jmp     .L008ecb_ret
-.align 16
-.L023ecb_dec_three:
-       call    _aesni_decrypt3
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       jmp     .L008ecb_ret
-.align 16
-.L024ecb_dec_four:
-       call    _aesni_decrypt4
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-.L008ecb_ret:
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-.size  aesni_ecb_encrypt,.-.L_aesni_ecb_encrypt_begin
-.globl aesni_ccm64_encrypt_blocks
-.type  aesni_ccm64_encrypt_blocks,@function
-.align 16
-aesni_ccm64_encrypt_blocks:
-.L_aesni_ccm64_encrypt_blocks_begin:
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-       movl    20(%esp),%esi
-       movl    24(%esp),%edi
-       movl    28(%esp),%eax
-       movl    32(%esp),%edx
-       movl    36(%esp),%ebx
-       movl    40(%esp),%ecx
-       movl    %esp,%ebp
-       subl    $60,%esp
-       andl    $-16,%esp
-       movl    %ebp,48(%esp)
-       movdqu  (%ebx),%xmm7
-       movdqu  (%ecx),%xmm3
-       movl    240(%edx),%ecx
-       movl    $202182159,(%esp)
-       movl    $134810123,4(%esp)
-       movl    $67438087,8(%esp)
-       movl    $66051,12(%esp)
-       movl    $1,%ebx
-       xorl    %ebp,%ebp
-       movl    %ebx,16(%esp)
-       movl    %ebp,20(%esp)
-       movl    %ebp,24(%esp)
-       movl    %ebp,28(%esp)
-       shrl    $1,%ecx
-       leal    (%edx),%ebp
-       movdqa  %xmm7,%xmm2
-       movl    %ecx,%ebx
-       movdqa  (%esp),%xmm5
-.L026ccm64_enc_outer:
-       movups  (%ebp),%xmm0
-       movl    %ebx,%ecx
-       movups  (%esi),%xmm6
-       xorps   %xmm0,%xmm2
-       movups  16(%ebp),%xmm1
-       xorps   %xmm6,%xmm0
-       leal    32(%ebp),%edx
-       xorps   %xmm0,%xmm3
-       movups  (%edx),%xmm0
-.L027ccm64_enc2_loop:
-.byte  102,15,56,220,209
-       decl    %ecx
-.byte  102,15,56,220,217
-       movups  16(%edx),%xmm1
-.byte  102,15,56,220,208
-       leal    32(%edx),%edx
-.byte  102,15,56,220,216
-       movups  (%edx),%xmm0
-       jnz     .L027ccm64_enc2_loop
-.byte  102,15,56,0,253
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-       paddq   16(%esp),%xmm7
-.byte  102,15,56,221,208
-.byte  102,15,56,221,216
-       decl    %eax
-       leal    16(%esi),%esi
-       xorps   %xmm2,%xmm6
-       movdqa  %xmm7,%xmm2
-       movups  %xmm6,(%edi)
-       leal    16(%edi),%edi
-.byte  102,15,56,0,253
-       jnz     .L026ccm64_enc_outer
-       movl    48(%esp),%esp
-       movl    40(%esp),%edi
-       movups  %xmm3,(%edi)
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-.size  aesni_ccm64_encrypt_blocks,.-.L_aesni_ccm64_encrypt_blocks_begin
-.globl aesni_ccm64_decrypt_blocks
-.type  aesni_ccm64_decrypt_blocks,@function
-.align 16
-aesni_ccm64_decrypt_blocks:
-.L_aesni_ccm64_decrypt_blocks_begin:
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-       movl    20(%esp),%esi
-       movl    24(%esp),%edi
-       movl    28(%esp),%eax
-       movl    32(%esp),%edx
-       movl    36(%esp),%ebx
-       movl    40(%esp),%ecx
-       movl    %esp,%ebp
-       subl    $60,%esp
-       andl    $-16,%esp
-       movl    %ebp,48(%esp)
-       movdqu  (%ebx),%xmm7
-       movdqu  (%ecx),%xmm3
-       movl    240(%edx),%ecx
-       movl    $202182159,(%esp)
-       movl    $134810123,4(%esp)
-       movl    $67438087,8(%esp)
-       movl    $66051,12(%esp)
-       movl    $1,%ebx
-       xorl    %ebp,%ebp
-       movl    %ebx,16(%esp)
-       movl    %ebp,20(%esp)
-       movl    %ebp,24(%esp)
-       movl    %ebp,28(%esp)
-       movdqa  (%esp),%xmm5
-       movdqa  %xmm7,%xmm2
-       movl    %edx,%ebp
-       movl    %ecx,%ebx
-.byte  102,15,56,0,253
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L028enc1_loop_5:
-.byte  102,15,56,220,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L028enc1_loop_5
-.byte  102,15,56,221,209
-       movups  (%esi),%xmm6
-       paddq   16(%esp),%xmm7
-.byte  102,15,56,0,253
-       leal    16(%esi),%esi
-       jmp     .L029ccm64_dec_outer
-.align 16
-.L029ccm64_dec_outer:
-       xorps   %xmm2,%xmm6
-       movdqa  %xmm7,%xmm2
-       movl    %ebx,%ecx
-       movups  %xmm6,(%edi)
-       leal    16(%edi),%edi
-       subl    $1,%eax
-       jz      .L030ccm64_dec_break
-       movups  (%ebp),%xmm0
-       shrl    $1,%ecx
-       movups  16(%ebp),%xmm1
-       xorps   %xmm0,%xmm6
-       leal    32(%ebp),%edx
-       xorps   %xmm0,%xmm2
-       xorps   %xmm6,%xmm3
-       movups  (%edx),%xmm0
-.L031ccm64_dec2_loop:
-.byte  102,15,56,220,209
-       decl    %ecx
-.byte  102,15,56,220,217
-       movups  16(%edx),%xmm1
-.byte  102,15,56,220,208
-       leal    32(%edx),%edx
-.byte  102,15,56,220,216
-       movups  (%edx),%xmm0
-       jnz     .L031ccm64_dec2_loop
-       movups  (%esi),%xmm6
-       paddq   16(%esp),%xmm7
-.byte  102,15,56,220,209
-.byte  102,15,56,220,217
-.byte  102,15,56,0,253
-       leal    16(%esi),%esi
-.byte  102,15,56,221,208
-.byte  102,15,56,221,216
-       jmp     .L029ccm64_dec_outer
-.align 16
-.L030ccm64_dec_break:
-       movl    %ebp,%edx
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       xorps   %xmm0,%xmm6
-       leal    32(%edx),%edx
-       xorps   %xmm6,%xmm3
-.L032enc1_loop_6:
-.byte  102,15,56,220,217
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L032enc1_loop_6
-.byte  102,15,56,221,217
-       movl    48(%esp),%esp
-       movl    40(%esp),%edi
-       movups  %xmm3,(%edi)
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-.size  aesni_ccm64_decrypt_blocks,.-.L_aesni_ccm64_decrypt_blocks_begin
-.globl aesni_ctr32_encrypt_blocks
-.type  aesni_ctr32_encrypt_blocks,@function
-.align 16
-aesni_ctr32_encrypt_blocks:
-.L_aesni_ctr32_encrypt_blocks_begin:
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-       movl    20(%esp),%esi
-       movl    24(%esp),%edi
-       movl    28(%esp),%eax
-       movl    32(%esp),%edx
-       movl    36(%esp),%ebx
-       movl    %esp,%ebp
-       subl    $88,%esp
-       andl    $-16,%esp
-       movl    %ebp,80(%esp)
-       cmpl    $1,%eax
-       je      .L033ctr32_one_shortcut
-       movdqu  (%ebx),%xmm7
-       movl    $202182159,(%esp)
-       movl    $134810123,4(%esp)
-       movl    $67438087,8(%esp)
-       movl    $66051,12(%esp)
-       movl    $6,%ecx
-       xorl    %ebp,%ebp
-       movl    %ecx,16(%esp)
-       movl    %ecx,20(%esp)
-       movl    %ecx,24(%esp)
-       movl    %ebp,28(%esp)
-.byte  102,15,58,22,251,3
-.byte  102,15,58,34,253,3
-       movl    240(%edx),%ecx
-       bswap   %ebx
-       pxor    %xmm1,%xmm1
-       pxor    %xmm0,%xmm0
-       movdqa  (%esp),%xmm2
-.byte  102,15,58,34,203,0
-       leal    3(%ebx),%ebp
-.byte  102,15,58,34,197,0
-       incl    %ebx
-.byte  102,15,58,34,203,1
-       incl    %ebp
-.byte  102,15,58,34,197,1
-       incl    %ebx
-.byte  102,15,58,34,203,2
-       incl    %ebp
-.byte  102,15,58,34,197,2
-       movdqa  %xmm1,48(%esp)
-.byte  102,15,56,0,202
-       movdqa  %xmm0,64(%esp)
-.byte  102,15,56,0,194
-       pshufd  $192,%xmm1,%xmm2
-       pshufd  $128,%xmm1,%xmm3
-       cmpl    $6,%eax
-       jb      .L034ctr32_tail
-       movdqa  %xmm7,32(%esp)
-       shrl    $1,%ecx
-       movl    %edx,%ebp
-       movl    %ecx,%ebx
-       subl    $6,%eax
-       jmp     .L035ctr32_loop6
-.align 16
-.L035ctr32_loop6:
-       pshufd  $64,%xmm1,%xmm4
-       movdqa  32(%esp),%xmm1
-       pshufd  $192,%xmm0,%xmm5
-       por     %xmm1,%xmm2
-       pshufd  $128,%xmm0,%xmm6
-       por     %xmm1,%xmm3
-       pshufd  $64,%xmm0,%xmm7
-       por     %xmm1,%xmm4
-       por     %xmm1,%xmm5
-       por     %xmm1,%xmm6
-       por     %xmm1,%xmm7
-       movups  (%ebp),%xmm0
-       movups  16(%ebp),%xmm1
-       leal    32(%ebp),%edx
-       decl    %ecx
-       pxor    %xmm0,%xmm2
-       pxor    %xmm0,%xmm3
-.byte  102,15,56,220,209
-       pxor    %xmm0,%xmm4
-.byte  102,15,56,220,217
-       pxor    %xmm0,%xmm5
-.byte  102,15,56,220,225
-       pxor    %xmm0,%xmm6
-.byte  102,15,56,220,233
-       pxor    %xmm0,%xmm7
-.byte  102,15,56,220,241
-       movups  (%edx),%xmm0
-.byte  102,15,56,220,249
-       call    .L_aesni_encrypt6_enter
-       movups  (%esi),%xmm1
-       movups  16(%esi),%xmm0
-       xorps   %xmm1,%xmm2
-       movups  32(%esi),%xmm1
-       xorps   %xmm0,%xmm3
-       movups  %xmm2,(%edi)
-       movdqa  16(%esp),%xmm0
-       xorps   %xmm1,%xmm4
-       movdqa  48(%esp),%xmm1
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       paddd   %xmm0,%xmm1
-       paddd   64(%esp),%xmm0
-       movdqa  (%esp),%xmm2
-       movups  48(%esi),%xmm3
-       movups  64(%esi),%xmm4
-       xorps   %xmm3,%xmm5
-       movups  80(%esi),%xmm3
-       leal    96(%esi),%esi
-       movdqa  %xmm1,48(%esp)
-.byte  102,15,56,0,202
-       xorps   %xmm4,%xmm6
-       movups  %xmm5,48(%edi)
-       xorps   %xmm3,%xmm7
-       movdqa  %xmm0,64(%esp)
-.byte  102,15,56,0,194
-       movups  %xmm6,64(%edi)
-       pshufd  $192,%xmm1,%xmm2
-       movups  %xmm7,80(%edi)
-       leal    96(%edi),%edi
-       movl    %ebx,%ecx
-       pshufd  $128,%xmm1,%xmm3
-       subl    $6,%eax
-       jnc     .L035ctr32_loop6
-       addl    $6,%eax
-       jz      .L036ctr32_ret
-       movl    %ebp,%edx
-       leal    1(,%ecx,2),%ecx
-       movdqa  32(%esp),%xmm7
-.L034ctr32_tail:
-       por     %xmm7,%xmm2
-       cmpl    $2,%eax
-       jb      .L037ctr32_one
-       pshufd  $64,%xmm1,%xmm4
-       por     %xmm7,%xmm3
-       je      .L038ctr32_two
-       pshufd  $192,%xmm0,%xmm5
-       por     %xmm7,%xmm4
-       cmpl    $4,%eax
-       jb      .L039ctr32_three
-       pshufd  $128,%xmm0,%xmm6
-       por     %xmm7,%xmm5
-       je      .L040ctr32_four
-       por     %xmm7,%xmm6
-       call    _aesni_encrypt6
-       movups  (%esi),%xmm1
-       movups  16(%esi),%xmm0
-       xorps   %xmm1,%xmm2
-       movups  32(%esi),%xmm1
-       xorps   %xmm0,%xmm3
-       movups  48(%esi),%xmm0
-       xorps   %xmm1,%xmm4
-       movups  64(%esi),%xmm1
-       xorps   %xmm0,%xmm5
-       movups  %xmm2,(%edi)
-       xorps   %xmm1,%xmm6
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-       movups  %xmm6,64(%edi)
-       jmp     .L036ctr32_ret
-.align 16
-.L033ctr32_one_shortcut:
-       movups  (%ebx),%xmm2
-       movl    240(%edx),%ecx
-.L037ctr32_one:
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L041enc1_loop_7:
-.byte  102,15,56,220,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L041enc1_loop_7
-.byte  102,15,56,221,209
-       movups  (%esi),%xmm6
-       xorps   %xmm2,%xmm6
-       movups  %xmm6,(%edi)
-       jmp     .L036ctr32_ret
-.align 16
-.L038ctr32_two:
-       call    _aesni_encrypt3
-       movups  (%esi),%xmm5
-       movups  16(%esi),%xmm6
-       xorps   %xmm5,%xmm2
-       xorps   %xmm6,%xmm3
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       jmp     .L036ctr32_ret
-.align 16
-.L039ctr32_three:
-       call    _aesni_encrypt3
-       movups  (%esi),%xmm5
-       movups  16(%esi),%xmm6
-       xorps   %xmm5,%xmm2
-       movups  32(%esi),%xmm7
-       xorps   %xmm6,%xmm3
-       movups  %xmm2,(%edi)
-       xorps   %xmm7,%xmm4
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       jmp     .L036ctr32_ret
-.align 16
-.L040ctr32_four:
-       call    _aesni_encrypt4
-       movups  (%esi),%xmm6
-       movups  16(%esi),%xmm7
-       movups  32(%esi),%xmm1
-       xorps   %xmm6,%xmm2
-       movups  48(%esi),%xmm0
-       xorps   %xmm7,%xmm3
-       movups  %xmm2,(%edi)
-       xorps   %xmm1,%xmm4
-       movups  %xmm3,16(%edi)
-       xorps   %xmm0,%xmm5
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-.L036ctr32_ret:
-       movl    80(%esp),%esp
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-.size  aesni_ctr32_encrypt_blocks,.-.L_aesni_ctr32_encrypt_blocks_begin
-.globl aesni_xts_encrypt
-.type  aesni_xts_encrypt,@function
-.align 16
-aesni_xts_encrypt:
-.L_aesni_xts_encrypt_begin:
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-       movl    36(%esp),%edx
-       movl    40(%esp),%esi
-       movl    240(%edx),%ecx
-       movups  (%esi),%xmm2
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L042enc1_loop_8:
-.byte  102,15,56,220,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L042enc1_loop_8
-.byte  102,15,56,221,209
-       movl    20(%esp),%esi
-       movl    24(%esp),%edi
-       movl    28(%esp),%eax
-       movl    32(%esp),%edx
-       movl    %esp,%ebp
-       subl    $120,%esp
-       movl    240(%edx),%ecx
-       andl    $-16,%esp
-       movl    $135,96(%esp)
-       movl    $0,100(%esp)
-       movl    $1,104(%esp)
-       movl    $0,108(%esp)
-       movl    %eax,112(%esp)
-       movl    %ebp,116(%esp)
-       movdqa  %xmm2,%xmm1
-       pxor    %xmm0,%xmm0
-       movdqa  96(%esp),%xmm3
-       pcmpgtd %xmm1,%xmm0
-       andl    $-16,%eax
-       movl    %edx,%ebp
-       movl    %ecx,%ebx
-       subl    $96,%eax
-       jc      .L043xts_enc_short
-       shrl    $1,%ecx
-       movl    %ecx,%ebx
-       jmp     .L044xts_enc_loop6
-.align 16
-.L044xts_enc_loop6:
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  %xmm1,(%esp)
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  %xmm1,16(%esp)
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  %xmm1,32(%esp)
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  %xmm1,48(%esp)
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       pshufd  $19,%xmm0,%xmm7
-       movdqa  %xmm1,64(%esp)
-       paddq   %xmm1,%xmm1
-       movups  (%ebp),%xmm0
-       pand    %xmm3,%xmm7
-       movups  (%esi),%xmm2
-       pxor    %xmm1,%xmm7
-       movdqu  16(%esi),%xmm3
-       xorps   %xmm0,%xmm2
-       movdqu  32(%esi),%xmm4
-       pxor    %xmm0,%xmm3
-       movdqu  48(%esi),%xmm5
-       pxor    %xmm0,%xmm4
-       movdqu  64(%esi),%xmm6
-       pxor    %xmm0,%xmm5
-       movdqu  80(%esi),%xmm1
-       pxor    %xmm0,%xmm6
-       leal    96(%esi),%esi
-       pxor    (%esp),%xmm2
-       movdqa  %xmm7,80(%esp)
-       pxor    %xmm1,%xmm7
-       movups  16(%ebp),%xmm1
-       leal    32(%ebp),%edx
-       pxor    16(%esp),%xmm3
-.byte  102,15,56,220,209
-       pxor    32(%esp),%xmm4
-.byte  102,15,56,220,217
-       pxor    48(%esp),%xmm5
-       decl    %ecx
-.byte  102,15,56,220,225
-       pxor    64(%esp),%xmm6
-.byte  102,15,56,220,233
-       pxor    %xmm0,%xmm7
-.byte  102,15,56,220,241
-       movups  (%edx),%xmm0
-.byte  102,15,56,220,249
-       call    .L_aesni_encrypt6_enter
-       movdqa  80(%esp),%xmm1
-       pxor    %xmm0,%xmm0
-       xorps   (%esp),%xmm2
-       pcmpgtd %xmm1,%xmm0
-       xorps   16(%esp),%xmm3
-       movups  %xmm2,(%edi)
-       xorps   32(%esp),%xmm4
-       movups  %xmm3,16(%edi)
-       xorps   48(%esp),%xmm5
-       movups  %xmm4,32(%edi)
-       xorps   64(%esp),%xmm6
-       movups  %xmm5,48(%edi)
-       xorps   %xmm1,%xmm7
-       movups  %xmm6,64(%edi)
-       pshufd  $19,%xmm0,%xmm2
-       movups  %xmm7,80(%edi)
-       leal    96(%edi),%edi
-       movdqa  96(%esp),%xmm3
-       pxor    %xmm0,%xmm0
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       movl    %ebx,%ecx
-       pxor    %xmm2,%xmm1
-       subl    $96,%eax
-       jnc     .L044xts_enc_loop6
-       leal    1(,%ecx,2),%ecx
-       movl    %ebp,%edx
-       movl    %ecx,%ebx
-.L043xts_enc_short:
-       addl    $96,%eax
-       jz      .L045xts_enc_done6x
-       movdqa  %xmm1,%xmm5
-       cmpl    $32,%eax
-       jb      .L046xts_enc_one
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       je      .L047xts_enc_two
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  %xmm1,%xmm6
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       cmpl    $64,%eax
-       jb      .L048xts_enc_three
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  %xmm1,%xmm7
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       movdqa  %xmm5,(%esp)
-       movdqa  %xmm6,16(%esp)
-       je      .L049xts_enc_four
-       movdqa  %xmm7,32(%esp)
-       pshufd  $19,%xmm0,%xmm7
-       movdqa  %xmm1,48(%esp)
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm7
-       pxor    %xmm1,%xmm7
-       movdqu  (%esi),%xmm2
-       movdqu  16(%esi),%xmm3
-       movdqu  32(%esi),%xmm4
-       pxor    (%esp),%xmm2
-       movdqu  48(%esi),%xmm5
-       pxor    16(%esp),%xmm3
-       movdqu  64(%esi),%xmm6
-       pxor    32(%esp),%xmm4
-       leal    80(%esi),%esi
-       pxor    48(%esp),%xmm5
-       movdqa  %xmm7,64(%esp)
-       pxor    %xmm7,%xmm6
-       call    _aesni_encrypt6
-       movaps  64(%esp),%xmm1
-       xorps   (%esp),%xmm2
-       xorps   16(%esp),%xmm3
-       xorps   32(%esp),%xmm4
-       movups  %xmm2,(%edi)
-       xorps   48(%esp),%xmm5
-       movups  %xmm3,16(%edi)
-       xorps   %xmm1,%xmm6
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-       movups  %xmm6,64(%edi)
-       leal    80(%edi),%edi
-       jmp     .L050xts_enc_done
-.align 16
-.L046xts_enc_one:
-       movups  (%esi),%xmm2
-       leal    16(%esi),%esi
-       xorps   %xmm5,%xmm2
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L051enc1_loop_9:
-.byte  102,15,56,220,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L051enc1_loop_9
-.byte  102,15,56,221,209
-       xorps   %xmm5,%xmm2
-       movups  %xmm2,(%edi)
-       leal    16(%edi),%edi
-       movdqa  %xmm5,%xmm1
-       jmp     .L050xts_enc_done
-.align 16
-.L047xts_enc_two:
-       movaps  %xmm1,%xmm6
-       movups  (%esi),%xmm2
-       movups  16(%esi),%xmm3
-       leal    32(%esi),%esi
-       xorps   %xmm5,%xmm2
-       xorps   %xmm6,%xmm3
-       xorps   %xmm4,%xmm4
-       call    _aesni_encrypt3
-       xorps   %xmm5,%xmm2
-       xorps   %xmm6,%xmm3
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       leal    32(%edi),%edi
-       movdqa  %xmm6,%xmm1
-       jmp     .L050xts_enc_done
-.align 16
-.L048xts_enc_three:
-       movaps  %xmm1,%xmm7
-       movups  (%esi),%xmm2
-       movups  16(%esi),%xmm3
-       movups  32(%esi),%xmm4
-       leal    48(%esi),%esi
-       xorps   %xmm5,%xmm2
-       xorps   %xmm6,%xmm3
-       xorps   %xmm7,%xmm4
-       call    _aesni_encrypt3
-       xorps   %xmm5,%xmm2
-       xorps   %xmm6,%xmm3
-       xorps   %xmm7,%xmm4
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       leal    48(%edi),%edi
-       movdqa  %xmm7,%xmm1
-       jmp     .L050xts_enc_done
-.align 16
-.L049xts_enc_four:
-       movaps  %xmm1,%xmm6
-       movups  (%esi),%xmm2
-       movups  16(%esi),%xmm3
-       movups  32(%esi),%xmm4
-       xorps   (%esp),%xmm2
-       movups  48(%esi),%xmm5
-       leal    64(%esi),%esi
-       xorps   16(%esp),%xmm3
-       xorps   %xmm7,%xmm4
-       xorps   %xmm6,%xmm5
-       call    _aesni_encrypt4
-       xorps   (%esp),%xmm2
-       xorps   16(%esp),%xmm3
-       xorps   %xmm7,%xmm4
-       movups  %xmm2,(%edi)
-       xorps   %xmm6,%xmm5
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-       leal    64(%edi),%edi
-       movdqa  %xmm6,%xmm1
-       jmp     .L050xts_enc_done
-.align 16
-.L045xts_enc_done6x:
-       movl    112(%esp),%eax
-       andl    $15,%eax
-       jz      .L052xts_enc_ret
-       movdqa  %xmm1,%xmm5
-       movl    %eax,112(%esp)
-       jmp     .L053xts_enc_steal
-.align 16
-.L050xts_enc_done:
-       movl    112(%esp),%eax
-       pxor    %xmm0,%xmm0
-       andl    $15,%eax
-       jz      .L052xts_enc_ret
-       pcmpgtd %xmm1,%xmm0
-       movl    %eax,112(%esp)
-       pshufd  $19,%xmm0,%xmm5
-       paddq   %xmm1,%xmm1
-       pand    96(%esp),%xmm5
-       pxor    %xmm1,%xmm5
-.L053xts_enc_steal:
-       movzbl  (%esi),%ecx
-       movzbl  -16(%edi),%edx
-       leal    1(%esi),%esi
-       movb    %cl,-16(%edi)
-       movb    %dl,(%edi)
-       leal    1(%edi),%edi
-       subl    $1,%eax
-       jnz     .L053xts_enc_steal
-       subl    112(%esp),%edi
-       movl    %ebp,%edx
-       movl    %ebx,%ecx
-       movups  -16(%edi),%xmm2
-       xorps   %xmm5,%xmm2
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L054enc1_loop_10:
-.byte  102,15,56,220,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L054enc1_loop_10
-.byte  102,15,56,221,209
-       xorps   %xmm5,%xmm2
-       movups  %xmm2,-16(%edi)
-.L052xts_enc_ret:
-       movl    116(%esp),%esp
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-.size  aesni_xts_encrypt,.-.L_aesni_xts_encrypt_begin
-.globl aesni_xts_decrypt
-.type  aesni_xts_decrypt,@function
-.align 16
-aesni_xts_decrypt:
-.L_aesni_xts_decrypt_begin:
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-       movl    36(%esp),%edx
-       movl    40(%esp),%esi
-       movl    240(%edx),%ecx
-       movups  (%esi),%xmm2
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L055enc1_loop_11:
-.byte  102,15,56,220,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L055enc1_loop_11
-.byte  102,15,56,221,209
-       movl    20(%esp),%esi
-       movl    24(%esp),%edi
-       movl    28(%esp),%eax
-       movl    32(%esp),%edx
-       movl    %esp,%ebp
-       subl    $120,%esp
-       andl    $-16,%esp
-       xorl    %ebx,%ebx
-       testl   $15,%eax
-       setnz   %bl
-       shll    $4,%ebx
-       subl    %ebx,%eax
-       movl    $135,96(%esp)
-       movl    $0,100(%esp)
-       movl    $1,104(%esp)
-       movl    $0,108(%esp)
-       movl    %eax,112(%esp)
-       movl    %ebp,116(%esp)
-       movl    240(%edx),%ecx
-       movl    %edx,%ebp
-       movl    %ecx,%ebx
-       movdqa  %xmm2,%xmm1
-       pxor    %xmm0,%xmm0
-       movdqa  96(%esp),%xmm3
-       pcmpgtd %xmm1,%xmm0
-       andl    $-16,%eax
-       subl    $96,%eax
-       jc      .L056xts_dec_short
-       shrl    $1,%ecx
-       movl    %ecx,%ebx
-       jmp     .L057xts_dec_loop6
-.align 16
-.L057xts_dec_loop6:
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  %xmm1,(%esp)
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  %xmm1,16(%esp)
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  %xmm1,32(%esp)
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  %xmm1,48(%esp)
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       pshufd  $19,%xmm0,%xmm7
-       movdqa  %xmm1,64(%esp)
-       paddq   %xmm1,%xmm1
-       movups  (%ebp),%xmm0
-       pand    %xmm3,%xmm7
-       movups  (%esi),%xmm2
-       pxor    %xmm1,%xmm7
-       movdqu  16(%esi),%xmm3
-       xorps   %xmm0,%xmm2
-       movdqu  32(%esi),%xmm4
-       pxor    %xmm0,%xmm3
-       movdqu  48(%esi),%xmm5
-       pxor    %xmm0,%xmm4
-       movdqu  64(%esi),%xmm6
-       pxor    %xmm0,%xmm5
-       movdqu  80(%esi),%xmm1
-       pxor    %xmm0,%xmm6
-       leal    96(%esi),%esi
-       pxor    (%esp),%xmm2
-       movdqa  %xmm7,80(%esp)
-       pxor    %xmm1,%xmm7
-       movups  16(%ebp),%xmm1
-       leal    32(%ebp),%edx
-       pxor    16(%esp),%xmm3
-.byte  102,15,56,222,209
-       pxor    32(%esp),%xmm4
-.byte  102,15,56,222,217
-       pxor    48(%esp),%xmm5
-       decl    %ecx
-.byte  102,15,56,222,225
-       pxor    64(%esp),%xmm6
-.byte  102,15,56,222,233
-       pxor    %xmm0,%xmm7
-.byte  102,15,56,222,241
-       movups  (%edx),%xmm0
-.byte  102,15,56,222,249
-       call    .L_aesni_decrypt6_enter
-       movdqa  80(%esp),%xmm1
-       pxor    %xmm0,%xmm0
-       xorps   (%esp),%xmm2
-       pcmpgtd %xmm1,%xmm0
-       xorps   16(%esp),%xmm3
-       movups  %xmm2,(%edi)
-       xorps   32(%esp),%xmm4
-       movups  %xmm3,16(%edi)
-       xorps   48(%esp),%xmm5
-       movups  %xmm4,32(%edi)
-       xorps   64(%esp),%xmm6
-       movups  %xmm5,48(%edi)
-       xorps   %xmm1,%xmm7
-       movups  %xmm6,64(%edi)
-       pshufd  $19,%xmm0,%xmm2
-       movups  %xmm7,80(%edi)
-       leal    96(%edi),%edi
-       movdqa  96(%esp),%xmm3
-       pxor    %xmm0,%xmm0
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       movl    %ebx,%ecx
-       pxor    %xmm2,%xmm1
-       subl    $96,%eax
-       jnc     .L057xts_dec_loop6
-       leal    1(,%ecx,2),%ecx
-       movl    %ebp,%edx
-       movl    %ecx,%ebx
-.L056xts_dec_short:
-       addl    $96,%eax
-       jz      .L058xts_dec_done6x
-       movdqa  %xmm1,%xmm5
-       cmpl    $32,%eax
-       jb      .L059xts_dec_one
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       je      .L060xts_dec_two
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  %xmm1,%xmm6
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       cmpl    $64,%eax
-       jb      .L061xts_dec_three
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  %xmm1,%xmm7
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-       movdqa  %xmm5,(%esp)
-       movdqa  %xmm6,16(%esp)
-       je      .L062xts_dec_four
-       movdqa  %xmm7,32(%esp)
-       pshufd  $19,%xmm0,%xmm7
-       movdqa  %xmm1,48(%esp)
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm7
-       pxor    %xmm1,%xmm7
-       movdqu  (%esi),%xmm2
-       movdqu  16(%esi),%xmm3
-       movdqu  32(%esi),%xmm4
-       pxor    (%esp),%xmm2
-       movdqu  48(%esi),%xmm5
-       pxor    16(%esp),%xmm3
-       movdqu  64(%esi),%xmm6
-       pxor    32(%esp),%xmm4
-       leal    80(%esi),%esi
-       pxor    48(%esp),%xmm5
-       movdqa  %xmm7,64(%esp)
-       pxor    %xmm7,%xmm6
-       call    _aesni_decrypt6
-       movaps  64(%esp),%xmm1
-       xorps   (%esp),%xmm2
-       xorps   16(%esp),%xmm3
-       xorps   32(%esp),%xmm4
-       movups  %xmm2,(%edi)
-       xorps   48(%esp),%xmm5
-       movups  %xmm3,16(%edi)
-       xorps   %xmm1,%xmm6
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-       movups  %xmm6,64(%edi)
-       leal    80(%edi),%edi
-       jmp     .L063xts_dec_done
-.align 16
-.L059xts_dec_one:
-       movups  (%esi),%xmm2
-       leal    16(%esi),%esi
-       xorps   %xmm5,%xmm2
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L064dec1_loop_12:
-.byte  102,15,56,222,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L064dec1_loop_12
-.byte  102,15,56,223,209
-       xorps   %xmm5,%xmm2
-       movups  %xmm2,(%edi)
-       leal    16(%edi),%edi
-       movdqa  %xmm5,%xmm1
-       jmp     .L063xts_dec_done
-.align 16
-.L060xts_dec_two:
-       movaps  %xmm1,%xmm6
-       movups  (%esi),%xmm2
-       movups  16(%esi),%xmm3
-       leal    32(%esi),%esi
-       xorps   %xmm5,%xmm2
-       xorps   %xmm6,%xmm3
-       call    _aesni_decrypt3
-       xorps   %xmm5,%xmm2
-       xorps   %xmm6,%xmm3
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       leal    32(%edi),%edi
-       movdqa  %xmm6,%xmm1
-       jmp     .L063xts_dec_done
-.align 16
-.L061xts_dec_three:
-       movaps  %xmm1,%xmm7
-       movups  (%esi),%xmm2
-       movups  16(%esi),%xmm3
-       movups  32(%esi),%xmm4
-       leal    48(%esi),%esi
-       xorps   %xmm5,%xmm2
-       xorps   %xmm6,%xmm3
-       xorps   %xmm7,%xmm4
-       call    _aesni_decrypt3
-       xorps   %xmm5,%xmm2
-       xorps   %xmm6,%xmm3
-       xorps   %xmm7,%xmm4
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       leal    48(%edi),%edi
-       movdqa  %xmm7,%xmm1
-       jmp     .L063xts_dec_done
-.align 16
-.L062xts_dec_four:
-       movaps  %xmm1,%xmm6
-       movups  (%esi),%xmm2
-       movups  16(%esi),%xmm3
-       movups  32(%esi),%xmm4
-       xorps   (%esp),%xmm2
-       movups  48(%esi),%xmm5
-       leal    64(%esi),%esi
-       xorps   16(%esp),%xmm3
-       xorps   %xmm7,%xmm4
-       xorps   %xmm6,%xmm5
-       call    _aesni_decrypt4
-       xorps   (%esp),%xmm2
-       xorps   16(%esp),%xmm3
-       xorps   %xmm7,%xmm4
-       movups  %xmm2,(%edi)
-       xorps   %xmm6,%xmm5
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-       leal    64(%edi),%edi
-       movdqa  %xmm6,%xmm1
-       jmp     .L063xts_dec_done
-.align 16
-.L058xts_dec_done6x:
-       movl    112(%esp),%eax
-       andl    $15,%eax
-       jz      .L065xts_dec_ret
-       movl    %eax,112(%esp)
-       jmp     .L066xts_dec_only_one_more
-.align 16
-.L063xts_dec_done:
-       movl    112(%esp),%eax
-       pxor    %xmm0,%xmm0
-       andl    $15,%eax
-       jz      .L065xts_dec_ret
-       pcmpgtd %xmm1,%xmm0
-       movl    %eax,112(%esp)
-       pshufd  $19,%xmm0,%xmm2
-       pxor    %xmm0,%xmm0
-       movdqa  96(%esp),%xmm3
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm2
-       pcmpgtd %xmm1,%xmm0
-       pxor    %xmm2,%xmm1
-.L066xts_dec_only_one_more:
-       pshufd  $19,%xmm0,%xmm5
-       movdqa  %xmm1,%xmm6
-       paddq   %xmm1,%xmm1
-       pand    %xmm3,%xmm5
-       pxor    %xmm1,%xmm5
-       movl    %ebp,%edx
-       movl    %ebx,%ecx
-       movups  (%esi),%xmm2
-       xorps   %xmm5,%xmm2
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L067dec1_loop_13:
-.byte  102,15,56,222,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L067dec1_loop_13
-.byte  102,15,56,223,209
-       xorps   %xmm5,%xmm2
-       movups  %xmm2,(%edi)
-.L068xts_dec_steal:
-       movzbl  16(%esi),%ecx
-       movzbl  (%edi),%edx
-       leal    1(%esi),%esi
-       movb    %cl,(%edi)
-       movb    %dl,16(%edi)
-       leal    1(%edi),%edi
-       subl    $1,%eax
-       jnz     .L068xts_dec_steal
-       subl    112(%esp),%edi
-       movl    %ebp,%edx
-       movl    %ebx,%ecx
-       movups  (%edi),%xmm2
-       xorps   %xmm6,%xmm2
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L069dec1_loop_14:
-.byte  102,15,56,222,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L069dec1_loop_14
-.byte  102,15,56,223,209
-       xorps   %xmm6,%xmm2
-       movups  %xmm2,(%edi)
-.L065xts_dec_ret:
-       movl    116(%esp),%esp
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-.size  aesni_xts_decrypt,.-.L_aesni_xts_decrypt_begin
-.globl aesni_cbc_encrypt
-.type  aesni_cbc_encrypt,@function
-.align 16
-aesni_cbc_encrypt:
-.L_aesni_cbc_encrypt_begin:
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-       movl    20(%esp),%esi
-       movl    %esp,%ebx
-       movl    24(%esp),%edi
-       subl    $24,%ebx
-       movl    28(%esp),%eax
-       andl    $-16,%ebx
-       movl    32(%esp),%edx
-       movl    36(%esp),%ebp
-       testl   %eax,%eax
-       jz      .L070cbc_abort
-       cmpl    $0,40(%esp)
-       xchgl   %esp,%ebx
-       movups  (%ebp),%xmm7
-       movl    240(%edx),%ecx
-       movl    %edx,%ebp
-       movl    %ebx,16(%esp)
-       movl    %ecx,%ebx
-       je      .L071cbc_decrypt
-       movaps  %xmm7,%xmm2
-       cmpl    $16,%eax
-       jb      .L072cbc_enc_tail
-       subl    $16,%eax
-       jmp     .L073cbc_enc_loop
-.align 16
-.L073cbc_enc_loop:
-       movups  (%esi),%xmm7
-       leal    16(%esi),%esi
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       xorps   %xmm0,%xmm7
-       leal    32(%edx),%edx
-       xorps   %xmm7,%xmm2
-.L074enc1_loop_15:
-.byte  102,15,56,220,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L074enc1_loop_15
-.byte  102,15,56,221,209
-       movl    %ebx,%ecx
-       movl    %ebp,%edx
-       movups  %xmm2,(%edi)
-       leal    16(%edi),%edi
-       subl    $16,%eax
-       jnc     .L073cbc_enc_loop
-       addl    $16,%eax
-       jnz     .L072cbc_enc_tail
-       movaps  %xmm2,%xmm7
-       jmp     .L075cbc_ret
-.L072cbc_enc_tail:
-       movl    %eax,%ecx
-.long  2767451785
-       movl    $16,%ecx
-       subl    %eax,%ecx
-       xorl    %eax,%eax
-.long  2868115081
-       leal    -16(%edi),%edi
-       movl    %ebx,%ecx
-       movl    %edi,%esi
-       movl    %ebp,%edx
-       jmp     .L073cbc_enc_loop
-.align 16
-.L071cbc_decrypt:
-       cmpl    $80,%eax
-       jbe     .L076cbc_dec_tail
-       movaps  %xmm7,(%esp)
-       subl    $80,%eax
-       jmp     .L077cbc_dec_loop6_enter
-.align 16
-.L078cbc_dec_loop6:
-       movaps  %xmm0,(%esp)
-       movups  %xmm7,(%edi)
-       leal    16(%edi),%edi
-.L077cbc_dec_loop6_enter:
-       movdqu  (%esi),%xmm2
-       movdqu  16(%esi),%xmm3
-       movdqu  32(%esi),%xmm4
-       movdqu  48(%esi),%xmm5
-       movdqu  64(%esi),%xmm6
-       movdqu  80(%esi),%xmm7
-       call    _aesni_decrypt6
-       movups  (%esi),%xmm1
-       movups  16(%esi),%xmm0
-       xorps   (%esp),%xmm2
-       xorps   %xmm1,%xmm3
-       movups  32(%esi),%xmm1
-       xorps   %xmm0,%xmm4
-       movups  48(%esi),%xmm0
-       xorps   %xmm1,%xmm5
-       movups  64(%esi),%xmm1
-       xorps   %xmm0,%xmm6
-       movups  80(%esi),%xmm0
-       xorps   %xmm1,%xmm7
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       leal    96(%esi),%esi
-       movups  %xmm4,32(%edi)
-       movl    %ebx,%ecx
-       movups  %xmm5,48(%edi)
-       movl    %ebp,%edx
-       movups  %xmm6,64(%edi)
-       leal    80(%edi),%edi
-       subl    $96,%eax
-       ja      .L078cbc_dec_loop6
-       movaps  %xmm7,%xmm2
-       movaps  %xmm0,%xmm7
-       addl    $80,%eax
-       jle     .L079cbc_dec_tail_collected
-       movups  %xmm2,(%edi)
-       leal    16(%edi),%edi
-.L076cbc_dec_tail:
-       movups  (%esi),%xmm2
-       movaps  %xmm2,%xmm6
-       cmpl    $16,%eax
-       jbe     .L080cbc_dec_one
-       movups  16(%esi),%xmm3
-       movaps  %xmm3,%xmm5
-       cmpl    $32,%eax
-       jbe     .L081cbc_dec_two
-       movups  32(%esi),%xmm4
-       cmpl    $48,%eax
-       jbe     .L082cbc_dec_three
-       movups  48(%esi),%xmm5
-       cmpl    $64,%eax
-       jbe     .L083cbc_dec_four
-       movups  64(%esi),%xmm6
-       movaps  %xmm7,(%esp)
-       movups  (%esi),%xmm2
-       xorps   %xmm7,%xmm7
-       call    _aesni_decrypt6
-       movups  (%esi),%xmm1
-       movups  16(%esi),%xmm0
-       xorps   (%esp),%xmm2
-       xorps   %xmm1,%xmm3
-       movups  32(%esi),%xmm1
-       xorps   %xmm0,%xmm4
-       movups  48(%esi),%xmm0
-       xorps   %xmm1,%xmm5
-       movups  64(%esi),%xmm7
-       xorps   %xmm0,%xmm6
-       movups  %xmm2,(%edi)
-       movups  %xmm3,16(%edi)
-       movups  %xmm4,32(%edi)
-       movups  %xmm5,48(%edi)
-       leal    64(%edi),%edi
-       movaps  %xmm6,%xmm2
-       subl    $80,%eax
-       jmp     .L079cbc_dec_tail_collected
-.align 16
-.L080cbc_dec_one:
-       movups  (%edx),%xmm0
-       movups  16(%edx),%xmm1
-       leal    32(%edx),%edx
-       xorps   %xmm0,%xmm2
-.L084dec1_loop_16:
-.byte  102,15,56,222,209
-       decl    %ecx
-       movups  (%edx),%xmm1
-       leal    16(%edx),%edx
-       jnz     .L084dec1_loop_16
-.byte  102,15,56,223,209
-       xorps   %xmm7,%xmm2
-       movaps  %xmm6,%xmm7
-       subl    $16,%eax
-       jmp     .L079cbc_dec_tail_collected
-.align 16
-.L081cbc_dec_two:
-       xorps   %xmm4,%xmm4
-       call    _aesni_decrypt3
-       xorps   %xmm7,%xmm2
-       xorps   %xmm6,%xmm3
-       movups  %xmm2,(%edi)
-       movaps  %xmm3,%xmm2
-       leal    16(%edi),%edi
-       movaps  %xmm5,%xmm7
-       subl    $32,%eax
-       jmp     .L079cbc_dec_tail_collected
-.align 16
-.L082cbc_dec_three:
-       call    _aesni_decrypt3
-       xorps   %xmm7,%xmm2
-       xorps   %xmm6,%xmm3
-       xorps   %xmm5,%xmm4
-       movups  %xmm2,(%edi)
-       movaps  %xmm4,%xmm2
-       movups  %xmm3,16(%edi)
-       leal    32(%edi),%edi
-       movups  32(%esi),%xmm7
-       subl    $48,%eax
-       jmp     .L079cbc_dec_tail_collected
-.align 16
-.L083cbc_dec_four:
-       call    _aesni_decrypt4
-       movups  16(%esi),%xmm1
-       movups  32(%esi),%xmm0
-       xorps   %xmm7,%xmm2
-       movups  48(%esi),%xmm7
-       xorps   %xmm6,%xmm3
-       movups  %xmm2,(%edi)
-       xorps   %xmm1,%xmm4
-       movups  %xmm3,16(%edi)
-       xorps   %xmm0,%xmm5
-       movups  %xmm4,32(%edi)
-       leal    48(%edi),%edi
-       movaps  %xmm5,%xmm2
-       subl    $64,%eax
-.L079cbc_dec_tail_collected:
-       andl    $15,%eax
-       jnz     .L085cbc_dec_tail_partial
-       movups  %xmm2,(%edi)
-       jmp     .L075cbc_ret
-.align 16
-.L085cbc_dec_tail_partial:
-       movaps  %xmm2,(%esp)
-       movl    $16,%ecx
-       movl    %esp,%esi
-       subl    %eax,%ecx
-.long  2767451785
-.L075cbc_ret:
-       movl    16(%esp),%esp
-       movl    36(%esp),%ebp
-       movups  %xmm7,(%ebp)
-.L070cbc_abort:
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-.size  aesni_cbc_encrypt,.-.L_aesni_cbc_encrypt_begin
-.type  _aesni_set_encrypt_key,@function
-.align 16
-_aesni_set_encrypt_key:
-       testl   %eax,%eax
-       jz      .L086bad_pointer
-       testl   %edx,%edx
-       jz      .L086bad_pointer
-       movups  (%eax),%xmm0
-       xorps   %xmm4,%xmm4
-       leal    16(%edx),%edx
-       cmpl    $256,%ecx
-       je      .L08714rounds
-       cmpl    $192,%ecx
-       je      .L08812rounds
-       cmpl    $128,%ecx
-       jne     .L089bad_keybits
-.align 16
-.L09010rounds:
-       movl    $9,%ecx
-       movups  %xmm0,-16(%edx)
-.byte  102,15,58,223,200,1
-       call    .L091key_128_cold
-.byte  102,15,58,223,200,2
-       call    .L092key_128
-.byte  102,15,58,223,200,4
-       call    .L092key_128
-.byte  102,15,58,223,200,8
-       call    .L092key_128
-.byte  102,15,58,223,200,16
-       call    .L092key_128
-.byte  102,15,58,223,200,32
-       call    .L092key_128
-.byte  102,15,58,223,200,64
-       call    .L092key_128
-.byte  102,15,58,223,200,128
-       call    .L092key_128
-.byte  102,15,58,223,200,27
-       call    .L092key_128
-.byte  102,15,58,223,200,54
-       call    .L092key_128
-       movups  %xmm0,(%edx)
-       movl    %ecx,80(%edx)
-       xorl    %eax,%eax
-       ret
-.align 16
-.L092key_128:
-       movups  %xmm0,(%edx)
-       leal    16(%edx),%edx
-.L091key_128_cold:
-       shufps  $16,%xmm0,%xmm4
-       xorps   %xmm4,%xmm0
-       shufps  $140,%xmm0,%xmm4
-       xorps   %xmm4,%xmm0
-       shufps  $255,%xmm1,%xmm1
-       xorps   %xmm1,%xmm0
-       ret
-.align 16
-.L08812rounds:
-       movq    16(%eax),%xmm2
-       movl    $11,%ecx
-       movups  %xmm0,-16(%edx)
-.byte  102,15,58,223,202,1
-       call    .L093key_192a_cold
-.byte  102,15,58,223,202,2
-       call    .L094key_192b
-.byte  102,15,58,223,202,4
-       call    .L095key_192a
-.byte  102,15,58,223,202,8
-       call    .L094key_192b
-.byte  102,15,58,223,202,16
-       call    .L095key_192a
-.byte  102,15,58,223,202,32
-       call    .L094key_192b
-.byte  102,15,58,223,202,64
-       call    .L095key_192a
-.byte  102,15,58,223,202,128
-       call    .L094key_192b
-       movups  %xmm0,(%edx)
-       movl    %ecx,48(%edx)
-       xorl    %eax,%eax
-       ret
-.align 16
-.L095key_192a:
-       movups  %xmm0,(%edx)
-       leal    16(%edx),%edx
-.align 16
-.L093key_192a_cold:
-       movaps  %xmm2,%xmm5
-.L096key_192b_warm:
-       shufps  $16,%xmm0,%xmm4
-       movdqa  %xmm2,%xmm3
-       xorps   %xmm4,%xmm0
-       shufps  $140,%xmm0,%xmm4
-       pslldq  $4,%xmm3
-       xorps   %xmm4,%xmm0
-       pshufd  $85,%xmm1,%xmm1
-       pxor    %xmm3,%xmm2
-       pxor    %xmm1,%xmm0
-       pshufd  $255,%xmm0,%xmm3
-       pxor    %xmm3,%xmm2
-       ret
-.align 16
-.L094key_192b:
-       movaps  %xmm0,%xmm3
-       shufps  $68,%xmm0,%xmm5
-       movups  %xmm5,(%edx)
-       shufps  $78,%xmm2,%xmm3
-       movups  %xmm3,16(%edx)
-       leal    32(%edx),%edx
-       jmp     .L096key_192b_warm
-.align 16
-.L08714rounds:
-       movups  16(%eax),%xmm2
-       movl    $13,%ecx
-       leal    16(%edx),%edx
-       movups  %xmm0,-32(%edx)
-       movups  %xmm2,-16(%edx)
-.byte  102,15,58,223,202,1
-       call    .L097key_256a_cold
-.byte  102,15,58,223,200,1
-       call    .L098key_256b
-.byte  102,15,58,223,202,2
-       call    .L099key_256a
-.byte  102,15,58,223,200,2
-       call    .L098key_256b
-.byte  102,15,58,223,202,4
-       call    .L099key_256a
-.byte  102,15,58,223,200,4
-       call    .L098key_256b
-.byte  102,15,58,223,202,8
-       call    .L099key_256a
-.byte  102,15,58,223,200,8
-       call    .L098key_256b
-.byte  102,15,58,223,202,16
-       call    .L099key_256a
-.byte  102,15,58,223,200,16
-       call    .L098key_256b
-.byte  102,15,58,223,202,32
-       call    .L099key_256a
-.byte  102,15,58,223,200,32
-       call    .L098key_256b
-.byte  102,15,58,223,202,64
-       call    .L099key_256a
-       movups  %xmm0,(%edx)
-       movl    %ecx,16(%edx)
-       xorl    %eax,%eax
-       ret
-.align 16
-.L099key_256a:
-       movups  %xmm2,(%edx)
-       leal    16(%edx),%edx
-.L097key_256a_cold:
-       shufps  $16,%xmm0,%xmm4
-       xorps   %xmm4,%xmm0
-       shufps  $140,%xmm0,%xmm4
-       xorps   %xmm4,%xmm0
-       shufps  $255,%xmm1,%xmm1
-       xorps   %xmm1,%xmm0
-       ret
-.align 16
-.L098key_256b:
-       movups  %xmm0,(%edx)
-       leal    16(%edx),%edx
-       shufps  $16,%xmm2,%xmm4
-       xorps   %xmm4,%xmm2
-       shufps  $140,%xmm2,%xmm4
-       xorps   %xmm4,%xmm2
-       shufps  $170,%xmm1,%xmm1
-       xorps   %xmm1,%xmm2
-       ret
-.align 4
-.L086bad_pointer:
-       movl    $-1,%eax
-       ret
-.align 4
-.L089bad_keybits:
-       movl    $-2,%eax
-       ret
-.size  _aesni_set_encrypt_key,.-_aesni_set_encrypt_key
-.globl aesni_set_encrypt_key
-.type  aesni_set_encrypt_key,@function
-.align 16
-aesni_set_encrypt_key:
-.L_aesni_set_encrypt_key_begin:
-       movl    4(%esp),%eax
-       movl    8(%esp),%ecx
-       movl    12(%esp),%edx
-       call    _aesni_set_encrypt_key
-       ret
-.size  aesni_set_encrypt_key,.-.L_aesni_set_encrypt_key_begin
-.globl aesni_set_decrypt_key
-.type  aesni_set_decrypt_key,@function
-.align 16
-aesni_set_decrypt_key:
-.L_aesni_set_decrypt_key_begin:
-       movl    4(%esp),%eax
-       movl    8(%esp),%ecx
-       movl    12(%esp),%edx
-       call    _aesni_set_encrypt_key
-       movl    12(%esp),%edx
-       shll    $4,%ecx
-       testl   %eax,%eax
-       jnz     .L100dec_key_ret
-       leal    16(%edx,%ecx,1),%eax
-       movups  (%edx),%xmm0
-       movups  (%eax),%xmm1
-       movups  %xmm0,(%eax)
-       movups  %xmm1,(%edx)
-       leal    16(%edx),%edx
-       leal    -16(%eax),%eax
-.L101dec_key_inverse:
-       movups  (%edx),%xmm0
-       movups  (%eax),%xmm1
-.byte  102,15,56,219,192
-.byte  102,15,56,219,201
-       leal    16(%edx),%edx
-       leal    -16(%eax),%eax
-       movups  %xmm0,16(%eax)
-       movups  %xmm1,-16(%edx)
-       cmpl    %edx,%eax
-       ja      .L101dec_key_inverse
-       movups  (%edx),%xmm0
-.byte  102,15,56,219,192
-       movups  %xmm0,(%edx)
-       xorl    %eax,%eax
-.L100dec_key_ret:
-       ret
-.size  aesni_set_decrypt_key,.-.L_aesni_set_decrypt_key_begin
-.byte  65,69,83,32,102,111,114,32,73,110,116,101,108,32,65,69
-.byte  83,45,78,73,44,32,67,82,89,80,84,79,71,65,77,83
-.byte  32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115
-.byte  115,108,46,111,114,103,62,0
-
-#if defined(__linux__) && defined(__ELF__)
-.section .note.GNU-stack,"",%progbits
-#endif
-
diff --git a/lib/accelerated/intel/asm/cpuid-x86-64.s 
b/lib/accelerated/intel/asm/cpuid-x86-64.s
deleted file mode 100644
index 48b2cc4..0000000
--- a/lib/accelerated/intel/asm/cpuid-x86-64.s
+++ /dev/null
@@ -1,39 +0,0 @@
-       .file "cpuid.asm"
-        
-       .text
-       .align 16
-.globl _gnutls_cpuid
-.type _gnutls_cpuid,%function
-_gnutls_cpuid:
-       pushq   %rbp
-       movq    %rsp, %rbp
-       pushq   %rbx
-       movl    %edi, -12(%rbp)
-       movq    %rsi, -24(%rbp)
-       movq    %rdx, -32(%rbp)
-       movq    %rcx, -40(%rbp)
-       movq    %r8, -48(%rbp)
-       movl    -12(%rbp), %eax
-       movl    %eax, -60(%rbp)
-       movl    -60(%rbp), %eax
-       cpuid
-       movl    %edx, -56(%rbp)
-       movl    %ecx, %esi
-       movl    %eax, -52(%rbp)
-       movq    -24(%rbp), %rax
-       movl    -52(%rbp), %edx
-       movl    %edx, (%rax)
-       movq    -32(%rbp), %rax
-       movl    %ebx, (%rax)
-       movq    -40(%rbp), %rax
-       movl    %esi, (%rax)
-       movq    -48(%rbp), %rax
-       movl    -56(%rbp), %ecx
-       movl    %ecx, (%rax)
-       popq    %rbx
-       leave
-       ret
-.size _gnutls_cpuid, . - _gnutls_cpuid
-
-
-.section .note.GNU-stack,"",@progbits
diff --git a/lib/accelerated/intel/asm/cpuid-x86.s 
b/lib/accelerated/intel/asm/cpuid-x86.s
deleted file mode 100644
index b286225..0000000
--- a/lib/accelerated/intel/asm/cpuid-x86.s
+++ /dev/null
@@ -1,54 +0,0 @@
-       .file "cpuid.asm"
-        
-       .text
-       .align 16
-.globl _gnutls_cpuid
-.type _gnutls_cpuid,%function
-_gnutls_cpuid:
-       pushl   %ebp
-       movl    %esp, %ebp
-       subl    $12, %esp
-       movl    %ebx, (%esp)
-       movl    8(%ebp), %eax
-       movl    %esi, 4(%esp)
-       movl    %edi, 8(%esp)
-       pushl %ebx
-       cpuid
-       movl %ebx, %edi
-       popl %ebx
-       movl    %edx, %esi
-       movl    12(%ebp), %edx
-       movl    %eax, (%edx)
-       movl    16(%ebp), %eax
-       movl    %edi, (%eax)
-       movl    20(%ebp), %eax
-       movl    %ecx, (%eax)
-       movl    24(%ebp), %eax
-       movl    %esi, (%eax)
-       movl    (%esp), %ebx
-       movl    4(%esp), %esi
-       movl    8(%esp), %edi
-       movl    %ebp, %esp
-       popl    %ebp
-       ret
-.size _gnutls_cpuid, . - _gnutls_cpuid
-
-       .globl  _gnutls_have_cpuid
-       .type   _gnutls_have_cpuid, @function
-_gnutls_have_cpuid:
-.LFB0:
-       .cfi_startproc
-       pushfl  
-       pop %eax        
-       orl $0x200000, %eax     
-       push %eax       
-       popfl   
-       pushfl  
-       pop %eax        
-       andl $0x200000, %eax    
-       ret
-       .cfi_endproc
-.LFE0:
-       .size   _gnutls_have_cpuid, .-_gnutls_have_cpuid
-
-.section .note.GNU-stack,"",@progbits
diff --git a/lib/accelerated/intel/asm/padlock-x86-64.s 
b/lib/accelerated/intel/asm/padlock-x86-64.s
deleted file mode 100644
index ebca3ae..0000000
--- a/lib/accelerated/intel/asm/padlock-x86-64.s
+++ /dev/null
@@ -1,723 +0,0 @@
-# Copyright (c) 2011, Andy Polyakov by <address@hidden>
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 
-#     * Redistributions of source code must retain copyright notices,
-#      this list of conditions and the following disclaimer.
-#
-#     * Redistributions in binary form must reproduce the above
-#      copyright notice, this list of conditions and the following
-#      disclaimer in the documentation and/or other materials
-#      provided with the distribution.
-#
-#     * Neither the name of the Andy Polyakov nor the names of its
-#      copyright holder and contributors may be used to endorse or
-#      promote products derived from this software without specific
-#      prior written permission.
-#
-# ALTERNATIVELY, provided that this notice is retained in full, this
-# product may be distributed under the terms of the GNU General Public
-# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
-# those given above.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-.text  
-.globl padlock_capability
-.type  padlock_capability,@function
-.align 16
-padlock_capability:
-       movq    %rbx,%r8
-       xorl    %eax,%eax
-       cpuid
-       xorl    %eax,%eax
-       cmpl    $1953391939,%ebx
-       jne     .Lnoluck
-       cmpl    $1215460705,%edx
-       jne     .Lnoluck
-       cmpl    $1936487777,%ecx
-       jne     .Lnoluck
-       movl    $3221225472,%eax
-       cpuid
-       movl    %eax,%edx
-       xorl    %eax,%eax
-       cmpl    $3221225473,%edx
-       jb      .Lnoluck
-       movl    $3221225473,%eax
-       cpuid
-       movl    %edx,%eax
-       andl    $4294967279,%eax
-       orl     $16,%eax
-.Lnoluck:
-       movq    %r8,%rbx
-       .byte   0xf3,0xc3
-.size  padlock_capability,.-padlock_capability
-
-.globl padlock_key_bswap
-.type  padlock_key_bswap,@function
-.align 16
-padlock_key_bswap:
-       movl    240(%rdi),%edx
-.Lbswap_loop:
-       movl    (%rdi),%eax
-       bswapl  %eax
-       movl    %eax,(%rdi)
-       leaq    4(%rdi),%rdi
-       subl    $1,%edx
-       jnz     .Lbswap_loop
-       .byte   0xf3,0xc3
-.size  padlock_key_bswap,.-padlock_key_bswap
-
-.globl padlock_verify_context
-.type  padlock_verify_context,@function
-.align 16
-padlock_verify_context:
-       movq    %rdi,%rdx
-       pushf
-       leaq    .Lpadlock_saved_context(%rip),%rax
-       call    _padlock_verify_ctx
-       leaq    8(%rsp),%rsp
-       .byte   0xf3,0xc3
-.size  padlock_verify_context,.-padlock_verify_context
-
-.type  _padlock_verify_ctx,@function
-.align 16
-_padlock_verify_ctx:
-       movq    8(%rsp),%r8
-       btq     $30,%r8
-       jnc     .Lverified
-       cmpq    (%rax),%rdx
-       je      .Lverified
-       pushf
-       popf
-.Lverified:
-       movq    %rdx,(%rax)
-       .byte   0xf3,0xc3
-.size  _padlock_verify_ctx,.-_padlock_verify_ctx
-
-.globl padlock_reload_key
-.type  padlock_reload_key,@function
-.align 16
-padlock_reload_key:
-       pushf
-       popf
-       .byte   0xf3,0xc3
-.size  padlock_reload_key,.-padlock_reload_key
-
-.globl padlock_aes_block
-.type  padlock_aes_block,@function
-.align 16
-padlock_aes_block:
-       movq    %rbx,%r8
-       movq    $1,%rcx
-       leaq    32(%rdx),%rbx
-       leaq    16(%rdx),%rdx
-.byte  0xf3,0x0f,0xa7,0xc8     
-       movq    %r8,%rbx
-       .byte   0xf3,0xc3
-.size  padlock_aes_block,.-padlock_aes_block
-
-.globl padlock_xstore
-.type  padlock_xstore,@function
-.align 16
-padlock_xstore:
-       movl    %esi,%edx
-.byte  0x0f,0xa7,0xc0          
-       .byte   0xf3,0xc3
-.size  padlock_xstore,.-padlock_xstore
-
-.globl padlock_sha1_oneshot
-.type  padlock_sha1_oneshot,@function
-.align 16
-padlock_sha1_oneshot:
-       xorq    %rax,%rax
-       movq    %rdx,%rcx
-.byte  0xf3,0x0f,0xa6,0xc8     
-       .byte   0xf3,0xc3
-.size  padlock_sha1_oneshot,.-padlock_sha1_oneshot
-
-.globl padlock_sha1
-.type  padlock_sha1,@function
-.align 16
-padlock_sha1:
-       movq    $-1,%rax
-       movq    %rdx,%rcx
-.byte  0xf3,0x0f,0xa6,0xc8     
-       .byte   0xf3,0xc3
-.size  padlock_sha1,.-padlock_sha1
-
-.globl padlock_sha256_oneshot
-.type  padlock_sha256_oneshot,@function
-.align 16
-padlock_sha256_oneshot:
-       xorq    %rax,%rax
-       movq    %rdx,%rcx
-.byte  0xf3,0x0f,0xa6,0xd0     
-       .byte   0xf3,0xc3
-.size  padlock_sha256_oneshot,.-padlock_sha256_oneshot
-
-.globl padlock_sha256
-.type  padlock_sha256,@function
-.align 16
-padlock_sha256:
-       movq    $-1,%rax
-       movq    %rdx,%rcx
-.byte  0xf3,0x0f,0xa6,0xd0     
-       .byte   0xf3,0xc3
-.size  padlock_sha256,.-padlock_sha256
-.globl padlock_ecb_encrypt
-.type  padlock_ecb_encrypt,@function
-.align 16
-padlock_ecb_encrypt:
-       pushq   %rbp
-       pushq   %rbx
-
-       xorl    %eax,%eax
-       testq   $15,%rdx
-       jnz     .Lecb_abort
-       testq   $15,%rcx
-       jnz     .Lecb_abort
-       leaq    .Lpadlock_saved_context(%rip),%rax
-       pushf
-       cld
-       call    _padlock_verify_ctx
-       leaq    16(%rdx),%rdx
-       xorl    %eax,%eax
-       xorl    %ebx,%ebx
-       testl   $32,(%rdx)
-       testq   $15,%rdi
-       setz    %al
-       testq   $15,%rsi
-       setz    %bl
-       testl   %ebx,%eax
-       jnz     .Lecb_aligned
-       negq    %rax
-       movq    $512,%rbx
-       notq    %rax
-       leaq    (%rsp),%rbp
-       cmpq    %rbx,%rcx
-       cmovcq  %rcx,%rbx
-       andq    %rbx,%rax
-       movq    %rcx,%rbx
-       negq    %rax
-       andq    $512-1,%rbx
-       leaq    (%rax,%rbp,1),%rsp
-       jmp     .Lecb_loop
-.align 16
-.Lecb_loop:
-       movq    %rdi,%r8
-       movq    %rsi,%r9
-       movq    %rcx,%r10
-       movq    %rbx,%rcx
-       movq    %rbx,%r11
-       testq   $15,%rdi
-       cmovnzq %rsp,%rdi
-       testq   $15,%rsi
-       jz      .Lecb_inp_aligned
-       shrq    $3,%rcx
-.byte  0xf3,0x48,0xa5          
-       subq    %rbx,%rdi
-       movq    %rbx,%rcx
-       movq    %rdi,%rsi
-.Lecb_inp_aligned:
-       leaq    -16(%rdx),%rax
-       leaq    16(%rdx),%rbx
-       shrq    $4,%rcx
-.byte  0xf3,0x0f,0xa7,200      
-       movq    %r8,%rdi
-       movq    %r11,%rbx
-       testq   $15,%rdi
-       jz      .Lecb_out_aligned
-       movq    %rbx,%rcx
-       shrq    $3,%rcx
-       leaq    (%rsp),%rsi
-.byte  0xf3,0x48,0xa5          
-       subq    %rbx,%rdi
-.Lecb_out_aligned:
-       movq    %r9,%rsi
-       movq    %r10,%rcx
-       addq    %rbx,%rdi
-       addq    %rbx,%rsi
-       subq    %rbx,%rcx
-       movq    $512,%rbx
-       jnz     .Lecb_loop
-
-       testq   $15,%rdi
-       jz      .Lecb_done
-
-       movq    %rbp,%rcx
-       movq    %rsp,%rdi
-       subq    %rsp,%rcx
-       xorq    %rax,%rax
-       shrq    $3,%rcx
-.byte  0xf3,0x48,0xab          
-.Lecb_done:
-       leaq    (%rbp),%rsp
-       jmp     .Lecb_exit
-
-.align 16
-.Lecb_aligned:
-       leaq    -16(%rdx),%rax
-       leaq    16(%rdx),%rbx
-       shrq    $4,%rcx
-.byte  0xf3,0x0f,0xa7,200      
-.Lecb_exit:
-       movl    $1,%eax
-       leaq    8(%rsp),%rsp
-.Lecb_abort:
-       popq    %rbx
-       popq    %rbp
-       .byte   0xf3,0xc3
-.size  padlock_ecb_encrypt,.-padlock_ecb_encrypt
-.globl padlock_cbc_encrypt
-.type  padlock_cbc_encrypt,@function
-.align 16
-padlock_cbc_encrypt:
-       pushq   %rbp
-       pushq   %rbx
-
-       xorl    %eax,%eax
-       testq   $15,%rdx
-       jnz     .Lcbc_abort
-       testq   $15,%rcx
-       jnz     .Lcbc_abort
-       leaq    .Lpadlock_saved_context(%rip),%rax
-       pushf
-       cld
-       call    _padlock_verify_ctx
-       leaq    16(%rdx),%rdx
-       xorl    %eax,%eax
-       xorl    %ebx,%ebx
-       testl   $32,(%rdx)
-       testq   $15,%rdi
-       setz    %al
-       testq   $15,%rsi
-       setz    %bl
-       testl   %ebx,%eax
-       jnz     .Lcbc_aligned
-       negq    %rax
-       movq    $512,%rbx
-       notq    %rax
-       leaq    (%rsp),%rbp
-       cmpq    %rbx,%rcx
-       cmovcq  %rcx,%rbx
-       andq    %rbx,%rax
-       movq    %rcx,%rbx
-       negq    %rax
-       andq    $512-1,%rbx
-       leaq    (%rax,%rbp,1),%rsp
-       jmp     .Lcbc_loop
-.align 16
-.Lcbc_loop:
-       movq    %rdi,%r8
-       movq    %rsi,%r9
-       movq    %rcx,%r10
-       movq    %rbx,%rcx
-       movq    %rbx,%r11
-       testq   $15,%rdi
-       cmovnzq %rsp,%rdi
-       testq   $15,%rsi
-       jz      .Lcbc_inp_aligned
-       shrq    $3,%rcx
-.byte  0xf3,0x48,0xa5          
-       subq    %rbx,%rdi
-       movq    %rbx,%rcx
-       movq    %rdi,%rsi
-.Lcbc_inp_aligned:
-       leaq    -16(%rdx),%rax
-       leaq    16(%rdx),%rbx
-       shrq    $4,%rcx
-.byte  0xf3,0x0f,0xa7,208      
-       movdqa  (%rax),%xmm0
-       movdqa  %xmm0,-16(%rdx)
-       movq    %r8,%rdi
-       movq    %r11,%rbx
-       testq   $15,%rdi
-       jz      .Lcbc_out_aligned
-       movq    %rbx,%rcx
-       shrq    $3,%rcx
-       leaq    (%rsp),%rsi
-.byte  0xf3,0x48,0xa5          
-       subq    %rbx,%rdi
-.Lcbc_out_aligned:
-       movq    %r9,%rsi
-       movq    %r10,%rcx
-       addq    %rbx,%rdi
-       addq    %rbx,%rsi
-       subq    %rbx,%rcx
-       movq    $512,%rbx
-       jnz     .Lcbc_loop
-
-       testq   $15,%rdi
-       jz      .Lcbc_done
-
-       movq    %rbp,%rcx
-       movq    %rsp,%rdi
-       subq    %rsp,%rcx
-       xorq    %rax,%rax
-       shrq    $3,%rcx
-.byte  0xf3,0x48,0xab          
-.Lcbc_done:
-       leaq    (%rbp),%rsp
-       jmp     .Lcbc_exit
-
-.align 16
-.Lcbc_aligned:
-       leaq    -16(%rdx),%rax
-       leaq    16(%rdx),%rbx
-       shrq    $4,%rcx
-.byte  0xf3,0x0f,0xa7,208      
-       movdqa  (%rax),%xmm0
-       movdqa  %xmm0,-16(%rdx)
-.Lcbc_exit:
-       movl    $1,%eax
-       leaq    8(%rsp),%rsp
-.Lcbc_abort:
-       popq    %rbx
-       popq    %rbp
-       .byte   0xf3,0xc3
-.size  padlock_cbc_encrypt,.-padlock_cbc_encrypt
-.globl padlock_cfb_encrypt
-.type  padlock_cfb_encrypt,@function
-.align 16
-padlock_cfb_encrypt:
-       pushq   %rbp
-       pushq   %rbx
-
-       xorl    %eax,%eax
-       testq   $15,%rdx
-       jnz     .Lcfb_abort
-       testq   $15,%rcx
-       jnz     .Lcfb_abort
-       leaq    .Lpadlock_saved_context(%rip),%rax
-       pushf
-       cld
-       call    _padlock_verify_ctx
-       leaq    16(%rdx),%rdx
-       xorl    %eax,%eax
-       xorl    %ebx,%ebx
-       testl   $32,(%rdx)
-       testq   $15,%rdi
-       setz    %al
-       testq   $15,%rsi
-       setz    %bl
-       testl   %ebx,%eax
-       jnz     .Lcfb_aligned
-       negq    %rax
-       movq    $512,%rbx
-       notq    %rax
-       leaq    (%rsp),%rbp
-       cmpq    %rbx,%rcx
-       cmovcq  %rcx,%rbx
-       andq    %rbx,%rax
-       movq    %rcx,%rbx
-       negq    %rax
-       andq    $512-1,%rbx
-       leaq    (%rax,%rbp,1),%rsp
-       jmp     .Lcfb_loop
-.align 16
-.Lcfb_loop:
-       movq    %rdi,%r8
-       movq    %rsi,%r9
-       movq    %rcx,%r10
-       movq    %rbx,%rcx
-       movq    %rbx,%r11
-       testq   $15,%rdi
-       cmovnzq %rsp,%rdi
-       testq   $15,%rsi
-       jz      .Lcfb_inp_aligned
-       shrq    $3,%rcx
-.byte  0xf3,0x48,0xa5          
-       subq    %rbx,%rdi
-       movq    %rbx,%rcx
-       movq    %rdi,%rsi
-.Lcfb_inp_aligned:
-       leaq    -16(%rdx),%rax
-       leaq    16(%rdx),%rbx
-       shrq    $4,%rcx
-.byte  0xf3,0x0f,0xa7,224      
-       movdqa  (%rax),%xmm0
-       movdqa  %xmm0,-16(%rdx)
-       movq    %r8,%rdi
-       movq    %r11,%rbx
-       testq   $15,%rdi
-       jz      .Lcfb_out_aligned
-       movq    %rbx,%rcx
-       shrq    $3,%rcx
-       leaq    (%rsp),%rsi
-.byte  0xf3,0x48,0xa5          
-       subq    %rbx,%rdi
-.Lcfb_out_aligned:
-       movq    %r9,%rsi
-       movq    %r10,%rcx
-       addq    %rbx,%rdi
-       addq    %rbx,%rsi
-       subq    %rbx,%rcx
-       movq    $512,%rbx
-       jnz     .Lcfb_loop
-
-       testq   $15,%rdi
-       jz      .Lcfb_done
-
-       movq    %rbp,%rcx
-       movq    %rsp,%rdi
-       subq    %rsp,%rcx
-       xorq    %rax,%rax
-       shrq    $3,%rcx
-.byte  0xf3,0x48,0xab          
-.Lcfb_done:
-       leaq    (%rbp),%rsp
-       jmp     .Lcfb_exit
-
-.align 16
-.Lcfb_aligned:
-       leaq    -16(%rdx),%rax
-       leaq    16(%rdx),%rbx
-       shrq    $4,%rcx
-.byte  0xf3,0x0f,0xa7,224      
-       movdqa  (%rax),%xmm0
-       movdqa  %xmm0,-16(%rdx)
-.Lcfb_exit:
-       movl    $1,%eax
-       leaq    8(%rsp),%rsp
-.Lcfb_abort:
-       popq    %rbx
-       popq    %rbp
-       .byte   0xf3,0xc3
-.size  padlock_cfb_encrypt,.-padlock_cfb_encrypt
-.globl padlock_ofb_encrypt
-.type  padlock_ofb_encrypt,@function
-.align 16
-padlock_ofb_encrypt:
-       pushq   %rbp
-       pushq   %rbx
-
-       xorl    %eax,%eax
-       testq   $15,%rdx
-       jnz     .Lofb_abort
-       testq   $15,%rcx
-       jnz     .Lofb_abort
-       leaq    .Lpadlock_saved_context(%rip),%rax
-       pushf
-       cld
-       call    _padlock_verify_ctx
-       leaq    16(%rdx),%rdx
-       xorl    %eax,%eax
-       xorl    %ebx,%ebx
-       testl   $32,(%rdx)
-       testq   $15,%rdi
-       setz    %al
-       testq   $15,%rsi
-       setz    %bl
-       testl   %ebx,%eax
-       jnz     .Lofb_aligned
-       negq    %rax
-       movq    $512,%rbx
-       notq    %rax
-       leaq    (%rsp),%rbp
-       cmpq    %rbx,%rcx
-       cmovcq  %rcx,%rbx
-       andq    %rbx,%rax
-       movq    %rcx,%rbx
-       negq    %rax
-       andq    $512-1,%rbx
-       leaq    (%rax,%rbp,1),%rsp
-       jmp     .Lofb_loop
-.align 16
-.Lofb_loop:
-       movq    %rdi,%r8
-       movq    %rsi,%r9
-       movq    %rcx,%r10
-       movq    %rbx,%rcx
-       movq    %rbx,%r11
-       testq   $15,%rdi
-       cmovnzq %rsp,%rdi
-       testq   $15,%rsi
-       jz      .Lofb_inp_aligned
-       shrq    $3,%rcx
-.byte  0xf3,0x48,0xa5          
-       subq    %rbx,%rdi
-       movq    %rbx,%rcx
-       movq    %rdi,%rsi
-.Lofb_inp_aligned:
-       leaq    -16(%rdx),%rax
-       leaq    16(%rdx),%rbx
-       shrq    $4,%rcx
-.byte  0xf3,0x0f,0xa7,232      
-       movdqa  (%rax),%xmm0
-       movdqa  %xmm0,-16(%rdx)
-       movq    %r8,%rdi
-       movq    %r11,%rbx
-       testq   $15,%rdi
-       jz      .Lofb_out_aligned
-       movq    %rbx,%rcx
-       shrq    $3,%rcx
-       leaq    (%rsp),%rsi
-.byte  0xf3,0x48,0xa5          
-       subq    %rbx,%rdi
-.Lofb_out_aligned:
-       movq    %r9,%rsi
-       movq    %r10,%rcx
-       addq    %rbx,%rdi
-       addq    %rbx,%rsi
-       subq    %rbx,%rcx
-       movq    $512,%rbx
-       jnz     .Lofb_loop
-
-       testq   $15,%rdi
-       jz      .Lofb_done
-
-       movq    %rbp,%rcx
-       movq    %rsp,%rdi
-       subq    %rsp,%rcx
-       xorq    %rax,%rax
-       shrq    $3,%rcx
-.byte  0xf3,0x48,0xab          
-.Lofb_done:
-       leaq    (%rbp),%rsp
-       jmp     .Lofb_exit
-
-.align 16
-.Lofb_aligned:
-       leaq    -16(%rdx),%rax
-       leaq    16(%rdx),%rbx
-       shrq    $4,%rcx
-.byte  0xf3,0x0f,0xa7,232      
-       movdqa  (%rax),%xmm0
-       movdqa  %xmm0,-16(%rdx)
-.Lofb_exit:
-       movl    $1,%eax
-       leaq    8(%rsp),%rsp
-.Lofb_abort:
-       popq    %rbx
-       popq    %rbp
-       .byte   0xf3,0xc3
-.size  padlock_ofb_encrypt,.-padlock_ofb_encrypt
-.globl padlock_ctr16_encrypt
-.type  padlock_ctr16_encrypt,@function
-.align 16
-padlock_ctr16_encrypt:
-       pushq   %rbp
-       pushq   %rbx
-
-       xorl    %eax,%eax
-       testq   $15,%rdx
-       jnz     .Lctr16_abort
-       testq   $15,%rcx
-       jnz     .Lctr16_abort
-       leaq    .Lpadlock_saved_context(%rip),%rax
-       pushf
-       cld
-       call    _padlock_verify_ctx
-       leaq    16(%rdx),%rdx
-       xorl    %eax,%eax
-       xorl    %ebx,%ebx
-       testl   $32,(%rdx)
-       testq   $15,%rdi
-       setz    %al
-       testq   $15,%rsi
-       setz    %bl
-       testl   %ebx,%eax
-       jnz     .Lctr16_aligned
-       negq    %rax
-       movq    $512,%rbx
-       notq    %rax
-       leaq    (%rsp),%rbp
-       cmpq    %rbx,%rcx
-       cmovcq  %rcx,%rbx
-       andq    %rbx,%rax
-       movq    %rcx,%rbx
-       negq    %rax
-       andq    $512-1,%rbx
-       leaq    (%rax,%rbp,1),%rsp
-       jmp     .Lctr16_loop
-.align 16
-.Lctr16_loop:
-       movq    %rdi,%r8
-       movq    %rsi,%r9
-       movq    %rcx,%r10
-       movq    %rbx,%rcx
-       movq    %rbx,%r11
-       testq   $15,%rdi
-       cmovnzq %rsp,%rdi
-       testq   $15,%rsi
-       jz      .Lctr16_inp_aligned
-       shrq    $3,%rcx
-.byte  0xf3,0x48,0xa5          
-       subq    %rbx,%rdi
-       movq    %rbx,%rcx
-       movq    %rdi,%rsi
-.Lctr16_inp_aligned:
-       leaq    -16(%rdx),%rax
-       leaq    16(%rdx),%rbx
-       shrq    $4,%rcx
-.byte  0xf3,0x0f,0xa7,216      
-       movq    %r8,%rdi
-       movq    %r11,%rbx
-       testq   $15,%rdi
-       jz      .Lctr16_out_aligned
-       movq    %rbx,%rcx
-       shrq    $3,%rcx
-       leaq    (%rsp),%rsi
-.byte  0xf3,0x48,0xa5          
-       subq    %rbx,%rdi
-.Lctr16_out_aligned:
-       movq    %r9,%rsi
-       movq    %r10,%rcx
-       addq    %rbx,%rdi
-       addq    %rbx,%rsi
-       subq    %rbx,%rcx
-       movq    $512,%rbx
-       jnz     .Lctr16_loop
-
-       testq   $15,%rdi
-       jz      .Lctr16_done
-
-       movq    %rbp,%rcx
-       movq    %rsp,%rdi
-       subq    %rsp,%rcx
-       xorq    %rax,%rax
-       shrq    $3,%rcx
-.byte  0xf3,0x48,0xab          
-.Lctr16_done:
-       leaq    (%rbp),%rsp
-       jmp     .Lctr16_exit
-
-.align 16
-.Lctr16_aligned:
-       leaq    -16(%rdx),%rax
-       leaq    16(%rdx),%rbx
-       shrq    $4,%rcx
-.byte  0xf3,0x0f,0xa7,216      
-.Lctr16_exit:
-       movl    $1,%eax
-       leaq    8(%rsp),%rsp
-.Lctr16_abort:
-       popq    %rbx
-       popq    %rbp
-       .byte   0xf3,0xc3
-.size  padlock_ctr16_encrypt,.-padlock_ctr16_encrypt
-.byte  
86,73,65,32,80,97,100,108,111,99,107,32,120,56,54,95,54,52,32,109,111,100,117,108,101,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
-.align 16
-.data  
-.align 8
-.Lpadlock_saved_context:
-.quad  0
-
-#if defined(__linux__) && defined(__ELF__)
-.section .note.GNU-stack,"",%progbits
-#endif
-
diff --git a/lib/accelerated/intel/asm/padlock-x86.s 
b/lib/accelerated/intel/asm/padlock-x86.s
deleted file mode 100644
index e81c967..0000000
--- a/lib/accelerated/intel/asm/padlock-x86.s
+++ /dev/null
@@ -1,822 +0,0 @@
-# Copyright (c) 2011, Andy Polyakov by <address@hidden>
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 
-#     * Redistributions of source code must retain copyright notices,
-#      this list of conditions and the following disclaimer.
-#
-#     * Redistributions in binary form must reproduce the above
-#      copyright notice, this list of conditions and the following
-#      disclaimer in the documentation and/or other materials
-#      provided with the distribution.
-#
-#     * Neither the name of the Andy Polyakov nor the names of its
-#      copyright holder and contributors may be used to endorse or
-#      promote products derived from this software without specific
-#      prior written permission.
-#
-# ALTERNATIVELY, provided that this notice is retained in full, this
-# product may be distributed under the terms of the GNU General Public
-# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
-# those given above.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-.file  "e_padlock-x86.s"
-.text
-.globl padlock_capability
-.type  padlock_capability,@function
-.align 16
-padlock_capability:
-.L_padlock_capability_begin:
-       pushl   %ebx
-       pushfl
-       popl    %eax
-       movl    %eax,%ecx
-       xorl    $2097152,%eax
-       pushl   %eax
-       popfl
-       pushfl
-       popl    %eax
-       xorl    %eax,%ecx
-       xorl    %eax,%eax
-       btl     $21,%ecx
-       jnc     .L000noluck
-       .byte   0x0f,0xa2
-       xorl    %eax,%eax
-       cmpl    $0x746e6543,%ebx
-       jne     .L000noluck
-       cmpl    $0x48727561,%edx
-       jne     .L000noluck
-       cmpl    $0x736c7561,%ecx
-       jne     .L000noluck
-       movl    $3221225472,%eax
-       .byte   0x0f,0xa2
-       movl    %eax,%edx
-       xorl    %eax,%eax
-       cmpl    $3221225473,%edx
-       jb      .L000noluck
-       movl    $1,%eax
-       .byte   0x0f,0xa2
-       orl     $15,%eax
-       xorl    %ebx,%ebx
-       andl    $4095,%eax
-       cmpl    $1791,%eax
-       sete    %bl
-       movl    $3221225473,%eax
-       pushl   %ebx
-       .byte   0x0f,0xa2
-       popl    %ebx
-       movl    %edx,%eax
-       shll    $4,%ebx
-       andl    $4294967279,%eax
-       orl     %ebx,%eax
-.L000noluck:
-       popl    %ebx
-       ret
-.size  padlock_capability,.-.L_padlock_capability_begin
-.globl padlock_key_bswap
-.type  padlock_key_bswap,@function
-.align 16
-padlock_key_bswap:
-.L_padlock_key_bswap_begin:
-       movl    4(%esp),%edx
-       movl    240(%edx),%ecx
-.L001bswap_loop:
-       movl    (%edx),%eax
-       bswap   %eax
-       movl    %eax,(%edx)
-       leal    4(%edx),%edx
-       subl    $1,%ecx
-       jnz     .L001bswap_loop
-       ret
-.size  padlock_key_bswap,.-.L_padlock_key_bswap_begin
-.globl padlock_verify_context
-.type  padlock_verify_context,@function
-.align 16
-padlock_verify_context:
-.L_padlock_verify_context_begin:
-       movl    4(%esp),%edx
-       leal    .Lpadlock_saved_context-.L002verify_pic_point,%eax
-       pushfl
-       call    _padlock_verify_ctx
-.L002verify_pic_point:
-       leal    4(%esp),%esp
-       ret
-.size  padlock_verify_context,.-.L_padlock_verify_context_begin
-.type  _padlock_verify_ctx,@function
-.align 16
-_padlock_verify_ctx:
-       addl    (%esp),%eax
-       btl     $30,4(%esp)
-       jnc     .L003verified
-       cmpl    (%eax),%edx
-       je      .L003verified
-       pushfl
-       popfl
-.L003verified:
-       movl    %edx,(%eax)
-       ret
-.size  _padlock_verify_ctx,.-_padlock_verify_ctx
-.globl padlock_reload_key
-.type  padlock_reload_key,@function
-.align 16
-padlock_reload_key:
-.L_padlock_reload_key_begin:
-       pushfl
-       popfl
-       ret
-.size  padlock_reload_key,.-.L_padlock_reload_key_begin
-.globl padlock_aes_block
-.type  padlock_aes_block,@function
-.align 16
-padlock_aes_block:
-.L_padlock_aes_block_begin:
-       pushl   %edi
-       pushl   %esi
-       pushl   %ebx
-       movl    16(%esp),%edi
-       movl    20(%esp),%esi
-       movl    24(%esp),%edx
-       movl    $1,%ecx
-       leal    32(%edx),%ebx
-       leal    16(%edx),%edx
-.byte  243,15,167,200
-       popl    %ebx
-       popl    %esi
-       popl    %edi
-       ret
-.size  padlock_aes_block,.-.L_padlock_aes_block_begin
-.globl padlock_ecb_encrypt
-.type  padlock_ecb_encrypt,@function
-.align 16
-padlock_ecb_encrypt:
-.L_padlock_ecb_encrypt_begin:
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-       movl    20(%esp),%edi
-       movl    24(%esp),%esi
-       movl    28(%esp),%edx
-       movl    32(%esp),%ecx
-       testl   $15,%edx
-       jnz     .L004ecb_abort
-       testl   $15,%ecx
-       jnz     .L004ecb_abort
-       leal    .Lpadlock_saved_context-.L005ecb_pic_point,%eax
-       pushfl
-       cld
-       call    _padlock_verify_ctx
-.L005ecb_pic_point:
-       leal    16(%edx),%edx
-       xorl    %eax,%eax
-       xorl    %ebx,%ebx
-       testl   $32,(%edx)
-       jnz     .L006ecb_aligned
-       testl   $15,%edi
-       setz    %al
-       testl   $15,%esi
-       setz    %bl
-       testl   %ebx,%eax
-       jnz     .L006ecb_aligned
-       negl    %eax
-       movl    $512,%ebx
-       notl    %eax
-       leal    -24(%esp),%ebp
-       cmpl    %ebx,%ecx
-       cmovcl  %ecx,%ebx
-       andl    %ebx,%eax
-       movl    %ecx,%ebx
-       negl    %eax
-       andl    $511,%ebx
-       leal    (%eax,%ebp,1),%esp
-       andl    $-16,%esp
-       jmp     .L007ecb_loop
-.align 16
-.L007ecb_loop:
-       movl    %edi,(%ebp)
-       movl    %esi,4(%ebp)
-       movl    %ecx,8(%ebp)
-       movl    %ebx,%ecx
-       movl    %ebx,12(%ebp)
-       testl   $15,%edi
-       cmovnzl %esp,%edi
-       testl   $15,%esi
-       jz      .L008ecb_inp_aligned
-       shrl    $2,%ecx
-.byte  243,165
-       subl    %ebx,%edi
-       movl    %ebx,%ecx
-       movl    %edi,%esi
-.L008ecb_inp_aligned:
-       leal    -16(%edx),%eax
-       leal    16(%edx),%ebx
-       shrl    $4,%ecx
-.byte  243,15,167,200
-       movl    (%ebp),%edi
-       movl    12(%ebp),%ebx
-       testl   $15,%edi
-       jz      .L009ecb_out_aligned
-       movl    %ebx,%ecx
-       shrl    $2,%ecx
-       leal    (%esp),%esi
-.byte  243,165
-       subl    %ebx,%edi
-.L009ecb_out_aligned:
-       movl    4(%ebp),%esi
-       movl    8(%ebp),%ecx
-       addl    %ebx,%edi
-       addl    %ebx,%esi
-       subl    %ebx,%ecx
-       movl    $512,%ebx
-       jnz     .L007ecb_loop
-       testl   $15,%edi
-       jz      .L010ecb_done
-       movl    %ebp,%ecx
-       movl    %esp,%edi
-       subl    %esp,%ecx
-       xorl    %eax,%eax
-       shrl    $2,%ecx
-.byte  243,171
-.L010ecb_done:
-       leal    24(%ebp),%esp
-       jmp     .L011ecb_exit
-.align 16
-.L006ecb_aligned:
-       leal    -16(%edx),%eax
-       leal    16(%edx),%ebx
-       shrl    $4,%ecx
-.byte  243,15,167,200
-.L011ecb_exit:
-       movl    $1,%eax
-       leal    4(%esp),%esp
-.L004ecb_abort:
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-.size  padlock_ecb_encrypt,.-.L_padlock_ecb_encrypt_begin
-.globl padlock_cbc_encrypt
-.type  padlock_cbc_encrypt,@function
-.align 16
-padlock_cbc_encrypt:
-.L_padlock_cbc_encrypt_begin:
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-       movl    20(%esp),%edi
-       movl    24(%esp),%esi
-       movl    28(%esp),%edx
-       movl    32(%esp),%ecx
-       testl   $15,%edx
-       jnz     .L012cbc_abort
-       testl   $15,%ecx
-       jnz     .L012cbc_abort
-       leal    .Lpadlock_saved_context-.L013cbc_pic_point,%eax
-       pushfl
-       cld
-       call    _padlock_verify_ctx
-.L013cbc_pic_point:
-       leal    16(%edx),%edx
-       xorl    %eax,%eax
-       xorl    %ebx,%ebx
-       testl   $32,(%edx)
-       jnz     .L014cbc_aligned
-       testl   $15,%edi
-       setz    %al
-       testl   $15,%esi
-       setz    %bl
-       testl   %ebx,%eax
-       jnz     .L014cbc_aligned
-       negl    %eax
-       movl    $512,%ebx
-       notl    %eax
-       leal    -24(%esp),%ebp
-       cmpl    %ebx,%ecx
-       cmovcl  %ecx,%ebx
-       andl    %ebx,%eax
-       movl    %ecx,%ebx
-       negl    %eax
-       andl    $511,%ebx
-       leal    (%eax,%ebp,1),%esp
-       andl    $-16,%esp
-       jmp     .L015cbc_loop
-.align 16
-.L015cbc_loop:
-       movl    %edi,(%ebp)
-       movl    %esi,4(%ebp)
-       movl    %ecx,8(%ebp)
-       movl    %ebx,%ecx
-       movl    %ebx,12(%ebp)
-       testl   $15,%edi
-       cmovnzl %esp,%edi
-       testl   $15,%esi
-       jz      .L016cbc_inp_aligned
-       shrl    $2,%ecx
-.byte  243,165
-       subl    %ebx,%edi
-       movl    %ebx,%ecx
-       movl    %edi,%esi
-.L016cbc_inp_aligned:
-       leal    -16(%edx),%eax
-       leal    16(%edx),%ebx
-       shrl    $4,%ecx
-.byte  243,15,167,208
-       movdqa  (%eax),%xmm0
-       movdqa  %xmm0,-16(%edx)
-       movl    (%ebp),%edi
-       movl    12(%ebp),%ebx
-       testl   $15,%edi
-       jz      .L017cbc_out_aligned
-       movl    %ebx,%ecx
-       shrl    $2,%ecx
-       leal    (%esp),%esi
-.byte  243,165
-       subl    %ebx,%edi
-.L017cbc_out_aligned:
-       movl    4(%ebp),%esi
-       movl    8(%ebp),%ecx
-       addl    %ebx,%edi
-       addl    %ebx,%esi
-       subl    %ebx,%ecx
-       movl    $512,%ebx
-       jnz     .L015cbc_loop
-       testl   $15,%edi
-       jz      .L018cbc_done
-       movl    %ebp,%ecx
-       movl    %esp,%edi
-       subl    %esp,%ecx
-       xorl    %eax,%eax
-       shrl    $2,%ecx
-.byte  243,171
-.L018cbc_done:
-       leal    24(%ebp),%esp
-       jmp     .L019cbc_exit
-.align 16
-.L014cbc_aligned:
-       leal    -16(%edx),%eax
-       leal    16(%edx),%ebx
-       shrl    $4,%ecx
-.byte  243,15,167,208
-       movdqa  (%eax),%xmm0
-       movdqa  %xmm0,-16(%edx)
-.L019cbc_exit:
-       movl    $1,%eax
-       leal    4(%esp),%esp
-.L012cbc_abort:
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-.size  padlock_cbc_encrypt,.-.L_padlock_cbc_encrypt_begin
-.globl padlock_cfb_encrypt
-.type  padlock_cfb_encrypt,@function
-.align 16
-padlock_cfb_encrypt:
-.L_padlock_cfb_encrypt_begin:
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-       movl    20(%esp),%edi
-       movl    24(%esp),%esi
-       movl    28(%esp),%edx
-       movl    32(%esp),%ecx
-       testl   $15,%edx
-       jnz     .L020cfb_abort
-       testl   $15,%ecx
-       jnz     .L020cfb_abort
-       leal    .Lpadlock_saved_context-.L021cfb_pic_point,%eax
-       pushfl
-       cld
-       call    _padlock_verify_ctx
-.L021cfb_pic_point:
-       leal    16(%edx),%edx
-       xorl    %eax,%eax
-       xorl    %ebx,%ebx
-       testl   $32,(%edx)
-       jnz     .L022cfb_aligned
-       testl   $15,%edi
-       setz    %al
-       testl   $15,%esi
-       setz    %bl
-       testl   %ebx,%eax
-       jnz     .L022cfb_aligned
-       negl    %eax
-       movl    $512,%ebx
-       notl    %eax
-       leal    -24(%esp),%ebp
-       cmpl    %ebx,%ecx
-       cmovcl  %ecx,%ebx
-       andl    %ebx,%eax
-       movl    %ecx,%ebx
-       negl    %eax
-       andl    $511,%ebx
-       leal    (%eax,%ebp,1),%esp
-       andl    $-16,%esp
-       jmp     .L023cfb_loop
-.align 16
-.L023cfb_loop:
-       movl    %edi,(%ebp)
-       movl    %esi,4(%ebp)
-       movl    %ecx,8(%ebp)
-       movl    %ebx,%ecx
-       movl    %ebx,12(%ebp)
-       testl   $15,%edi
-       cmovnzl %esp,%edi
-       testl   $15,%esi
-       jz      .L024cfb_inp_aligned
-       shrl    $2,%ecx
-.byte  243,165
-       subl    %ebx,%edi
-       movl    %ebx,%ecx
-       movl    %edi,%esi
-.L024cfb_inp_aligned:
-       leal    -16(%edx),%eax
-       leal    16(%edx),%ebx
-       shrl    $4,%ecx
-.byte  243,15,167,224
-       movdqa  (%eax),%xmm0
-       movdqa  %xmm0,-16(%edx)
-       movl    (%ebp),%edi
-       movl    12(%ebp),%ebx
-       testl   $15,%edi
-       jz      .L025cfb_out_aligned
-       movl    %ebx,%ecx
-       shrl    $2,%ecx
-       leal    (%esp),%esi
-.byte  243,165
-       subl    %ebx,%edi
-.L025cfb_out_aligned:
-       movl    4(%ebp),%esi
-       movl    8(%ebp),%ecx
-       addl    %ebx,%edi
-       addl    %ebx,%esi
-       subl    %ebx,%ecx
-       movl    $512,%ebx
-       jnz     .L023cfb_loop
-       testl   $15,%edi
-       jz      .L026cfb_done
-       movl    %ebp,%ecx
-       movl    %esp,%edi
-       subl    %esp,%ecx
-       xorl    %eax,%eax
-       shrl    $2,%ecx
-.byte  243,171
-.L026cfb_done:
-       leal    24(%ebp),%esp
-       jmp     .L027cfb_exit
-.align 16
-.L022cfb_aligned:
-       leal    -16(%edx),%eax
-       leal    16(%edx),%ebx
-       shrl    $4,%ecx
-.byte  243,15,167,224
-       movdqa  (%eax),%xmm0
-       movdqa  %xmm0,-16(%edx)
-.L027cfb_exit:
-       movl    $1,%eax
-       leal    4(%esp),%esp
-.L020cfb_abort:
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-.size  padlock_cfb_encrypt,.-.L_padlock_cfb_encrypt_begin
-.globl padlock_ofb_encrypt
-.type  padlock_ofb_encrypt,@function
-.align 16
-padlock_ofb_encrypt:
-.L_padlock_ofb_encrypt_begin:
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-       movl    20(%esp),%edi
-       movl    24(%esp),%esi
-       movl    28(%esp),%edx
-       movl    32(%esp),%ecx
-       testl   $15,%edx
-       jnz     .L028ofb_abort
-       testl   $15,%ecx
-       jnz     .L028ofb_abort
-       leal    .Lpadlock_saved_context-.L029ofb_pic_point,%eax
-       pushfl
-       cld
-       call    _padlock_verify_ctx
-.L029ofb_pic_point:
-       leal    16(%edx),%edx
-       xorl    %eax,%eax
-       xorl    %ebx,%ebx
-       testl   $32,(%edx)
-       jnz     .L030ofb_aligned
-       testl   $15,%edi
-       setz    %al
-       testl   $15,%esi
-       setz    %bl
-       testl   %ebx,%eax
-       jnz     .L030ofb_aligned
-       negl    %eax
-       movl    $512,%ebx
-       notl    %eax
-       leal    -24(%esp),%ebp
-       cmpl    %ebx,%ecx
-       cmovcl  %ecx,%ebx
-       andl    %ebx,%eax
-       movl    %ecx,%ebx
-       negl    %eax
-       andl    $511,%ebx
-       leal    (%eax,%ebp,1),%esp
-       andl    $-16,%esp
-       jmp     .L031ofb_loop
-.align 16
-.L031ofb_loop:
-       movl    %edi,(%ebp)
-       movl    %esi,4(%ebp)
-       movl    %ecx,8(%ebp)
-       movl    %ebx,%ecx
-       movl    %ebx,12(%ebp)
-       testl   $15,%edi
-       cmovnzl %esp,%edi
-       testl   $15,%esi
-       jz      .L032ofb_inp_aligned
-       shrl    $2,%ecx
-.byte  243,165
-       subl    %ebx,%edi
-       movl    %ebx,%ecx
-       movl    %edi,%esi
-.L032ofb_inp_aligned:
-       leal    -16(%edx),%eax
-       leal    16(%edx),%ebx
-       shrl    $4,%ecx
-.byte  243,15,167,232
-       movdqa  (%eax),%xmm0
-       movdqa  %xmm0,-16(%edx)
-       movl    (%ebp),%edi
-       movl    12(%ebp),%ebx
-       testl   $15,%edi
-       jz      .L033ofb_out_aligned
-       movl    %ebx,%ecx
-       shrl    $2,%ecx
-       leal    (%esp),%esi
-.byte  243,165
-       subl    %ebx,%edi
-.L033ofb_out_aligned:
-       movl    4(%ebp),%esi
-       movl    8(%ebp),%ecx
-       addl    %ebx,%edi
-       addl    %ebx,%esi
-       subl    %ebx,%ecx
-       movl    $512,%ebx
-       jnz     .L031ofb_loop
-       testl   $15,%edi
-       jz      .L034ofb_done
-       movl    %ebp,%ecx
-       movl    %esp,%edi
-       subl    %esp,%ecx
-       xorl    %eax,%eax
-       shrl    $2,%ecx
-.byte  243,171
-.L034ofb_done:
-       leal    24(%ebp),%esp
-       jmp     .L035ofb_exit
-.align 16
-.L030ofb_aligned:
-       leal    -16(%edx),%eax
-       leal    16(%edx),%ebx
-       shrl    $4,%ecx
-.byte  243,15,167,232
-       movdqa  (%eax),%xmm0
-       movdqa  %xmm0,-16(%edx)
-.L035ofb_exit:
-       movl    $1,%eax
-       leal    4(%esp),%esp
-.L028ofb_abort:
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-.size  padlock_ofb_encrypt,.-.L_padlock_ofb_encrypt_begin
-.globl padlock_ctr16_encrypt
-.type  padlock_ctr16_encrypt,@function
-.align 16
-padlock_ctr16_encrypt:
-.L_padlock_ctr16_encrypt_begin:
-       pushl   %ebp
-       pushl   %ebx
-       pushl   %esi
-       pushl   %edi
-       movl    20(%esp),%edi
-       movl    24(%esp),%esi
-       movl    28(%esp),%edx
-       movl    32(%esp),%ecx
-       testl   $15,%edx
-       jnz     .L036ctr16_abort
-       testl   $15,%ecx
-       jnz     .L036ctr16_abort
-       leal    .Lpadlock_saved_context-.L037ctr16_pic_point,%eax
-       pushfl
-       cld
-       call    _padlock_verify_ctx
-.L037ctr16_pic_point:
-       leal    16(%edx),%edx
-       xorl    %eax,%eax
-       movdqa  -16(%edx),%xmm0
-       movl    $512,%ebx
-       notl    %eax
-       leal    -24(%esp),%ebp
-       cmpl    %ebx,%ecx
-       cmovcl  %ecx,%ebx
-       andl    %ebx,%eax
-       movl    %ecx,%ebx
-       negl    %eax
-       andl    $511,%ebx
-       leal    (%eax,%ebp,1),%esp
-       andl    $-16,%esp
-       jmp     .L038ctr16_loop
-.align 16
-.L038ctr16_loop:
-       movl    %edi,(%ebp)
-       movl    %esi,4(%ebp)
-       movl    %ecx,8(%ebp)
-       movl    %ebx,%ecx
-       movl    %ebx,12(%ebp)
-       pextrw  $7,%xmm0,%ecx
-       movl    $1,%esi
-       xorl    %edi,%edi
-       xchgb   %cl,%ch
-.L039ctr16_prepare:
-       movdqa  %xmm0,(%esp,%edi,1)
-       leal    (%ecx,%esi,1),%eax
-       xchgb   %al,%ah
-       leal    16(%edi),%edi
-       pinsrw  $7,%eax,%xmm0
-       leal    1(%esi),%esi
-       cmpl    %ebx,%edi
-       jb      .L039ctr16_prepare
-       leal    (%esp),%esi
-       leal    (%esp),%edi
-       movl    %ebx,%ecx
-       leal    -16(%edx),%eax
-       leal    16(%edx),%ebx
-       shrl    $4,%ecx
-.byte  243,15,167,200
-       movl    (%ebp),%edi
-       movl    12(%ebp),%ebx
-       movl    4(%ebp),%esi
-       xorl    %ecx,%ecx
-.L040ctr16_xor:
-       movdqu  (%esi,%ecx,1),%xmm1
-       leal    16(%ecx),%ecx
-       pxor    -16(%esp,%ecx,1),%xmm1
-       movdqu  %xmm1,-16(%edi,%ecx,1)
-       cmpl    %ebx,%ecx
-       jb      .L040ctr16_xor
-       movl    8(%ebp),%ecx
-       addl    %ebx,%edi
-       addl    %ebx,%esi
-       subl    %ebx,%ecx
-       movl    $512,%ebx
-       jnz     .L038ctr16_loop
-       movdqa  %xmm0,-16(%edx)
-       pxor    %xmm0,%xmm0
-       pxor    %xmm1,%xmm1
-       movl    %ebp,%ecx
-       movl    %esp,%edi
-       subl    %esp,%ecx
-       xorl    %eax,%eax
-       shrl    $2,%ecx
-.byte  243,171
-.L041ctr16_done:
-       leal    24(%ebp),%esp
-       movl    $1,%eax
-       leal    4(%esp),%esp
-.L036ctr16_abort:
-       popl    %edi
-       popl    %esi
-       popl    %ebx
-       popl    %ebp
-       ret
-.size  padlock_ctr16_encrypt,.-.L_padlock_ctr16_encrypt_begin
-.globl padlock_xstore
-.type  padlock_xstore,@function
-.align 16
-padlock_xstore:
-.L_padlock_xstore_begin:
-       pushl   %edi
-       movl    8(%esp),%edi
-       movl    12(%esp),%edx
-.byte  15,167,192
-       popl    %edi
-       ret
-.size  padlock_xstore,.-.L_padlock_xstore_begin
-.type  _win32_segv_handler,@function
-.align 16
-_win32_segv_handler:
-       movl    $1,%eax
-       movl    4(%esp),%edx
-       movl    12(%esp),%ecx
-       cmpl    $3221225477,(%edx)
-       jne     .L042ret
-       addl    $4,184(%ecx)
-       movl    $0,%eax
-.L042ret:
-       ret
-.size  _win32_segv_handler,.-_win32_segv_handler
-.globl padlock_sha1_oneshot
-.type  padlock_sha1_oneshot,@function
-.align 16
-padlock_sha1_oneshot:
-.L_padlock_sha1_oneshot_begin:
-       pushl   %edi
-       pushl   %esi
-       xorl    %eax,%eax
-       movl    12(%esp),%edi
-       movl    16(%esp),%esi
-       movl    20(%esp),%ecx
-.byte  243,15,166,200
-       popl    %esi
-       popl    %edi
-       ret
-.size  padlock_sha1_oneshot,.-.L_padlock_sha1_oneshot_begin
-.globl padlock_sha1
-.type  padlock_sha1,@function
-.align 16
-padlock_sha1:
-.L_padlock_sha1_begin:
-       pushl   %edi
-       pushl   %esi
-       movl    $-1,%eax
-       movl    12(%esp),%edi
-       movl    16(%esp),%esi
-       movl    20(%esp),%ecx
-.byte  243,15,166,200
-       popl    %esi
-       popl    %edi
-       ret
-.size  padlock_sha1,.-.L_padlock_sha1_begin
-.globl padlock_sha256_oneshot
-.type  padlock_sha256_oneshot,@function
-.align 16
-padlock_sha256_oneshot:
-.L_padlock_sha256_oneshot_begin:
-       pushl   %edi
-       pushl   %esi
-       xorl    %eax,%eax
-       movl    12(%esp),%edi
-       movl    16(%esp),%esi
-       movl    20(%esp),%ecx
-.byte  243,15,166,208
-       popl    %esi
-       popl    %edi
-       ret
-.size  padlock_sha256_oneshot,.-.L_padlock_sha256_oneshot_begin
-.globl padlock_sha256
-.type  padlock_sha256,@function
-.align 16
-padlock_sha256:
-.L_padlock_sha256_begin:
-       pushl   %edi
-       pushl   %esi
-       movl    $-1,%eax
-       movl    12(%esp),%edi
-       movl    16(%esp),%esi
-       movl    20(%esp),%ecx
-.byte  243,15,166,208
-       popl    %esi
-       popl    %edi
-       ret
-.size  padlock_sha256,.-.L_padlock_sha256_begin
-.byte  86,73,65,32,80,97,100,108,111,99,107,32,120,56,54,32
-.byte  109,111,100,117,108,101,44,32,67,82,89,80,84,79,71,65
-.byte  77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101
-.byte  110,115,115,108,46,111,114,103,62,0
-.align 16
-.data
-.align 4
-.Lpadlock_saved_context:
-.long  0
-
-#if defined(__linux__) && defined(__ELF__)
-.section .note.GNU-stack,"",%progbits
-#endif
-
diff --git a/lib/accelerated/x86.h b/lib/accelerated/x86.h
deleted file mode 100644
index 4a5d5c7..0000000
--- a/lib/accelerated/x86.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2011 Free Software Foundation, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS.
- *
- * The GnuTLS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <config.h>
-
-#if defined(ASM_X86_32) || defined(ASM_X86_64)
-
-void _gnutls_cpuid(unsigned int func, unsigned int *ax, unsigned int *bx, 
unsigned int *cx, unsigned int* dx);
-
-# ifdef ASM_X86_32
-unsigned int _gnutls_have_cpuid(void);
-# else
-#  define _gnutls_have_cpuid() 1
-# endif /* ASM_X86_32 */
-
-#endif
-
diff --git a/lib/accelerated/intel/.gitignore b/lib/accelerated/x86/.gitignore
similarity index 100%
rename from lib/accelerated/intel/.gitignore
rename to lib/accelerated/x86/.gitignore
diff --git a/lib/accelerated/x86/Makefile.am b/lib/accelerated/x86/Makefile.am
new file mode 100644
index 0000000..79acf96
--- /dev/null
+++ b/lib/accelerated/x86/Makefile.am
@@ -0,0 +1,59 @@
+## Process this file with automake to produce Makefile.in
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# Author: Nikos Mavrogiannopoulos
+#
+# This file is part of GNUTLS.
+#
+# The GNUTLS library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 3 of
+# the License, or (at your option) any later version.
+#
+# The GNUTLS library is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
+# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>
+
+AM_LIBTOOLFLAGS=--tag=CC
+AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
+AM_CPPFLAGS = \
+       -I$(srcdir)/../../../gl         \
+       -I$(builddir)/../../../gl               \
+       -I$(srcdir)/../../includes      \
+       -I$(builddir)/../../includes    \
+       -I$(srcdir)/../../ \
+       -I$(srcdir)/../
+
+if ENABLE_MINITASN1
+AM_CPPFLAGS += -I$(srcdir)/../../minitasn1
+endif
+
+EXTRA_DIST = README license.txt
+
+noinst_LTLIBRARIES = libx86.la
+
+libx86_la_SOURCES = sha-padlock.c hmac-padlock.c aes-x86.c aes-padlock.c 
aes-gcm-padlock.c aes-padlock.h aes-x86.h x86.h sha-padlock.h
+
+if ASM_X86_64
+AM_CFLAGS += -DASM_X86_64 -DASM_X86
+
+if WINDOWS
+libx86_la_SOURCES += asm-coff/appro-aes-x86-64-coff.s 
asm-coff/padlock-x86-64-coff.s asm-coff/cpuid-x86-64-coff.s 
asm-coff/appro-aes-gcm-x86-64-coff.s
+else
+libx86_la_SOURCES += asm/appro-aes-x86-64.s asm/appro-aes-gcm-x86-64.s 
aes-gcm-x86.c asm/padlock-x86-64.s asm/cpuid-x86-64.s
+endif
+
+else
+AM_CFLAGS += -DASM_X86_32 -DASM_X86
+
+if WINDOWS
+libx86_la_SOURCES += asm-coff/appro-aes-x86-coff.s asm-coff/padlock-x86-coff.s 
asm-coff/cpuid-x86-coff.s
+else
+libx86_la_SOURCES += asm/appro-aes-x86.s asm/padlock-x86.s asm/cpuid-x86.s
+endif
+
+endif
diff --git a/lib/accelerated/x86/README b/lib/accelerated/x86/README
new file mode 100644
index 0000000..9325982
--- /dev/null
+++ b/lib/accelerated/x86/README
@@ -0,0 +1,3 @@
+The AES-NI and Padlock implementation by Andy Polyakov is not part of the 
GnuTLS library, but is 
+used with GnuTLS. Their license is included in license.txt.
+
diff --git a/lib/accelerated/x86/aes-gcm-padlock.c 
b/lib/accelerated/x86/aes-gcm-padlock.c
new file mode 100644
index 0000000..5039e86
--- /dev/null
+++ b/lib/accelerated/x86/aes-gcm-padlock.c
@@ -0,0 +1,168 @@
+/*
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * The GnuTLS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/*
+ * The following code is an implementation of the AES-128-CBC cipher
+ * using intel's AES instruction set. It is based on Intel reference
+ * code.
+ */
+
+#include <gnutls_errors.h>
+#include <gnutls_int.h>
+
+#ifdef HAVE_LIBNETTLE
+
+#include <gnutls/crypto.h>
+#include <gnutls_errors.h>
+#include <aes-x86.h>
+#include <x86.h>
+#include <byteswap.h>
+#include <nettle/gcm.h>
+#include <aes-padlock.h>
+
+#define GCM_BLOCK_SIZE 16
+
+/* GCM mode 
+ * Actually padlock doesn't include GCM mode. We just use
+ * the ECB part of padlock and nettle for everything else.
+ */
+struct gcm_padlock_aes_ctx GCM_CTX(struct padlock_ctx);
+
+static void padlock_aes_encrypt(void *_ctx,
+                                unsigned length, uint8_t *dst,
+                                const uint8_t *src)
+{
+    struct padlock_ctx *ctx = _ctx;
+    struct padlock_cipher_data *pce;
+
+    pce = ALIGN16(&ctx->expanded_key);
+
+    padlock_ecb_encrypt(dst, src, pce, length);
+}
+
+static void padlock_aes_set_encrypt_key(struct padlock_ctx *_ctx,
+                                        unsigned length, const uint8_t *key)
+{
+  struct padlock_ctx *ctx = _ctx;
+  ctx->enc = 1;
+  
+  padlock_aes_cipher_setkey(_ctx, key, length);
+}
+
+static void
+aes_gcm_deinit (void *_ctx)
+{
+  gnutls_free (_ctx);
+}
+
+static int
+aes_gcm_cipher_init (gnutls_cipher_algorithm_t algorithm, void **_ctx, int enc)
+{
+  /* we use key size to distinguish */
+  if (algorithm != GNUTLS_CIPHER_AES_128_GCM &&
+      algorithm != GNUTLS_CIPHER_AES_256_GCM)
+    return GNUTLS_E_INVALID_REQUEST;
+
+  *_ctx = gnutls_calloc (1, sizeof (struct gcm_padlock_aes_ctx));
+  if (*_ctx == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
+    }
+
+  return 0;
+}
+
+static int
+aes_gcm_cipher_setkey (void *_ctx, const void *userkey, size_t keysize)
+{
+  struct gcm_padlock_aes_ctx *ctx = _ctx;
+
+  GCM_SET_KEY(ctx, padlock_aes_set_encrypt_key, padlock_aes_encrypt, keysize, 
userkey);
+
+  return 0;
+}
+
+static int
+aes_gcm_setiv (void *_ctx, const void *iv, size_t iv_size)
+{
+  struct gcm_padlock_aes_ctx *ctx = _ctx;
+
+  if (iv_size != GCM_BLOCK_SIZE - 4)
+    return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+  
+  GCM_SET_IV(ctx, iv_size, iv);
+
+  return 0;
+}
+
+static int
+aes_gcm_encrypt (void *_ctx, const void *src, size_t src_size,
+                 void *dst, size_t length)
+{
+  struct gcm_padlock_aes_ctx *ctx = _ctx;
+
+  GCM_ENCRYPT(ctx, padlock_aes_encrypt, src_size, dst, src);
+
+  return 0;
+}
+
+static int
+aes_gcm_decrypt (void *_ctx, const void *src, size_t src_size,
+                 void *dst, size_t dst_size)
+{
+  struct gcm_padlock_aes_ctx *ctx = _ctx;
+
+  GCM_DECRYPT(ctx, padlock_aes_encrypt, src_size, dst, src);
+  return 0;
+}
+
+static int
+aes_gcm_auth (void *_ctx, const void *src, size_t src_size)
+{
+  struct gcm_padlock_aes_ctx *ctx = _ctx;
+
+  GCM_UPDATE(ctx, src_size, src);
+
+  return 0;
+}
+
+static void
+aes_gcm_tag (void *_ctx, void *tag, size_t tagsize)
+{
+  struct gcm_padlock_aes_ctx *ctx = _ctx;
+  
+  GCM_DIGEST(ctx, padlock_aes_encrypt, tagsize, tag);
+}
+
+const gnutls_crypto_cipher_st aes_gcm_padlock_struct = {
+  .init = aes_gcm_cipher_init,
+  .setkey = aes_gcm_cipher_setkey,
+  .setiv = aes_gcm_setiv,
+  .encrypt = aes_gcm_encrypt,
+  .decrypt = aes_gcm_decrypt,
+  .deinit = aes_gcm_deinit,
+  .tag = aes_gcm_tag,
+  .auth = aes_gcm_auth,
+};
+
+#endif
diff --git a/lib/accelerated/intel/aes-gcm-x86.c 
b/lib/accelerated/x86/aes-gcm-x86.c
similarity index 100%
rename from lib/accelerated/intel/aes-gcm-x86.c
rename to lib/accelerated/x86/aes-gcm-x86.c
diff --git a/lib/accelerated/x86/aes-padlock.c 
b/lib/accelerated/x86/aes-padlock.c
new file mode 100644
index 0000000..881eb75
--- /dev/null
+++ b/lib/accelerated/x86/aes-padlock.c
@@ -0,0 +1,410 @@
+/*
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * The GnuTLS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/*
+ * The following code is an implementation of the AES-128-CBC cipher
+ * using VIA Padlock instruction set. 
+ */
+
+#include <gnutls_errors.h>
+#include <gnutls_int.h>
+#include <gnutls/crypto.h>
+#include <gnutls_errors.h>
+#include <aes-x86.h>
+#include <x86.h>
+#ifdef HAVE_LIBNETTLE
+#include <nettle/aes.h>         /* for key generation in 192 and 256 bits */
+#include <sha-padlock.h>
+#endif
+#include <aes-padlock.h>
+
+static int
+aes_cipher_init (gnutls_cipher_algorithm_t algorithm, void **_ctx, int enc)
+{
+  /* we use key size to distinguish */
+  if (algorithm != GNUTLS_CIPHER_AES_128_CBC
+      && algorithm != GNUTLS_CIPHER_AES_192_CBC
+      && algorithm != GNUTLS_CIPHER_AES_256_CBC)
+    return GNUTLS_E_INVALID_REQUEST;
+
+  *_ctx = gnutls_calloc (1, sizeof (struct padlock_ctx));
+  if (*_ctx == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
+    }
+
+  ((struct padlock_ctx *) (*_ctx))->enc = enc;
+  return 0;
+}
+
+int
+padlock_aes_cipher_setkey (void *_ctx, const void *userkey, size_t keysize)
+{
+  struct padlock_ctx *ctx = _ctx;
+  struct padlock_cipher_data *pce;
+#ifdef HAVE_LIBNETTLE
+  struct aes_ctx nc;
+#endif
+
+  memset (_ctx, 0, sizeof (struct padlock_cipher_data));
+
+  pce = ALIGN16 (&ctx->expanded_key);
+
+  pce->cword.b.encdec = (ctx->enc == 0);
+
+  switch (keysize)
+    {
+    case 16:
+      pce->cword.b.ksize = 0;
+      pce->cword.b.rounds = 10;
+      memcpy (pce->ks.rd_key, userkey, 16);
+      pce->cword.b.keygen = 0;
+      break;
+#ifdef HAVE_LIBNETTLE
+    case 24:
+      pce->cword.b.ksize = 1;
+      pce->cword.b.rounds = 12;
+      goto common_24_32;
+    case 32:
+      pce->cword.b.ksize = 2;
+      pce->cword.b.rounds = 14;
+    common_24_32:
+      /* expand key using nettle */
+      if (ctx->enc)
+        aes_set_encrypt_key (&nc, keysize, userkey);
+      else
+        aes_set_decrypt_key (&nc, keysize, userkey);
+
+      memcpy (pce->ks.rd_key, nc.keys, sizeof (nc.keys));
+      pce->ks.rounds = nc.nrounds;
+
+      pce->cword.b.keygen = 1;
+      break;
+#endif
+    default:
+      return gnutls_assert_val (GNUTLS_E_ENCRYPTION_FAILED);
+    }
+
+  padlock_reload_key ();
+
+  return 0;
+}
+
+static int
+aes_setiv (void *_ctx, const void *iv, size_t iv_size)
+{
+  struct padlock_ctx *ctx = _ctx;
+  struct padlock_cipher_data *pce;
+
+  pce = ALIGN16 (&ctx->expanded_key);
+
+  memcpy (pce->iv, iv, 16);
+
+  return 0;
+}
+
+static int
+padlock_aes_cbc_encrypt (void *_ctx, const void *src, size_t src_size,
+                         void *dst, size_t dst_size)
+{
+  struct padlock_ctx *ctx = _ctx;
+  struct padlock_cipher_data *pce;
+
+  pce = ALIGN16 (&ctx->expanded_key);
+
+  padlock_cbc_encrypt (dst, src, pce, src_size);
+
+  return 0;
+}
+
+
+static int
+padlock_aes_cbc_decrypt (void *_ctx, const void *src, size_t src_size,
+                         void *dst, size_t dst_size)
+{
+  struct padlock_ctx *ctx = _ctx;
+  struct padlock_cipher_data *pcd;
+
+  pcd = ALIGN16 (&ctx->expanded_key);
+
+  padlock_cbc_encrypt (dst, src, pcd, src_size);
+
+  return 0;
+}
+
+static void
+aes_deinit (void *_ctx)
+{
+  gnutls_free (_ctx);
+}
+
+static const gnutls_crypto_cipher_st aes_padlock_struct = {
+  .init = aes_cipher_init,
+  .setkey = padlock_aes_cipher_setkey,
+  .setiv = aes_setiv,
+  .encrypt = padlock_aes_cbc_encrypt,
+  .decrypt = padlock_aes_cbc_decrypt,
+  .deinit = aes_deinit,
+};
+
+static int
+check_padlock (void)
+{
+  unsigned int edx = padlock_capability ();
+
+  return ((edx & (0x3 << 6)) == (0x3 << 6));
+}
+
+static int
+check_phe (void)
+{
+  unsigned int edx = padlock_capability ();
+
+  return ((edx & (0x3 << 10)) == (0x3 << 10));
+}
+
+/* We are actually checking for SHA512 */
+static int
+check_phe_sha512 (void)
+{
+  unsigned int edx = padlock_capability ();
+
+  return ((edx & (0x3 << 25)) == (0x3 << 25));
+}
+
+static int
+check_phe_partial (void)
+{
+  const char* text = "test and test";
+  uint32_t iv[5] = { 0x67452301UL, 0xEFCDAB89UL,
+       0x98BADCFEUL, 0x10325476UL, 0xC3D2E1F0UL };
+
+  padlock_sha1_blocks (iv, text, sizeof(text)-1);
+  padlock_sha1_blocks (iv, text, sizeof(text)-1);
+
+  if (iv[0] == 0x9096E2D8UL && iv[1] == 0xA33074EEUL &&
+      iv[2] == 0xCDBEE447UL && iv[3] == 0xEC7979D2UL &&
+      iv[4] == 0x9D3FF5CFUL)
+      return 1;
+  else
+    return 0;
+}
+
+static unsigned
+check_via (void)
+{
+  unsigned int a, b, c, d;
+  _gnutls_cpuid (0, &a, &b, &c, &d);
+
+  if ((memcmp (&b, "Cent", 4) == 0 &&
+       memcmp (&d, "aurH", 4) == 0 && memcmp (&c, "auls", 4) == 0))
+    {
+      return 1;
+    }
+
+  return 0;
+}
+
+void
+register_padlock_crypto (void)
+{
+  int ret, phe;
+
+  if (check_via () == 0)
+    return;
+  if (check_padlock ())
+    {
+      _gnutls_debug_log ("Padlock AES accelerator was detected\n");
+      ret =
+        gnutls_crypto_single_cipher_register
+        (GNUTLS_CIPHER_AES_128_CBC, 80, &aes_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      /* register GCM ciphers */
+      ret =
+        gnutls_crypto_single_cipher_register
+        (GNUTLS_CIPHER_AES_128_GCM, 80, &aes_gcm_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+#ifdef HAVE_LIBNETTLE
+      ret =
+        gnutls_crypto_single_cipher_register (GNUTLS_CIPHER_AES_192_CBC,
+                                              80, &aes_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      ret =
+        gnutls_crypto_single_cipher_register (GNUTLS_CIPHER_AES_256_CBC,
+                                              80, &aes_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      ret =
+        gnutls_crypto_single_cipher_register (GNUTLS_CIPHER_AES_256_GCM,
+                                              80, &aes_gcm_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+#endif
+    }
+
+#ifdef HAVE_LIBNETTLE
+  phe = check_phe ();
+
+  if (check_phe_partial () && phe)
+    {
+      _gnutls_debug_log ("Padlock SHA1 and SHA256 (partial) accelerator was 
detected\n");
+      if (check_phe_sha512 ())
+        {
+          _gnutls_debug_log ("Padlock SHA512 (partial) accelerator was 
detected\n");
+          ret =
+            gnutls_crypto_single_digest_register (GNUTLS_DIG_SHA384,
+                                                  80,
+                                                  &sha_padlock_nano_struct);
+          if (ret < 0)
+            {
+              gnutls_assert ();
+            }
+
+          ret =
+            gnutls_crypto_single_digest_register (GNUTLS_DIG_SHA512,
+                                                  80,
+                                                  &sha_padlock_nano_struct);
+          if (ret < 0)
+            {
+              gnutls_assert ();
+            }
+
+          ret =
+            gnutls_crypto_single_mac_register (GNUTLS_MAC_SHA384,
+                                               80,
+                                               &hmac_sha_padlock_nano_struct);
+          if (ret < 0)
+            {
+              gnutls_assert ();
+            }
+
+          ret =
+            gnutls_crypto_single_mac_register (GNUTLS_MAC_SHA512,
+                                               80,
+                                               &hmac_sha_padlock_nano_struct);
+          if (ret < 0)
+            {
+              gnutls_assert ();
+            }
+        }
+
+      ret =
+        gnutls_crypto_single_digest_register (GNUTLS_DIG_SHA1,
+                                              80, &sha_padlock_nano_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      ret =
+        gnutls_crypto_single_digest_register (GNUTLS_DIG_SHA224,
+                                              80, &sha_padlock_nano_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      ret =
+        gnutls_crypto_single_digest_register (GNUTLS_DIG_SHA256,
+                                              80, &sha_padlock_nano_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      ret =
+        gnutls_crypto_single_mac_register (GNUTLS_MAC_SHA1,
+                                           80, &hmac_sha_padlock_nano_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      /* we don't register MAC_SHA224 because it is not used by TLS */
+
+      ret =
+        gnutls_crypto_single_mac_register (GNUTLS_MAC_SHA256,
+                                           80, &hmac_sha_padlock_nano_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+    }
+  else if (phe)
+    {
+      /* Original padlock PHE. Does not support incremental operations.
+       */
+      _gnutls_debug_log ("Padlock SHA1 and SHA256 accelerator was detected\n");
+      ret =
+        gnutls_crypto_single_digest_register (GNUTLS_DIG_SHA1,
+                                              80, &sha_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      ret =
+        gnutls_crypto_single_digest_register (GNUTLS_DIG_SHA256,
+                                              80, &sha_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      ret =
+        gnutls_crypto_single_mac_register (GNUTLS_MAC_SHA1,
+                                           80, &hmac_sha_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+
+      ret =
+        gnutls_crypto_single_mac_register (GNUTLS_MAC_SHA256,
+                                           80, &hmac_sha_padlock_struct);
+      if (ret < 0)
+        {
+          gnutls_assert ();
+        }
+    }
+#endif
+
+  return;
+}
diff --git a/lib/accelerated/x86/aes-padlock.h 
b/lib/accelerated/x86/aes-padlock.h
new file mode 100644
index 0000000..ccb8359
--- /dev/null
+++ b/lib/accelerated/x86/aes-padlock.h
@@ -0,0 +1,46 @@
+#ifndef AES_PADLOCK_H
+# define AES_PADLOCK_H
+
+#include <gnutls_int.h>
+#include <aes-x86.h>
+
+struct padlock_cipher_data {
+    unsigned char iv[16];       /* Initialization vector */
+    union {
+        unsigned int pad[4];
+        struct {
+            int rounds:4;
+            int dgst:1;         /* n/a in C3 */
+            int align:1;        /* n/a in C3 */
+            int ciphr:1;        /* n/a in C3 */
+            unsigned int keygen:1;
+            int interm:1;
+            unsigned int encdec:1;
+            int ksize:2;
+        } b;
+    } cword;                    /* Control word */
+    AES_KEY ks;                 /* Encryption key */
+};
+
+struct padlock_ctx {
+    struct padlock_cipher_data expanded_key;
+    int enc;
+};
+
+extern const gnutls_crypto_cipher_st aes_gcm_padlock_struct;
+extern const gnutls_crypto_mac_st hmac_sha_padlock_struct;
+extern const gnutls_crypto_digest_st sha_padlock_struct;
+
+extern const gnutls_crypto_mac_st hmac_sha_padlock_nano_struct;
+extern const gnutls_crypto_digest_st sha_padlock_nano_struct;
+
+int padlock_aes_cipher_setkey(void *_ctx, const void *userkey, size_t keysize);
+
+/* asm */
+unsigned int padlock_capability(void);
+void padlock_reload_key(void);
+int padlock_ecb_encrypt(void *out, const void *inp,
+                        struct padlock_cipher_data *ctx, size_t len);
+int padlock_cbc_encrypt(void *out, const void *inp,
+                        struct padlock_cipher_data *ctx, size_t len);
+#endif
diff --git a/lib/accelerated/intel/aes-x86.c b/lib/accelerated/x86/aes-x86.c
similarity index 100%
rename from lib/accelerated/intel/aes-x86.c
rename to lib/accelerated/x86/aes-x86.c
diff --git a/lib/accelerated/intel/aes-x86.h b/lib/accelerated/x86/aes-x86.h
similarity index 100%
rename from lib/accelerated/intel/aes-x86.h
rename to lib/accelerated/x86/aes-x86.h
diff --git a/lib/accelerated/x86/asm-coff/appro-aes-gcm-x86-64-coff.s 
b/lib/accelerated/x86/asm-coff/appro-aes-gcm-x86-64-coff.s
new file mode 100644
index 0000000..201a790
--- /dev/null
+++ b/lib/accelerated/x86/asm-coff/appro-aes-gcm-x86-64-coff.s
@@ -0,0 +1,1211 @@
+# Copyright (c) 2011, Andy Polyakov by <address@hidden>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 
+#     * Redistributions of source code must retain copyright notices,
+#      this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+#
+#     * Neither the name of the Andy Polyakov nor the names of its
+#      copyright holder and contributors may be used to endorse or
+#      promote products derived from this software without specific
+#      prior written permission.
+#
+# ALTERNATIVELY, provided that this notice is retained in full, this
+# product may be distributed under the terms of the GNU General Public
+# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+# those given above.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.text  
+
+.globl gcm_gmult_4bit
+.def   gcm_gmult_4bit; .scl 2; .type 32;       .endef
+.p2align       4
+gcm_gmult_4bit:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_gcm_gmult_4bit:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+
+       pushq   %rbx
+       pushq   %rbp
+       pushq   %r12
+.Lgmult_prologue:
+
+       movzbq  15(%rdi),%r8
+       leaq    .Lrem_4bit(%rip),%r11
+       xorq    %rax,%rax
+       xorq    %rbx,%rbx
+       movb    %r8b,%al
+       movb    %r8b,%bl
+       shlb    $4,%al
+       movq    $14,%rcx
+       movq    8(%rsi,%rax,1),%r8
+       movq    (%rsi,%rax,1),%r9
+       andb    $240,%bl
+       movq    %r8,%rdx
+       jmp     .Loop1
+
+.p2align       4
+.Loop1:
+       shrq    $4,%r8
+       andq    $15,%rdx
+       movq    %r9,%r10
+       movb    (%rdi,%rcx,1),%al
+       shrq    $4,%r9
+       xorq    8(%rsi,%rbx,1),%r8
+       shlq    $60,%r10
+       xorq    (%rsi,%rbx,1),%r9
+       movb    %al,%bl
+       xorq    (%r11,%rdx,8),%r9
+       movq    %r8,%rdx
+       shlb    $4,%al
+       xorq    %r10,%r8
+       decq    %rcx
+       js      .Lbreak1
+
+       shrq    $4,%r8
+       andq    $15,%rdx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       xorq    8(%rsi,%rax,1),%r8
+       shlq    $60,%r10
+       xorq    (%rsi,%rax,1),%r9
+       andb    $240,%bl
+       xorq    (%r11,%rdx,8),%r9
+       movq    %r8,%rdx
+       xorq    %r10,%r8
+       jmp     .Loop1
+
+.p2align       4
+.Lbreak1:
+       shrq    $4,%r8
+       andq    $15,%rdx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       xorq    8(%rsi,%rax,1),%r8
+       shlq    $60,%r10
+       xorq    (%rsi,%rax,1),%r9
+       andb    $240,%bl
+       xorq    (%r11,%rdx,8),%r9
+       movq    %r8,%rdx
+       xorq    %r10,%r8
+
+       shrq    $4,%r8
+       andq    $15,%rdx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       xorq    8(%rsi,%rbx,1),%r8
+       shlq    $60,%r10
+       xorq    (%rsi,%rbx,1),%r9
+       xorq    %r10,%r8
+       xorq    (%r11,%rdx,8),%r9
+
+       bswapq  %r8
+       bswapq  %r9
+       movq    %r8,8(%rdi)
+       movq    %r9,(%rdi)
+
+       movq    16(%rsp),%rbx
+       leaq    24(%rsp),%rsp
+.Lgmult_epilogue:
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_gcm_gmult_4bit:
+.globl gcm_ghash_4bit
+.def   gcm_ghash_4bit; .scl 2; .type 32;       .endef
+.p2align       4
+gcm_ghash_4bit:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_gcm_ghash_4bit:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+       movq    %r9,%rcx
+
+       pushq   %rbx
+       pushq   %rbp
+       pushq   %r12
+       pushq   %r13
+       pushq   %r14
+       pushq   %r15
+       subq    $280,%rsp
+.Lghash_prologue:
+       movq    %rdx,%r14
+       movq    %rcx,%r15
+       subq    $-128,%rsi
+       leaq    16+128(%rsp),%rbp
+       xorl    %edx,%edx
+       movq    0+0-128(%rsi),%r8
+       movq    0+8-128(%rsi),%rax
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    16+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    16+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,0(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,0(%rbp)
+       movq    32+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,0-128(%rbp)
+       movq    32+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,1(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,8(%rbp)
+       movq    48+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,8-128(%rbp)
+       movq    48+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,2(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,16(%rbp)
+       movq    64+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,16-128(%rbp)
+       movq    64+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,3(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,24(%rbp)
+       movq    80+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,24-128(%rbp)
+       movq    80+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,4(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,32(%rbp)
+       movq    96+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,32-128(%rbp)
+       movq    96+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,5(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,40(%rbp)
+       movq    112+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,40-128(%rbp)
+       movq    112+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,6(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,48(%rbp)
+       movq    128+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,48-128(%rbp)
+       movq    128+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,7(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,56(%rbp)
+       movq    144+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,56-128(%rbp)
+       movq    144+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,8(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,64(%rbp)
+       movq    160+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,64-128(%rbp)
+       movq    160+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,9(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,72(%rbp)
+       movq    176+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,72-128(%rbp)
+       movq    176+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,10(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,80(%rbp)
+       movq    192+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,80-128(%rbp)
+       movq    192+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,11(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,88(%rbp)
+       movq    208+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,88-128(%rbp)
+       movq    208+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,12(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,96(%rbp)
+       movq    224+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,96-128(%rbp)
+       movq    224+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,13(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,104(%rbp)
+       movq    240+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,104-128(%rbp)
+       movq    240+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,14(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,112(%rbp)
+       shlb    $4,%dl
+       movq    %rax,112-128(%rbp)
+       shlq    $60,%r10
+       movb    %dl,15(%rsp)
+       orq     %r10,%rbx
+       movq    %r9,120(%rbp)
+       movq    %rbx,120-128(%rbp)
+       addq    $-128,%rsi
+       movq    8(%rdi),%r8
+       movq    0(%rdi),%r9
+       addq    %r14,%r15
+       leaq    .Lrem_8bit(%rip),%r11
+       jmp     .Louter_loop
+.p2align       4
+.Louter_loop:
+       xorq    (%r14),%r9
+       movq    8(%r14),%rdx
+       leaq    16(%r14),%r14
+       xorq    %r8,%rdx
+       movq    %r9,(%rdi)
+       movq    %rdx,8(%rdi)
+       shrq    $32,%rdx
+       xorq    %rax,%rax
+       roll    $8,%edx
+       movb    %dl,%al
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       shrl    $4,%ebx
+       roll    $8,%edx
+       movq    8(%rsi,%rax,1),%r8
+       movq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       movl    8(%rdi),%edx
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       movl    4(%rdi),%edx
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       movl    0(%rdi),%edx
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       andl    $240,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       movl    -4(%rdi),%edx
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       movzwq  (%r11,%r12,2),%r12
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       shlq    $48,%r12
+       xorq    %r10,%r8
+       xorq    %r12,%r9
+       movzbq  %r8b,%r13
+       shrq    $4,%r8
+       movq    %r9,%r10
+       shlb    $4,%r13b
+       shrq    $4,%r9
+       xorq    8(%rsi,%rcx,1),%r8
+       movzwq  (%r11,%r13,2),%r13
+       shlq    $60,%r10
+       xorq    (%rsi,%rcx,1),%r9
+       xorq    %r10,%r8
+       shlq    $48,%r13
+       bswapq  %r8
+       xorq    %r13,%r9
+       bswapq  %r9
+       cmpq    %r15,%r14
+       jb      .Louter_loop
+       movq    %r8,8(%rdi)
+       movq    %r9,(%rdi)
+
+       leaq    280(%rsp),%rsi
+       movq    0(%rsi),%r15
+       movq    8(%rsi),%r14
+       movq    16(%rsi),%r13
+       movq    24(%rsi),%r12
+       movq    32(%rsi),%rbp
+       movq    40(%rsi),%rbx
+       leaq    48(%rsi),%rsp
+.Lghash_epilogue:
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_gcm_ghash_4bit:
+.globl gcm_init_clmul
+.def   gcm_init_clmul; .scl 2; .type 32;       .endef
+.p2align       4
+gcm_init_clmul:
+       movdqu  (%rdx),%xmm2
+       pshufd  $78,%xmm2,%xmm2
+
+
+       pshufd  $255,%xmm2,%xmm4
+       movdqa  %xmm2,%xmm3
+       psllq   $1,%xmm2
+       pxor    %xmm5,%xmm5
+       psrlq   $63,%xmm3
+       pcmpgtd %xmm4,%xmm5
+       pslldq  $8,%xmm3
+       por     %xmm3,%xmm2
+
+
+       pand    .L0x1c2_polynomial(%rip),%xmm5
+       pxor    %xmm5,%xmm2
+
+
+       movdqa  %xmm2,%xmm0
+       movdqa  %xmm0,%xmm1
+       pshufd  $78,%xmm0,%xmm3
+       pshufd  $78,%xmm2,%xmm4
+       pxor    %xmm0,%xmm3
+       pxor    %xmm2,%xmm4
+.byte  102,15,58,68,194,0
+.byte  102,15,58,68,202,17
+.byte  102,15,58,68,220,0
+       pxor    %xmm0,%xmm3
+       pxor    %xmm1,%xmm3
+
+       movdqa  %xmm3,%xmm4
+       psrldq  $8,%xmm3
+       pslldq  $8,%xmm4
+       pxor    %xmm3,%xmm1
+       pxor    %xmm4,%xmm0
+
+       movdqa  %xmm0,%xmm3
+       psllq   $1,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $5,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $57,%xmm0
+       movdqa  %xmm0,%xmm4
+       pslldq  $8,%xmm0
+       psrldq  $8,%xmm4
+       pxor    %xmm3,%xmm0
+       pxor    %xmm4,%xmm1
+
+
+       movdqa  %xmm0,%xmm4
+       psrlq   $5,%xmm0
+       pxor    %xmm4,%xmm0
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       pxor    %xmm1,%xmm4
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       movdqu  %xmm2,(%rcx)
+       movdqu  %xmm0,16(%rcx)
+       .byte   0xf3,0xc3
+
+.globl gcm_gmult_clmul
+.def   gcm_gmult_clmul;        .scl 2; .type 32;       .endef
+.p2align       4
+gcm_gmult_clmul:
+       movdqu  (%rcx),%xmm0
+       movdqa  .Lbswap_mask(%rip),%xmm5
+       movdqu  (%rdx),%xmm2
+.byte  102,15,56,0,197
+       movdqa  %xmm0,%xmm1
+       pshufd  $78,%xmm0,%xmm3
+       pshufd  $78,%xmm2,%xmm4
+       pxor    %xmm0,%xmm3
+       pxor    %xmm2,%xmm4
+.byte  102,15,58,68,194,0
+.byte  102,15,58,68,202,17
+.byte  102,15,58,68,220,0
+       pxor    %xmm0,%xmm3
+       pxor    %xmm1,%xmm3
+
+       movdqa  %xmm3,%xmm4
+       psrldq  $8,%xmm3
+       pslldq  $8,%xmm4
+       pxor    %xmm3,%xmm1
+       pxor    %xmm4,%xmm0
+
+       movdqa  %xmm0,%xmm3
+       psllq   $1,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $5,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $57,%xmm0
+       movdqa  %xmm0,%xmm4
+       pslldq  $8,%xmm0
+       psrldq  $8,%xmm4
+       pxor    %xmm3,%xmm0
+       pxor    %xmm4,%xmm1
+
+
+       movdqa  %xmm0,%xmm4
+       psrlq   $5,%xmm0
+       pxor    %xmm4,%xmm0
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       pxor    %xmm1,%xmm4
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+.byte  102,15,56,0,197
+       movdqu  %xmm0,(%rcx)
+       .byte   0xf3,0xc3
+
+.globl gcm_ghash_clmul
+.def   gcm_ghash_clmul;        .scl 2; .type 32;       .endef
+.p2align       4
+gcm_ghash_clmul:
+.LSEH_begin_gcm_ghash_clmul:
+
+.byte  0x48,0x83,0xec,0x58             
+.byte  0x0f,0x29,0x34,0x24             
+.byte  0x0f,0x29,0x7c,0x24,0x10        
+.byte  0x44,0x0f,0x29,0x44,0x24,0x20   
+.byte  0x44,0x0f,0x29,0x4c,0x24,0x30   
+.byte  0x44,0x0f,0x29,0x54,0x24,0x40   
+       movdqa  .Lbswap_mask(%rip),%xmm5
+
+       movdqu  (%rcx),%xmm0
+       movdqu  (%rdx),%xmm2
+.byte  102,15,56,0,197
+
+       subq    $16,%r9
+       jz      .Lodd_tail
+
+       movdqu  16(%rdx),%xmm8
+
+
+
+
+
+       movdqu  (%r8),%xmm3
+       movdqu  16(%r8),%xmm6
+.byte  102,15,56,0,221
+.byte  102,15,56,0,245
+       pxor    %xmm3,%xmm0
+       movdqa  %xmm6,%xmm7
+       pshufd  $78,%xmm6,%xmm3
+       pshufd  $78,%xmm2,%xmm4
+       pxor    %xmm6,%xmm3
+       pxor    %xmm2,%xmm4
+.byte  102,15,58,68,242,0
+.byte  102,15,58,68,250,17
+.byte  102,15,58,68,220,0
+       pxor    %xmm6,%xmm3
+       pxor    %xmm7,%xmm3
+
+       movdqa  %xmm3,%xmm4
+       psrldq  $8,%xmm3
+       pslldq  $8,%xmm4
+       pxor    %xmm3,%xmm7
+       pxor    %xmm4,%xmm6
+       movdqa  %xmm0,%xmm1
+       pshufd  $78,%xmm0,%xmm3
+       pshufd  $78,%xmm8,%xmm4
+       pxor    %xmm0,%xmm3
+       pxor    %xmm8,%xmm4
+
+       leaq    32(%r8),%r8
+       subq    $32,%r9
+       jbe     .Leven_tail
+
+.Lmod_loop:
+.byte  102,65,15,58,68,192,0
+.byte  102,65,15,58,68,200,17
+.byte  102,15,58,68,220,0
+       pxor    %xmm0,%xmm3
+       pxor    %xmm1,%xmm3
+
+       movdqa  %xmm3,%xmm4
+       psrldq  $8,%xmm3
+       pslldq  $8,%xmm4
+       pxor    %xmm3,%xmm1
+       pxor    %xmm4,%xmm0
+       movdqu  (%r8),%xmm3
+       pxor    %xmm6,%xmm0
+       pxor    %xmm7,%xmm1
+
+       movdqu  16(%r8),%xmm6
+.byte  102,15,56,0,221
+.byte  102,15,56,0,245
+
+       movdqa  %xmm6,%xmm7
+       pshufd  $78,%xmm6,%xmm9
+       pshufd  $78,%xmm2,%xmm10
+       pxor    %xmm6,%xmm9
+       pxor    %xmm2,%xmm10
+       pxor    %xmm3,%xmm1
+
+       movdqa  %xmm0,%xmm3
+       psllq   $1,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $5,%xmm0
+       pxor    %xmm3,%xmm0
+.byte  102,15,58,68,242,0
+       psllq   $57,%xmm0
+       movdqa  %xmm0,%xmm4
+       pslldq  $8,%xmm0
+       psrldq  $8,%xmm4
+       pxor    %xmm3,%xmm0
+       pxor    %xmm4,%xmm1
+
+.byte  102,15,58,68,250,17
+       movdqa  %xmm0,%xmm4
+       psrlq   $5,%xmm0
+       pxor    %xmm4,%xmm0
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       pxor    %xmm1,%xmm4
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+
+.byte  102,69,15,58,68,202,0
+       movdqa  %xmm0,%xmm1
+       pshufd  $78,%xmm0,%xmm3
+       pshufd  $78,%xmm8,%xmm4
+       pxor    %xmm0,%xmm3
+       pxor    %xmm8,%xmm4
+
+       pxor    %xmm6,%xmm9
+       pxor    %xmm7,%xmm9
+       movdqa  %xmm9,%xmm10
+       psrldq  $8,%xmm9
+       pslldq  $8,%xmm10
+       pxor    %xmm9,%xmm7
+       pxor    %xmm10,%xmm6
+
+       leaq    32(%r8),%r8
+       subq    $32,%r9
+       ja      .Lmod_loop
+
+.Leven_tail:
+.byte  102,65,15,58,68,192,0
+.byte  102,65,15,58,68,200,17
+.byte  102,15,58,68,220,0
+       pxor    %xmm0,%xmm3
+       pxor    %xmm1,%xmm3
+
+       movdqa  %xmm3,%xmm4
+       psrldq  $8,%xmm3
+       pslldq  $8,%xmm4
+       pxor    %xmm3,%xmm1
+       pxor    %xmm4,%xmm0
+       pxor    %xmm6,%xmm0
+       pxor    %xmm7,%xmm1
+
+       movdqa  %xmm0,%xmm3
+       psllq   $1,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $5,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $57,%xmm0
+       movdqa  %xmm0,%xmm4
+       pslldq  $8,%xmm0
+       psrldq  $8,%xmm4
+       pxor    %xmm3,%xmm0
+       pxor    %xmm4,%xmm1
+
+
+       movdqa  %xmm0,%xmm4
+       psrlq   $5,%xmm0
+       pxor    %xmm4,%xmm0
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       pxor    %xmm1,%xmm4
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       testq   %r9,%r9
+       jnz     .Ldone
+
+.Lodd_tail:
+       movdqu  (%r8),%xmm3
+.byte  102,15,56,0,221
+       pxor    %xmm3,%xmm0
+       movdqa  %xmm0,%xmm1
+       pshufd  $78,%xmm0,%xmm3
+       pshufd  $78,%xmm2,%xmm4
+       pxor    %xmm0,%xmm3
+       pxor    %xmm2,%xmm4
+.byte  102,15,58,68,194,0
+.byte  102,15,58,68,202,17
+.byte  102,15,58,68,220,0
+       pxor    %xmm0,%xmm3
+       pxor    %xmm1,%xmm3
+
+       movdqa  %xmm3,%xmm4
+       psrldq  $8,%xmm3
+       pslldq  $8,%xmm4
+       pxor    %xmm3,%xmm1
+       pxor    %xmm4,%xmm0
+
+       movdqa  %xmm0,%xmm3
+       psllq   $1,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $5,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $57,%xmm0
+       movdqa  %xmm0,%xmm4
+       pslldq  $8,%xmm0
+       psrldq  $8,%xmm4
+       pxor    %xmm3,%xmm0
+       pxor    %xmm4,%xmm1
+
+
+       movdqa  %xmm0,%xmm4
+       psrlq   $5,%xmm0
+       pxor    %xmm4,%xmm0
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       pxor    %xmm1,%xmm4
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+.Ldone:
+.byte  102,15,56,0,197
+       movdqu  %xmm0,(%rcx)
+       movaps  (%rsp),%xmm6
+       movaps  16(%rsp),%xmm7
+       movaps  32(%rsp),%xmm8
+       movaps  48(%rsp),%xmm9
+       movaps  64(%rsp),%xmm10
+       addq    $88,%rsp
+       .byte   0xf3,0xc3
+.LSEH_end_gcm_ghash_clmul:
+
+.p2align       6
+.Lbswap_mask:
+.byte  15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
+.L0x1c2_polynomial:
+.byte  1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xc2
+.p2align       6
+
+.Lrem_4bit:
+.long  0,0,0,471859200,0,943718400,0,610271232
+.long  0,1887436800,0,1822425088,0,1220542464,0,1423966208
+.long  0,3774873600,0,4246732800,0,3644850176,0,3311403008
+.long  0,2441084928,0,2376073216,0,2847932416,0,3051356160
+
+.Lrem_8bit:
+.value 0x0000,0x01C2,0x0384,0x0246,0x0708,0x06CA,0x048C,0x054E
+.value 0x0E10,0x0FD2,0x0D94,0x0C56,0x0918,0x08DA,0x0A9C,0x0B5E
+.value 0x1C20,0x1DE2,0x1FA4,0x1E66,0x1B28,0x1AEA,0x18AC,0x196E
+.value 0x1230,0x13F2,0x11B4,0x1076,0x1538,0x14FA,0x16BC,0x177E
+.value 0x3840,0x3982,0x3BC4,0x3A06,0x3F48,0x3E8A,0x3CCC,0x3D0E
+.value 0x3650,0x3792,0x35D4,0x3416,0x3158,0x309A,0x32DC,0x331E
+.value 0x2460,0x25A2,0x27E4,0x2626,0x2368,0x22AA,0x20EC,0x212E
+.value 0x2A70,0x2BB2,0x29F4,0x2836,0x2D78,0x2CBA,0x2EFC,0x2F3E
+.value 0x7080,0x7142,0x7304,0x72C6,0x7788,0x764A,0x740C,0x75CE
+.value 0x7E90,0x7F52,0x7D14,0x7CD6,0x7998,0x785A,0x7A1C,0x7BDE
+.value 0x6CA0,0x6D62,0x6F24,0x6EE6,0x6BA8,0x6A6A,0x682C,0x69EE
+.value 0x62B0,0x6372,0x6134,0x60F6,0x65B8,0x647A,0x663C,0x67FE
+.value 0x48C0,0x4902,0x4B44,0x4A86,0x4FC8,0x4E0A,0x4C4C,0x4D8E
+.value 0x46D0,0x4712,0x4554,0x4496,0x41D8,0x401A,0x425C,0x439E
+.value 0x54E0,0x5522,0x5764,0x56A6,0x53E8,0x522A,0x506C,0x51AE
+.value 0x5AF0,0x5B32,0x5974,0x58B6,0x5DF8,0x5C3A,0x5E7C,0x5FBE
+.value 0xE100,0xE0C2,0xE284,0xE346,0xE608,0xE7CA,0xE58C,0xE44E
+.value 0xEF10,0xEED2,0xEC94,0xED56,0xE818,0xE9DA,0xEB9C,0xEA5E
+.value 0xFD20,0xFCE2,0xFEA4,0xFF66,0xFA28,0xFBEA,0xF9AC,0xF86E
+.value 0xF330,0xF2F2,0xF0B4,0xF176,0xF438,0xF5FA,0xF7BC,0xF67E
+.value 0xD940,0xD882,0xDAC4,0xDB06,0xDE48,0xDF8A,0xDDCC,0xDC0E
+.value 0xD750,0xD692,0xD4D4,0xD516,0xD058,0xD19A,0xD3DC,0xD21E
+.value 0xC560,0xC4A2,0xC6E4,0xC726,0xC268,0xC3AA,0xC1EC,0xC02E
+.value 0xCB70,0xCAB2,0xC8F4,0xC936,0xCC78,0xCDBA,0xCFFC,0xCE3E
+.value 0x9180,0x9042,0x9204,0x93C6,0x9688,0x974A,0x950C,0x94CE
+.value 0x9F90,0x9E52,0x9C14,0x9DD6,0x9898,0x995A,0x9B1C,0x9ADE
+.value 0x8DA0,0x8C62,0x8E24,0x8FE6,0x8AA8,0x8B6A,0x892C,0x88EE
+.value 0x83B0,0x8272,0x8034,0x81F6,0x84B8,0x857A,0x873C,0x86FE
+.value 0xA9C0,0xA802,0xAA44,0xAB86,0xAEC8,0xAF0A,0xAD4C,0xAC8E
+.value 0xA7D0,0xA612,0xA454,0xA596,0xA0D8,0xA11A,0xA35C,0xA29E
+.value 0xB5E0,0xB422,0xB664,0xB7A6,0xB2E8,0xB32A,0xB16C,0xB0AE
+.value 0xBBF0,0xBA32,0xB874,0xB9B6,0xBCF8,0xBD3A,0xBF7C,0xBEBE
+
+.byte  
71,72,65,83,72,32,102,111,114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
+.p2align       6
+
+.def   se_handler;     .scl 3; .type 32;       .endef
+.p2align       4
+se_handler:
+       pushq   %rsi
+       pushq   %rdi
+       pushq   %rbx
+       pushq   %rbp
+       pushq   %r12
+       pushq   %r13
+       pushq   %r14
+       pushq   %r15
+       pushfq
+       subq    $64,%rsp
+
+       movq    120(%r8),%rax
+       movq    248(%r8),%rbx
+
+       movq    8(%r9),%rsi
+       movq    56(%r9),%r11
+
+       movl    0(%r11),%r10d
+       leaq    (%rsi,%r10,1),%r10
+       cmpq    %r10,%rbx
+       jb      .Lin_prologue
+
+       movq    152(%r8),%rax
+
+       movl    4(%r11),%r10d
+       leaq    (%rsi,%r10,1),%r10
+       cmpq    %r10,%rbx
+       jae     .Lin_prologue
+
+       leaq    24(%rax),%rax
+
+       movq    -8(%rax),%rbx
+       movq    -16(%rax),%rbp
+       movq    -24(%rax),%r12
+       movq    %rbx,144(%r8)
+       movq    %rbp,160(%r8)
+       movq    %r12,216(%r8)
+
+.Lin_prologue:
+       movq    8(%rax),%rdi
+       movq    16(%rax),%rsi
+       movq    %rax,152(%r8)
+       movq    %rsi,168(%r8)
+       movq    %rdi,176(%r8)
+
+       movq    40(%r9),%rdi
+       movq    %r8,%rsi
+       movl    $154,%ecx
+.long  0xa548f3fc              
+
+       movq    %r9,%rsi
+       xorq    %rcx,%rcx
+       movq    8(%rsi),%rdx
+       movq    0(%rsi),%r8
+       movq    16(%rsi),%r9
+       movq    40(%rsi),%r10
+       leaq    56(%rsi),%r11
+       leaq    24(%rsi),%r12
+       movq    %r10,32(%rsp)
+       movq    %r11,40(%rsp)
+       movq    %r12,48(%rsp)
+       movq    %rcx,56(%rsp)
+       call    *__imp_RtlVirtualUnwind(%rip)
+
+       movl    $1,%eax
+       addq    $64,%rsp
+       popfq
+       popq    %r15
+       popq    %r14
+       popq    %r13
+       popq    %r12
+       popq    %rbp
+       popq    %rbx
+       popq    %rdi
+       popq    %rsi
+       .byte   0xf3,0xc3
+
+
+.section       .pdata
+.p2align       2
+.rva   .LSEH_begin_gcm_gmult_4bit
+.rva   .LSEH_end_gcm_gmult_4bit
+.rva   .LSEH_info_gcm_gmult_4bit
+
+.rva   .LSEH_begin_gcm_ghash_4bit
+.rva   .LSEH_end_gcm_ghash_4bit
+.rva   .LSEH_info_gcm_ghash_4bit
+
+.rva   .LSEH_begin_gcm_ghash_clmul
+.rva   .LSEH_end_gcm_ghash_clmul
+.rva   .LSEH_info_gcm_ghash_clmul
+
+.section       .xdata
+.p2align       3
+.LSEH_info_gcm_gmult_4bit:
+.byte  9,0,0,0
+.rva   se_handler
+.rva   .Lgmult_prologue,.Lgmult_epilogue       
+.LSEH_info_gcm_ghash_4bit:
+.byte  9,0,0,0
+.rva   se_handler
+.rva   .Lghash_prologue,.Lghash_epilogue       
+.LSEH_info_gcm_ghash_clmul:
+.byte  0x01,0x1f,0x0b,0x00
+.byte  0x1f,0xa8,0x04,0x00     
+.byte  0x19,0x98,0x03,0x00     
+.byte  0x13,0x88,0x02,0x00     
+.byte  0x0d,0x78,0x01,0x00     
+.byte  0x08,0x68,0x00,0x00     
+.byte  0x04,0xa2,0x00,0x00     
diff --git a/lib/accelerated/x86/asm-coff/appro-aes-x86-64-coff.s 
b/lib/accelerated/x86/asm-coff/appro-aes-x86-64-coff.s
new file mode 100644
index 0000000..5a69465
--- /dev/null
+++ b/lib/accelerated/x86/asm-coff/appro-aes-x86-64-coff.s
@@ -0,0 +1,3044 @@
+# Copyright (c) 2011, Andy Polyakov by <address@hidden>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 
+#     * Redistributions of source code must retain copyright notices,
+#      this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+#
+#     * Neither the name of the Andy Polyakov nor the names of its
+#      copyright holder and contributors may be used to endorse or
+#      promote products derived from this software without specific
+#      prior written permission.
+#
+# ALTERNATIVELY, provided that this notice is retained in full, this
+# product may be distributed under the terms of the GNU General Public
+# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+# those given above.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.text  
+.globl aesni_encrypt
+.def   aesni_encrypt;  .scl 2; .type 32;       .endef
+.p2align       4
+aesni_encrypt:
+       movups  (%rcx),%xmm2
+       movl    240(%r8),%eax
+       movups  (%r8),%xmm0
+       movups  16(%r8),%xmm1
+       leaq    32(%r8),%r8
+       xorps   %xmm0,%xmm2
+.Loop_enc1_1:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%r8),%xmm1
+       leaq    16(%r8),%r8
+       jnz     .Loop_enc1_1    
+.byte  102,15,56,221,209
+       movups  %xmm2,(%rdx)
+       .byte   0xf3,0xc3
+
+
+.globl aesni_decrypt
+.def   aesni_decrypt;  .scl 2; .type 32;       .endef
+.p2align       4
+aesni_decrypt:
+       movups  (%rcx),%xmm2
+       movl    240(%r8),%eax
+       movups  (%r8),%xmm0
+       movups  16(%r8),%xmm1
+       leaq    32(%r8),%r8
+       xorps   %xmm0,%xmm2
+.Loop_dec1_2:
+.byte  102,15,56,222,209
+       decl    %eax
+       movups  (%r8),%xmm1
+       leaq    16(%r8),%r8
+       jnz     .Loop_dec1_2    
+.byte  102,15,56,223,209
+       movups  %xmm2,(%rdx)
+       .byte   0xf3,0xc3
+
+.def   _aesni_encrypt3;        .scl 3; .type 32;       .endef
+.p2align       4
+_aesni_encrypt3:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm0,%xmm3
+       xorps   %xmm0,%xmm4
+       movups  (%rcx),%xmm0
+
+.Lenc_loop3:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %eax
+.byte  102,15,56,220,225
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,224
+       movups  (%rcx),%xmm0
+       jnz     .Lenc_loop3
+
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+       .byte   0xf3,0xc3
+
+.def   _aesni_decrypt3;        .scl 3; .type 32;       .endef
+.p2align       4
+_aesni_decrypt3:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm0,%xmm3
+       xorps   %xmm0,%xmm4
+       movups  (%rcx),%xmm0
+
+.Ldec_loop3:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %eax
+.byte  102,15,56,222,225
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,222,224
+       movups  (%rcx),%xmm0
+       jnz     .Ldec_loop3
+
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+       .byte   0xf3,0xc3
+
+.def   _aesni_encrypt4;        .scl 3; .type 32;       .endef
+.p2align       4
+_aesni_encrypt4:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm0,%xmm3
+       xorps   %xmm0,%xmm4
+       xorps   %xmm0,%xmm5
+       movups  (%rcx),%xmm0
+
+.Lenc_loop4:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %eax
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+       movups  (%rcx),%xmm0
+       jnz     .Lenc_loop4
+
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+.byte  102,15,56,221,232
+       .byte   0xf3,0xc3
+
+.def   _aesni_decrypt4;        .scl 3; .type 32;       .endef
+.p2align       4
+_aesni_decrypt4:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm0,%xmm3
+       xorps   %xmm0,%xmm4
+       xorps   %xmm0,%xmm5
+       movups  (%rcx),%xmm0
+
+.Ldec_loop4:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %eax
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,222,224
+.byte  102,15,56,222,232
+       movups  (%rcx),%xmm0
+       jnz     .Ldec_loop4
+
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+.byte  102,15,56,223,232
+       .byte   0xf3,0xc3
+
+.def   _aesni_encrypt6;        .scl 3; .type 32;       .endef
+.p2align       4
+_aesni_encrypt6:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+.byte  102,15,56,220,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,220,217
+       pxor    %xmm0,%xmm5
+.byte  102,15,56,220,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+       decl    %eax
+.byte  102,15,56,220,241
+       movups  (%rcx),%xmm0
+.byte  102,15,56,220,249
+       jmp     .Lenc_loop6_enter
+.p2align       4
+.Lenc_loop6:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %eax
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.Lenc_loop6_enter:
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+.byte  102,15,56,220,240
+.byte  102,15,56,220,248
+       movups  (%rcx),%xmm0
+       jnz     .Lenc_loop6
+
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+.byte  102,15,56,221,232
+.byte  102,15,56,221,240
+.byte  102,15,56,221,248
+       .byte   0xf3,0xc3
+
+.def   _aesni_decrypt6;        .scl 3; .type 32;       .endef
+.p2align       4
+_aesni_decrypt6:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+.byte  102,15,56,222,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,222,217
+       pxor    %xmm0,%xmm5
+.byte  102,15,56,222,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,222,233
+       pxor    %xmm0,%xmm7
+       decl    %eax
+.byte  102,15,56,222,241
+       movups  (%rcx),%xmm0
+.byte  102,15,56,222,249
+       jmp     .Ldec_loop6_enter
+.p2align       4
+.Ldec_loop6:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %eax
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.Ldec_loop6_enter:
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,222,224
+.byte  102,15,56,222,232
+.byte  102,15,56,222,240
+.byte  102,15,56,222,248
+       movups  (%rcx),%xmm0
+       jnz     .Ldec_loop6
+
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+.byte  102,15,56,223,232
+.byte  102,15,56,223,240
+.byte  102,15,56,223,248
+       .byte   0xf3,0xc3
+
+.def   _aesni_encrypt8;        .scl 3; .type 32;       .endef
+.p2align       4
+_aesni_encrypt8:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm0,%xmm3
+.byte  102,15,56,220,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,220,217
+       pxor    %xmm0,%xmm5
+.byte  102,15,56,220,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+       decl    %eax
+.byte  102,15,56,220,241
+       pxor    %xmm0,%xmm8
+.byte  102,15,56,220,249
+       pxor    %xmm0,%xmm9
+       movups  (%rcx),%xmm0
+.byte  102,68,15,56,220,193
+.byte  102,68,15,56,220,201
+       movups  16(%rcx),%xmm1
+       jmp     .Lenc_loop8_enter
+.p2align       4
+.Lenc_loop8:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %eax
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.byte  102,68,15,56,220,193
+.byte  102,68,15,56,220,201
+       movups  16(%rcx),%xmm1
+.Lenc_loop8_enter:
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+.byte  102,15,56,220,240
+.byte  102,15,56,220,248
+.byte  102,68,15,56,220,192
+.byte  102,68,15,56,220,200
+       movups  (%rcx),%xmm0
+       jnz     .Lenc_loop8
+
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.byte  102,68,15,56,220,193
+.byte  102,68,15,56,220,201
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+.byte  102,15,56,221,232
+.byte  102,15,56,221,240
+.byte  102,15,56,221,248
+.byte  102,68,15,56,221,192
+.byte  102,68,15,56,221,200
+       .byte   0xf3,0xc3
+
+.def   _aesni_decrypt8;        .scl 3; .type 32;       .endef
+.p2align       4
+_aesni_decrypt8:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm0,%xmm3
+.byte  102,15,56,222,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,222,217
+       pxor    %xmm0,%xmm5
+.byte  102,15,56,222,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,222,233
+       pxor    %xmm0,%xmm7
+       decl    %eax
+.byte  102,15,56,222,241
+       pxor    %xmm0,%xmm8
+.byte  102,15,56,222,249
+       pxor    %xmm0,%xmm9
+       movups  (%rcx),%xmm0
+.byte  102,68,15,56,222,193
+.byte  102,68,15,56,222,201
+       movups  16(%rcx),%xmm1
+       jmp     .Ldec_loop8_enter
+.p2align       4
+.Ldec_loop8:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %eax
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.byte  102,68,15,56,222,193
+.byte  102,68,15,56,222,201
+       movups  16(%rcx),%xmm1
+.Ldec_loop8_enter:
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,222,224
+.byte  102,15,56,222,232
+.byte  102,15,56,222,240
+.byte  102,15,56,222,248
+.byte  102,68,15,56,222,192
+.byte  102,68,15,56,222,200
+       movups  (%rcx),%xmm0
+       jnz     .Ldec_loop8
+
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.byte  102,68,15,56,222,193
+.byte  102,68,15,56,222,201
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+.byte  102,15,56,223,232
+.byte  102,15,56,223,240
+.byte  102,15,56,223,248
+.byte  102,68,15,56,223,192
+.byte  102,68,15,56,223,200
+       .byte   0xf3,0xc3
+
+.globl aesni_ecb_encrypt
+.def   aesni_ecb_encrypt;      .scl 2; .type 32;       .endef
+.p2align       4
+aesni_ecb_encrypt:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_aesni_ecb_encrypt:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+       movq    %r9,%rcx
+       movq    40(%rsp),%r8
+
+       andq    $-16,%rdx
+       jz      .Lecb_ret
+
+       movl    240(%rcx),%eax
+       movups  (%rcx),%xmm0
+       movq    %rcx,%r11
+       movl    %eax,%r10d
+       testl   %r8d,%r8d
+       jz      .Lecb_decrypt
+
+       cmpq    $128,%rdx
+       jb      .Lecb_enc_tail
+
+       movdqu  (%rdi),%xmm2
+       movdqu  16(%rdi),%xmm3
+       movdqu  32(%rdi),%xmm4
+       movdqu  48(%rdi),%xmm5
+       movdqu  64(%rdi),%xmm6
+       movdqu  80(%rdi),%xmm7
+       movdqu  96(%rdi),%xmm8
+       movdqu  112(%rdi),%xmm9
+       leaq    128(%rdi),%rdi
+       subq    $128,%rdx
+       jmp     .Lecb_enc_loop8_enter
+.p2align       4
+.Lecb_enc_loop8:
+       movups  %xmm2,(%rsi)
+       movq    %r11,%rcx
+       movdqu  (%rdi),%xmm2
+       movl    %r10d,%eax
+       movups  %xmm3,16(%rsi)
+       movdqu  16(%rdi),%xmm3
+       movups  %xmm4,32(%rsi)
+       movdqu  32(%rdi),%xmm4
+       movups  %xmm5,48(%rsi)
+       movdqu  48(%rdi),%xmm5
+       movups  %xmm6,64(%rsi)
+       movdqu  64(%rdi),%xmm6
+       movups  %xmm7,80(%rsi)
+       movdqu  80(%rdi),%xmm7
+       movups  %xmm8,96(%rsi)
+       movdqu  96(%rdi),%xmm8
+       movups  %xmm9,112(%rsi)
+       leaq    128(%rsi),%rsi
+       movdqu  112(%rdi),%xmm9
+       leaq    128(%rdi),%rdi
+.Lecb_enc_loop8_enter:
+
+       call    _aesni_encrypt8
+
+       subq    $128,%rdx
+       jnc     .Lecb_enc_loop8
+
+       movups  %xmm2,(%rsi)
+       movq    %r11,%rcx
+       movups  %xmm3,16(%rsi)
+       movl    %r10d,%eax
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       movups  %xmm8,96(%rsi)
+       movups  %xmm9,112(%rsi)
+       leaq    128(%rsi),%rsi
+       addq    $128,%rdx
+       jz      .Lecb_ret
+
+.Lecb_enc_tail:
+       movups  (%rdi),%xmm2
+       cmpq    $32,%rdx
+       jb      .Lecb_enc_one
+       movups  16(%rdi),%xmm3
+       je      .Lecb_enc_two
+       movups  32(%rdi),%xmm4
+       cmpq    $64,%rdx
+       jb      .Lecb_enc_three
+       movups  48(%rdi),%xmm5
+       je      .Lecb_enc_four
+       movups  64(%rdi),%xmm6
+       cmpq    $96,%rdx
+       jb      .Lecb_enc_five
+       movups  80(%rdi),%xmm7
+       je      .Lecb_enc_six
+       movdqu  96(%rdi),%xmm8
+       call    _aesni_encrypt8
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       movups  %xmm8,96(%rsi)
+       jmp     .Lecb_ret
+.p2align       4
+.Lecb_enc_one:
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_enc1_3:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_enc1_3    
+.byte  102,15,56,221,209
+       movups  %xmm2,(%rsi)
+       jmp     .Lecb_ret
+.p2align       4
+.Lecb_enc_two:
+       xorps   %xmm4,%xmm4
+       call    _aesni_encrypt3
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       jmp     .Lecb_ret
+.p2align       4
+.Lecb_enc_three:
+       call    _aesni_encrypt3
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       jmp     .Lecb_ret
+.p2align       4
+.Lecb_enc_four:
+       call    _aesni_encrypt4
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       jmp     .Lecb_ret
+.p2align       4
+.Lecb_enc_five:
+       xorps   %xmm7,%xmm7
+       call    _aesni_encrypt6
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       jmp     .Lecb_ret
+.p2align       4
+.Lecb_enc_six:
+       call    _aesni_encrypt6
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       jmp     .Lecb_ret
+
+.p2align       4
+.Lecb_decrypt:
+       cmpq    $128,%rdx
+       jb      .Lecb_dec_tail
+
+       movdqu  (%rdi),%xmm2
+       movdqu  16(%rdi),%xmm3
+       movdqu  32(%rdi),%xmm4
+       movdqu  48(%rdi),%xmm5
+       movdqu  64(%rdi),%xmm6
+       movdqu  80(%rdi),%xmm7
+       movdqu  96(%rdi),%xmm8
+       movdqu  112(%rdi),%xmm9
+       leaq    128(%rdi),%rdi
+       subq    $128,%rdx
+       jmp     .Lecb_dec_loop8_enter
+.p2align       4
+.Lecb_dec_loop8:
+       movups  %xmm2,(%rsi)
+       movq    %r11,%rcx
+       movdqu  (%rdi),%xmm2
+       movl    %r10d,%eax
+       movups  %xmm3,16(%rsi)
+       movdqu  16(%rdi),%xmm3
+       movups  %xmm4,32(%rsi)
+       movdqu  32(%rdi),%xmm4
+       movups  %xmm5,48(%rsi)
+       movdqu  48(%rdi),%xmm5
+       movups  %xmm6,64(%rsi)
+       movdqu  64(%rdi),%xmm6
+       movups  %xmm7,80(%rsi)
+       movdqu  80(%rdi),%xmm7
+       movups  %xmm8,96(%rsi)
+       movdqu  96(%rdi),%xmm8
+       movups  %xmm9,112(%rsi)
+       leaq    128(%rsi),%rsi
+       movdqu  112(%rdi),%xmm9
+       leaq    128(%rdi),%rdi
+.Lecb_dec_loop8_enter:
+
+       call    _aesni_decrypt8
+
+       movups  (%r11),%xmm0
+       subq    $128,%rdx
+       jnc     .Lecb_dec_loop8
+
+       movups  %xmm2,(%rsi)
+       movq    %r11,%rcx
+       movups  %xmm3,16(%rsi)
+       movl    %r10d,%eax
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       movups  %xmm8,96(%rsi)
+       movups  %xmm9,112(%rsi)
+       leaq    128(%rsi),%rsi
+       addq    $128,%rdx
+       jz      .Lecb_ret
+
+.Lecb_dec_tail:
+       movups  (%rdi),%xmm2
+       cmpq    $32,%rdx
+       jb      .Lecb_dec_one
+       movups  16(%rdi),%xmm3
+       je      .Lecb_dec_two
+       movups  32(%rdi),%xmm4
+       cmpq    $64,%rdx
+       jb      .Lecb_dec_three
+       movups  48(%rdi),%xmm5
+       je      .Lecb_dec_four
+       movups  64(%rdi),%xmm6
+       cmpq    $96,%rdx
+       jb      .Lecb_dec_five
+       movups  80(%rdi),%xmm7
+       je      .Lecb_dec_six
+       movups  96(%rdi),%xmm8
+       movups  (%rcx),%xmm0
+       call    _aesni_decrypt8
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       movups  %xmm8,96(%rsi)
+       jmp     .Lecb_ret
+.p2align       4
+.Lecb_dec_one:
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_dec1_4:
+.byte  102,15,56,222,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_dec1_4    
+.byte  102,15,56,223,209
+       movups  %xmm2,(%rsi)
+       jmp     .Lecb_ret
+.p2align       4
+.Lecb_dec_two:
+       xorps   %xmm4,%xmm4
+       call    _aesni_decrypt3
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       jmp     .Lecb_ret
+.p2align       4
+.Lecb_dec_three:
+       call    _aesni_decrypt3
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       jmp     .Lecb_ret
+.p2align       4
+.Lecb_dec_four:
+       call    _aesni_decrypt4
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       jmp     .Lecb_ret
+.p2align       4
+.Lecb_dec_five:
+       xorps   %xmm7,%xmm7
+       call    _aesni_decrypt6
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       jmp     .Lecb_ret
+.p2align       4
+.Lecb_dec_six:
+       call    _aesni_decrypt6
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+
+.Lecb_ret:
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_aesni_ecb_encrypt:
+.globl aesni_ccm64_encrypt_blocks
+.def   aesni_ccm64_encrypt_blocks;     .scl 2; .type 32;       .endef
+.p2align       4
+aesni_ccm64_encrypt_blocks:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_aesni_ccm64_encrypt_blocks:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+       movq    %r9,%rcx
+       movq    40(%rsp),%r8
+       movq    48(%rsp),%r9
+
+       leaq    -88(%rsp),%rsp
+       movaps  %xmm6,(%rsp)
+       movaps  %xmm7,16(%rsp)
+       movaps  %xmm8,32(%rsp)
+       movaps  %xmm9,48(%rsp)
+.Lccm64_enc_body:
+       movl    240(%rcx),%eax
+       movdqu  (%r8),%xmm9
+       movdqa  .Lincrement64(%rip),%xmm6
+       movdqa  .Lbswap_mask(%rip),%xmm7
+
+       shrl    $1,%eax
+       leaq    0(%rcx),%r11
+       movdqu  (%r9),%xmm3
+       movdqa  %xmm9,%xmm2
+       movl    %eax,%r10d
+.byte  102,68,15,56,0,207
+       jmp     .Lccm64_enc_outer
+.p2align       4
+.Lccm64_enc_outer:
+       movups  (%r11),%xmm0
+       movl    %r10d,%eax
+       movups  (%rdi),%xmm8
+
+       xorps   %xmm0,%xmm2
+       movups  16(%r11),%xmm1
+       xorps   %xmm8,%xmm0
+       leaq    32(%r11),%rcx
+       xorps   %xmm0,%xmm3
+       movups  (%rcx),%xmm0
+
+.Lccm64_enc2_loop:
+.byte  102,15,56,220,209
+       decl    %eax
+.byte  102,15,56,220,217
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,216
+       movups  0(%rcx),%xmm0
+       jnz     .Lccm64_enc2_loop
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       paddq   %xmm6,%xmm9
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+
+       decq    %rdx
+       leaq    16(%rdi),%rdi
+       xorps   %xmm2,%xmm8
+       movdqa  %xmm9,%xmm2
+       movups  %xmm8,(%rsi)
+       leaq    16(%rsi),%rsi
+.byte  102,15,56,0,215
+       jnz     .Lccm64_enc_outer
+
+       movups  %xmm3,(%r9)
+       movaps  (%rsp),%xmm6
+       movaps  16(%rsp),%xmm7
+       movaps  32(%rsp),%xmm8
+       movaps  48(%rsp),%xmm9
+       leaq    88(%rsp),%rsp
+.Lccm64_enc_ret:
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_aesni_ccm64_encrypt_blocks:
+.globl aesni_ccm64_decrypt_blocks
+.def   aesni_ccm64_decrypt_blocks;     .scl 2; .type 32;       .endef
+.p2align       4
+aesni_ccm64_decrypt_blocks:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_aesni_ccm64_decrypt_blocks:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+       movq    %r9,%rcx
+       movq    40(%rsp),%r8
+       movq    48(%rsp),%r9
+
+       leaq    -88(%rsp),%rsp
+       movaps  %xmm6,(%rsp)
+       movaps  %xmm7,16(%rsp)
+       movaps  %xmm8,32(%rsp)
+       movaps  %xmm9,48(%rsp)
+.Lccm64_dec_body:
+       movl    240(%rcx),%eax
+       movups  (%r8),%xmm9
+       movdqu  (%r9),%xmm3
+       movdqa  .Lincrement64(%rip),%xmm6
+       movdqa  .Lbswap_mask(%rip),%xmm7
+
+       movaps  %xmm9,%xmm2
+       movl    %eax,%r10d
+       movq    %rcx,%r11
+.byte  102,68,15,56,0,207
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_enc1_5:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_enc1_5    
+.byte  102,15,56,221,209
+       movups  (%rdi),%xmm8
+       paddq   %xmm6,%xmm9
+       leaq    16(%rdi),%rdi
+       jmp     .Lccm64_dec_outer
+.p2align       4
+.Lccm64_dec_outer:
+       xorps   %xmm2,%xmm8
+       movdqa  %xmm9,%xmm2
+       movl    %r10d,%eax
+       movups  %xmm8,(%rsi)
+       leaq    16(%rsi),%rsi
+.byte  102,15,56,0,215
+
+       subq    $1,%rdx
+       jz      .Lccm64_dec_break
+
+       movups  (%r11),%xmm0
+       shrl    $1,%eax
+       movups  16(%r11),%xmm1
+       xorps   %xmm0,%xmm8
+       leaq    32(%r11),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm8,%xmm3
+       movups  (%rcx),%xmm0
+
+.Lccm64_dec2_loop:
+.byte  102,15,56,220,209
+       decl    %eax
+.byte  102,15,56,220,217
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,216
+       movups  0(%rcx),%xmm0
+       jnz     .Lccm64_dec2_loop
+       movups  (%rdi),%xmm8
+       paddq   %xmm6,%xmm9
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       leaq    16(%rdi),%rdi
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+       jmp     .Lccm64_dec_outer
+
+.p2align       4
+.Lccm64_dec_break:
+
+       movups  (%r11),%xmm0
+       movups  16(%r11),%xmm1
+       xorps   %xmm0,%xmm8
+       leaq    32(%r11),%r11
+       xorps   %xmm8,%xmm3
+.Loop_enc1_6:
+.byte  102,15,56,220,217
+       decl    %eax
+       movups  (%r11),%xmm1
+       leaq    16(%r11),%r11
+       jnz     .Loop_enc1_6    
+.byte  102,15,56,221,217
+       movups  %xmm3,(%r9)
+       movaps  (%rsp),%xmm6
+       movaps  16(%rsp),%xmm7
+       movaps  32(%rsp),%xmm8
+       movaps  48(%rsp),%xmm9
+       leaq    88(%rsp),%rsp
+.Lccm64_dec_ret:
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_aesni_ccm64_decrypt_blocks:
+.globl aesni_ctr32_encrypt_blocks
+.def   aesni_ctr32_encrypt_blocks;     .scl 2; .type 32;       .endef
+.p2align       4
+aesni_ctr32_encrypt_blocks:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_aesni_ctr32_encrypt_blocks:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+       movq    %r9,%rcx
+       movq    40(%rsp),%r8
+
+       leaq    -200(%rsp),%rsp
+       movaps  %xmm6,32(%rsp)
+       movaps  %xmm7,48(%rsp)
+       movaps  %xmm8,64(%rsp)
+       movaps  %xmm9,80(%rsp)
+       movaps  %xmm10,96(%rsp)
+       movaps  %xmm11,112(%rsp)
+       movaps  %xmm12,128(%rsp)
+       movaps  %xmm13,144(%rsp)
+       movaps  %xmm14,160(%rsp)
+       movaps  %xmm15,176(%rsp)
+.Lctr32_body:
+       cmpq    $1,%rdx
+       je      .Lctr32_one_shortcut
+
+       movdqu  (%r8),%xmm14
+       movdqa  .Lbswap_mask(%rip),%xmm15
+       xorl    %eax,%eax
+.byte  102,69,15,58,22,242,3
+.byte  102,68,15,58,34,240,3
+
+       movl    240(%rcx),%eax
+       bswapl  %r10d
+       pxor    %xmm12,%xmm12
+       pxor    %xmm13,%xmm13
+.byte  102,69,15,58,34,226,0
+       leaq    3(%r10),%r11
+.byte  102,69,15,58,34,235,0
+       incl    %r10d
+.byte  102,69,15,58,34,226,1
+       incq    %r11
+.byte  102,69,15,58,34,235,1
+       incl    %r10d
+.byte  102,69,15,58,34,226,2
+       incq    %r11
+.byte  102,69,15,58,34,235,2
+       movdqa  %xmm12,0(%rsp)
+.byte  102,69,15,56,0,231
+       movdqa  %xmm13,16(%rsp)
+.byte  102,69,15,56,0,239
+
+       pshufd  $192,%xmm12,%xmm2
+       pshufd  $128,%xmm12,%xmm3
+       pshufd  $64,%xmm12,%xmm4
+       cmpq    $6,%rdx
+       jb      .Lctr32_tail
+       shrl    $1,%eax
+       movq    %rcx,%r11
+       movl    %eax,%r10d
+       subq    $6,%rdx
+       jmp     .Lctr32_loop6
+
+.p2align       4
+.Lctr32_loop6:
+       pshufd  $192,%xmm13,%xmm5
+       por     %xmm14,%xmm2
+       movups  (%r11),%xmm0
+       pshufd  $128,%xmm13,%xmm6
+       por     %xmm14,%xmm3
+       movups  16(%r11),%xmm1
+       pshufd  $64,%xmm13,%xmm7
+       por     %xmm14,%xmm4
+       por     %xmm14,%xmm5
+       xorps   %xmm0,%xmm2
+       por     %xmm14,%xmm6
+       por     %xmm14,%xmm7
+
+
+
+
+       pxor    %xmm0,%xmm3
+.byte  102,15,56,220,209
+       leaq    32(%r11),%rcx
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,220,217
+       movdqa  .Lincrement32(%rip),%xmm13
+       pxor    %xmm0,%xmm5
+.byte  102,15,56,220,225
+       movdqa  0(%rsp),%xmm12
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+       movups  (%rcx),%xmm0
+       decl    %eax
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+       jmp     .Lctr32_enc_loop6_enter
+.p2align       4
+.Lctr32_enc_loop6:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %eax
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.Lctr32_enc_loop6_enter:
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+.byte  102,15,56,220,240
+.byte  102,15,56,220,248
+       movups  (%rcx),%xmm0
+       jnz     .Lctr32_enc_loop6
+
+.byte  102,15,56,220,209
+       paddd   %xmm13,%xmm12
+.byte  102,15,56,220,217
+       paddd   16(%rsp),%xmm13
+.byte  102,15,56,220,225
+       movdqa  %xmm12,0(%rsp)
+.byte  102,15,56,220,233
+       movdqa  %xmm13,16(%rsp)
+.byte  102,15,56,220,241
+.byte  102,69,15,56,0,231
+.byte  102,15,56,220,249
+.byte  102,69,15,56,0,239
+
+.byte  102,15,56,221,208
+       movups  (%rdi),%xmm8
+.byte  102,15,56,221,216
+       movups  16(%rdi),%xmm9
+.byte  102,15,56,221,224
+       movups  32(%rdi),%xmm10
+.byte  102,15,56,221,232
+       movups  48(%rdi),%xmm11
+.byte  102,15,56,221,240
+       movups  64(%rdi),%xmm1
+.byte  102,15,56,221,248
+       movups  80(%rdi),%xmm0
+       leaq    96(%rdi),%rdi
+
+       xorps   %xmm2,%xmm8
+       pshufd  $192,%xmm12,%xmm2
+       xorps   %xmm3,%xmm9
+       pshufd  $128,%xmm12,%xmm3
+       movups  %xmm8,(%rsi)
+       xorps   %xmm4,%xmm10
+       pshufd  $64,%xmm12,%xmm4
+       movups  %xmm9,16(%rsi)
+       xorps   %xmm5,%xmm11
+       movups  %xmm10,32(%rsi)
+       xorps   %xmm6,%xmm1
+       movups  %xmm11,48(%rsi)
+       xorps   %xmm7,%xmm0
+       movups  %xmm1,64(%rsi)
+       movups  %xmm0,80(%rsi)
+       leaq    96(%rsi),%rsi
+       movl    %r10d,%eax
+       subq    $6,%rdx
+       jnc     .Lctr32_loop6
+
+       addq    $6,%rdx
+       jz      .Lctr32_done
+       movq    %r11,%rcx
+       leal    1(%rax,%rax,1),%eax
+
+.Lctr32_tail:
+       por     %xmm14,%xmm2
+       movups  (%rdi),%xmm8
+       cmpq    $2,%rdx
+       jb      .Lctr32_one
+
+       por     %xmm14,%xmm3
+       movups  16(%rdi),%xmm9
+       je      .Lctr32_two
+
+       pshufd  $192,%xmm13,%xmm5
+       por     %xmm14,%xmm4
+       movups  32(%rdi),%xmm10
+       cmpq    $4,%rdx
+       jb      .Lctr32_three
+
+       pshufd  $128,%xmm13,%xmm6
+       por     %xmm14,%xmm5
+       movups  48(%rdi),%xmm11
+       je      .Lctr32_four
+
+       por     %xmm14,%xmm6
+       xorps   %xmm7,%xmm7
+
+       call    _aesni_encrypt6
+
+       movups  64(%rdi),%xmm1
+       xorps   %xmm2,%xmm8
+       xorps   %xmm3,%xmm9
+       movups  %xmm8,(%rsi)
+       xorps   %xmm4,%xmm10
+       movups  %xmm9,16(%rsi)
+       xorps   %xmm5,%xmm11
+       movups  %xmm10,32(%rsi)
+       xorps   %xmm6,%xmm1
+       movups  %xmm11,48(%rsi)
+       movups  %xmm1,64(%rsi)
+       jmp     .Lctr32_done
+
+.p2align       4
+.Lctr32_one_shortcut:
+       movups  (%r8),%xmm2
+       movups  (%rdi),%xmm8
+       movl    240(%rcx),%eax
+.Lctr32_one:
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_enc1_7:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_enc1_7    
+.byte  102,15,56,221,209
+       xorps   %xmm2,%xmm8
+       movups  %xmm8,(%rsi)
+       jmp     .Lctr32_done
+
+.p2align       4
+.Lctr32_two:
+       xorps   %xmm4,%xmm4
+       call    _aesni_encrypt3
+       xorps   %xmm2,%xmm8
+       xorps   %xmm3,%xmm9
+       movups  %xmm8,(%rsi)
+       movups  %xmm9,16(%rsi)
+       jmp     .Lctr32_done
+
+.p2align       4
+.Lctr32_three:
+       call    _aesni_encrypt3
+       xorps   %xmm2,%xmm8
+       xorps   %xmm3,%xmm9
+       movups  %xmm8,(%rsi)
+       xorps   %xmm4,%xmm10
+       movups  %xmm9,16(%rsi)
+       movups  %xmm10,32(%rsi)
+       jmp     .Lctr32_done
+
+.p2align       4
+.Lctr32_four:
+       call    _aesni_encrypt4
+       xorps   %xmm2,%xmm8
+       xorps   %xmm3,%xmm9
+       movups  %xmm8,(%rsi)
+       xorps   %xmm4,%xmm10
+       movups  %xmm9,16(%rsi)
+       xorps   %xmm5,%xmm11
+       movups  %xmm10,32(%rsi)
+       movups  %xmm11,48(%rsi)
+
+.Lctr32_done:
+       movaps  32(%rsp),%xmm6
+       movaps  48(%rsp),%xmm7
+       movaps  64(%rsp),%xmm8
+       movaps  80(%rsp),%xmm9
+       movaps  96(%rsp),%xmm10
+       movaps  112(%rsp),%xmm11
+       movaps  128(%rsp),%xmm12
+       movaps  144(%rsp),%xmm13
+       movaps  160(%rsp),%xmm14
+       movaps  176(%rsp),%xmm15
+       leaq    200(%rsp),%rsp
+.Lctr32_ret:
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_aesni_ctr32_encrypt_blocks:
+.globl aesni_xts_encrypt
+.def   aesni_xts_encrypt;      .scl 2; .type 32;       .endef
+.p2align       4
+aesni_xts_encrypt:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_aesni_xts_encrypt:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+       movq    %r9,%rcx
+       movq    40(%rsp),%r8
+       movq    48(%rsp),%r9
+
+       leaq    -264(%rsp),%rsp
+       movaps  %xmm6,96(%rsp)
+       movaps  %xmm7,112(%rsp)
+       movaps  %xmm8,128(%rsp)
+       movaps  %xmm9,144(%rsp)
+       movaps  %xmm10,160(%rsp)
+       movaps  %xmm11,176(%rsp)
+       movaps  %xmm12,192(%rsp)
+       movaps  %xmm13,208(%rsp)
+       movaps  %xmm14,224(%rsp)
+       movaps  %xmm15,240(%rsp)
+.Lxts_enc_body:
+       movups  (%r9),%xmm15
+       movl    240(%r8),%eax
+       movl    240(%rcx),%r10d
+       movups  (%r8),%xmm0
+       movups  16(%r8),%xmm1
+       leaq    32(%r8),%r8
+       xorps   %xmm0,%xmm15
+.Loop_enc1_8:
+.byte  102,68,15,56,220,249
+       decl    %eax
+       movups  (%r8),%xmm1
+       leaq    16(%r8),%r8
+       jnz     .Loop_enc1_8    
+.byte  102,68,15,56,221,249
+       movq    %rcx,%r11
+       movl    %r10d,%eax
+       movq    %rdx,%r9
+       andq    $-16,%rdx
+
+       movdqa  .Lxts_magic(%rip),%xmm8
+       pxor    %xmm14,%xmm14
+       pcmpgtd %xmm15,%xmm14
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm10
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm11
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm12
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm13
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       subq    $96,%rdx
+       jc      .Lxts_enc_short
+
+       shrl    $1,%eax
+       subl    $1,%eax
+       movl    %eax,%r10d
+       jmp     .Lxts_enc_grandloop
+
+.p2align       4
+.Lxts_enc_grandloop:
+       pshufd  $19,%xmm14,%xmm9
+       movdqa  %xmm15,%xmm14
+       paddq   %xmm15,%xmm15
+       movdqu  0(%rdi),%xmm2
+       pand    %xmm8,%xmm9
+       movdqu  16(%rdi),%xmm3
+       pxor    %xmm9,%xmm15
+
+       movdqu  32(%rdi),%xmm4
+       pxor    %xmm10,%xmm2
+       movdqu  48(%rdi),%xmm5
+       pxor    %xmm11,%xmm3
+       movdqu  64(%rdi),%xmm6
+       pxor    %xmm12,%xmm4
+       movdqu  80(%rdi),%xmm7
+       leaq    96(%rdi),%rdi
+       pxor    %xmm13,%xmm5
+       movups  (%r11),%xmm0
+       pxor    %xmm14,%xmm6
+       pxor    %xmm15,%xmm7
+
+
+
+       movups  16(%r11),%xmm1
+       pxor    %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+       movdqa  %xmm10,0(%rsp)
+.byte  102,15,56,220,209
+       leaq    32(%r11),%rcx
+       pxor    %xmm0,%xmm4
+       movdqa  %xmm11,16(%rsp)
+.byte  102,15,56,220,217
+       pxor    %xmm0,%xmm5
+       movdqa  %xmm12,32(%rsp)
+.byte  102,15,56,220,225
+       pxor    %xmm0,%xmm6
+       movdqa  %xmm13,48(%rsp)
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+       movups  (%rcx),%xmm0
+       decl    %eax
+       movdqa  %xmm14,64(%rsp)
+.byte  102,15,56,220,241
+       movdqa  %xmm15,80(%rsp)
+.byte  102,15,56,220,249
+       pxor    %xmm14,%xmm14
+       pcmpgtd %xmm15,%xmm14
+       jmp     .Lxts_enc_loop6_enter
+
+.p2align       4
+.Lxts_enc_loop6:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %eax
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.Lxts_enc_loop6_enter:
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+.byte  102,15,56,220,240
+.byte  102,15,56,220,248
+       movups  (%rcx),%xmm0
+       jnz     .Lxts_enc_loop6
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,220,209
+       pand    %xmm8,%xmm9
+.byte  102,15,56,220,217
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,220,225
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+       movups  16(%rcx),%xmm1
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm10
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,220,208
+       pand    %xmm8,%xmm9
+.byte  102,15,56,220,216
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,220,224
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,220,232
+.byte  102,15,56,220,240
+.byte  102,15,56,220,248
+       movups  32(%rcx),%xmm0
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm11
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,220,209
+       pand    %xmm8,%xmm9
+.byte  102,15,56,220,217
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,220,225
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm12
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,221,208
+       pand    %xmm8,%xmm9
+.byte  102,15,56,221,216
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,221,224
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,221,232
+.byte  102,15,56,221,240
+.byte  102,15,56,221,248
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm13
+       paddq   %xmm15,%xmm15
+       xorps   0(%rsp),%xmm2
+       pand    %xmm8,%xmm9
+       xorps   16(%rsp),%xmm3
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+
+       xorps   32(%rsp),%xmm4
+       movups  %xmm2,0(%rsi)
+       xorps   48(%rsp),%xmm5
+       movups  %xmm3,16(%rsi)
+       xorps   64(%rsp),%xmm6
+       movups  %xmm4,32(%rsi)
+       xorps   80(%rsp),%xmm7
+       movups  %xmm5,48(%rsi)
+       movl    %r10d,%eax
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       leaq    96(%rsi),%rsi
+       subq    $96,%rdx
+       jnc     .Lxts_enc_grandloop
+
+       leal    3(%rax,%rax,1),%eax
+       movq    %r11,%rcx
+       movl    %eax,%r10d
+
+.Lxts_enc_short:
+       addq    $96,%rdx
+       jz      .Lxts_enc_done
+
+       cmpq    $32,%rdx
+       jb      .Lxts_enc_one
+       je      .Lxts_enc_two
+
+       cmpq    $64,%rdx
+       jb      .Lxts_enc_three
+       je      .Lxts_enc_four
+
+       pshufd  $19,%xmm14,%xmm9
+       movdqa  %xmm15,%xmm14
+       paddq   %xmm15,%xmm15
+       movdqu  (%rdi),%xmm2
+       pand    %xmm8,%xmm9
+       movdqu  16(%rdi),%xmm3
+       pxor    %xmm9,%xmm15
+
+       movdqu  32(%rdi),%xmm4
+       pxor    %xmm10,%xmm2
+       movdqu  48(%rdi),%xmm5
+       pxor    %xmm11,%xmm3
+       movdqu  64(%rdi),%xmm6
+       leaq    80(%rdi),%rdi
+       pxor    %xmm12,%xmm4
+       pxor    %xmm13,%xmm5
+       pxor    %xmm14,%xmm6
+
+       call    _aesni_encrypt6
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm15,%xmm10
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+       movdqu  %xmm2,(%rsi)
+       xorps   %xmm13,%xmm5
+       movdqu  %xmm3,16(%rsi)
+       xorps   %xmm14,%xmm6
+       movdqu  %xmm4,32(%rsi)
+       movdqu  %xmm5,48(%rsi)
+       movdqu  %xmm6,64(%rsi)
+       leaq    80(%rsi),%rsi
+       jmp     .Lxts_enc_done
+
+.p2align       4
+.Lxts_enc_one:
+       movups  (%rdi),%xmm2
+       leaq    16(%rdi),%rdi
+       xorps   %xmm10,%xmm2
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_enc1_9:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_enc1_9    
+.byte  102,15,56,221,209
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm11,%xmm10
+       movups  %xmm2,(%rsi)
+       leaq    16(%rsi),%rsi
+       jmp     .Lxts_enc_done
+
+.p2align       4
+.Lxts_enc_two:
+       movups  (%rdi),%xmm2
+       movups  16(%rdi),%xmm3
+       leaq    32(%rdi),%rdi
+       xorps   %xmm10,%xmm2
+       xorps   %xmm11,%xmm3
+
+       call    _aesni_encrypt3
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm12,%xmm10
+       xorps   %xmm11,%xmm3
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       leaq    32(%rsi),%rsi
+       jmp     .Lxts_enc_done
+
+.p2align       4
+.Lxts_enc_three:
+       movups  (%rdi),%xmm2
+       movups  16(%rdi),%xmm3
+       movups  32(%rdi),%xmm4
+       leaq    48(%rdi),%rdi
+       xorps   %xmm10,%xmm2
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+
+       call    _aesni_encrypt3
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm13,%xmm10
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       leaq    48(%rsi),%rsi
+       jmp     .Lxts_enc_done
+
+.p2align       4
+.Lxts_enc_four:
+       movups  (%rdi),%xmm2
+       movups  16(%rdi),%xmm3
+       movups  32(%rdi),%xmm4
+       xorps   %xmm10,%xmm2
+       movups  48(%rdi),%xmm5
+       leaq    64(%rdi),%rdi
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+       xorps   %xmm13,%xmm5
+
+       call    _aesni_encrypt4
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm15,%xmm10
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+       movups  %xmm2,(%rsi)
+       xorps   %xmm13,%xmm5
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       leaq    64(%rsi),%rsi
+       jmp     .Lxts_enc_done
+
+.p2align       4
+.Lxts_enc_done:
+       andq    $15,%r9
+       jz      .Lxts_enc_ret
+       movq    %r9,%rdx
+
+.Lxts_enc_steal:
+       movzbl  (%rdi),%eax
+       movzbl  -16(%rsi),%ecx
+       leaq    1(%rdi),%rdi
+       movb    %al,-16(%rsi)
+       movb    %cl,0(%rsi)
+       leaq    1(%rsi),%rsi
+       subq    $1,%rdx
+       jnz     .Lxts_enc_steal
+
+       subq    %r9,%rsi
+       movq    %r11,%rcx
+       movl    %r10d,%eax
+
+       movups  -16(%rsi),%xmm2
+       xorps   %xmm10,%xmm2
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_enc1_10:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_enc1_10   
+.byte  102,15,56,221,209
+       xorps   %xmm10,%xmm2
+       movups  %xmm2,-16(%rsi)
+
+.Lxts_enc_ret:
+       movaps  96(%rsp),%xmm6
+       movaps  112(%rsp),%xmm7
+       movaps  128(%rsp),%xmm8
+       movaps  144(%rsp),%xmm9
+       movaps  160(%rsp),%xmm10
+       movaps  176(%rsp),%xmm11
+       movaps  192(%rsp),%xmm12
+       movaps  208(%rsp),%xmm13
+       movaps  224(%rsp),%xmm14
+       movaps  240(%rsp),%xmm15
+       leaq    264(%rsp),%rsp
+.Lxts_enc_epilogue:
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_aesni_xts_encrypt:
+.globl aesni_xts_decrypt
+.def   aesni_xts_decrypt;      .scl 2; .type 32;       .endef
+.p2align       4
+aesni_xts_decrypt:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_aesni_xts_decrypt:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+       movq    %r9,%rcx
+       movq    40(%rsp),%r8
+       movq    48(%rsp),%r9
+
+       leaq    -264(%rsp),%rsp
+       movaps  %xmm6,96(%rsp)
+       movaps  %xmm7,112(%rsp)
+       movaps  %xmm8,128(%rsp)
+       movaps  %xmm9,144(%rsp)
+       movaps  %xmm10,160(%rsp)
+       movaps  %xmm11,176(%rsp)
+       movaps  %xmm12,192(%rsp)
+       movaps  %xmm13,208(%rsp)
+       movaps  %xmm14,224(%rsp)
+       movaps  %xmm15,240(%rsp)
+.Lxts_dec_body:
+       movups  (%r9),%xmm15
+       movl    240(%r8),%eax
+       movl    240(%rcx),%r10d
+       movups  (%r8),%xmm0
+       movups  16(%r8),%xmm1
+       leaq    32(%r8),%r8
+       xorps   %xmm0,%xmm15
+.Loop_enc1_11:
+.byte  102,68,15,56,220,249
+       decl    %eax
+       movups  (%r8),%xmm1
+       leaq    16(%r8),%r8
+       jnz     .Loop_enc1_11   
+.byte  102,68,15,56,221,249
+       xorl    %eax,%eax
+       testq   $15,%rdx
+       setnz   %al
+       shlq    $4,%rax
+       subq    %rax,%rdx
+
+       movq    %rcx,%r11
+       movl    %r10d,%eax
+       movq    %rdx,%r9
+       andq    $-16,%rdx
+
+       movdqa  .Lxts_magic(%rip),%xmm8
+       pxor    %xmm14,%xmm14
+       pcmpgtd %xmm15,%xmm14
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm10
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm11
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm12
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm13
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       subq    $96,%rdx
+       jc      .Lxts_dec_short
+
+       shrl    $1,%eax
+       subl    $1,%eax
+       movl    %eax,%r10d
+       jmp     .Lxts_dec_grandloop
+
+.p2align       4
+.Lxts_dec_grandloop:
+       pshufd  $19,%xmm14,%xmm9
+       movdqa  %xmm15,%xmm14
+       paddq   %xmm15,%xmm15
+       movdqu  0(%rdi),%xmm2
+       pand    %xmm8,%xmm9
+       movdqu  16(%rdi),%xmm3
+       pxor    %xmm9,%xmm15
+
+       movdqu  32(%rdi),%xmm4
+       pxor    %xmm10,%xmm2
+       movdqu  48(%rdi),%xmm5
+       pxor    %xmm11,%xmm3
+       movdqu  64(%rdi),%xmm6
+       pxor    %xmm12,%xmm4
+       movdqu  80(%rdi),%xmm7
+       leaq    96(%rdi),%rdi
+       pxor    %xmm13,%xmm5
+       movups  (%r11),%xmm0
+       pxor    %xmm14,%xmm6
+       pxor    %xmm15,%xmm7
+
+
+
+       movups  16(%r11),%xmm1
+       pxor    %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+       movdqa  %xmm10,0(%rsp)
+.byte  102,15,56,222,209
+       leaq    32(%r11),%rcx
+       pxor    %xmm0,%xmm4
+       movdqa  %xmm11,16(%rsp)
+.byte  102,15,56,222,217
+       pxor    %xmm0,%xmm5
+       movdqa  %xmm12,32(%rsp)
+.byte  102,15,56,222,225
+       pxor    %xmm0,%xmm6
+       movdqa  %xmm13,48(%rsp)
+.byte  102,15,56,222,233
+       pxor    %xmm0,%xmm7
+       movups  (%rcx),%xmm0
+       decl    %eax
+       movdqa  %xmm14,64(%rsp)
+.byte  102,15,56,222,241
+       movdqa  %xmm15,80(%rsp)
+.byte  102,15,56,222,249
+       pxor    %xmm14,%xmm14
+       pcmpgtd %xmm15,%xmm14
+       jmp     .Lxts_dec_loop6_enter
+
+.p2align       4
+.Lxts_dec_loop6:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %eax
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.Lxts_dec_loop6_enter:
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,222,224
+.byte  102,15,56,222,232
+.byte  102,15,56,222,240
+.byte  102,15,56,222,248
+       movups  (%rcx),%xmm0
+       jnz     .Lxts_dec_loop6
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,222,209
+       pand    %xmm8,%xmm9
+.byte  102,15,56,222,217
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,222,225
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+       movups  16(%rcx),%xmm1
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm10
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,222,208
+       pand    %xmm8,%xmm9
+.byte  102,15,56,222,216
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,222,224
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,222,232
+.byte  102,15,56,222,240
+.byte  102,15,56,222,248
+       movups  32(%rcx),%xmm0
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm11
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,222,209
+       pand    %xmm8,%xmm9
+.byte  102,15,56,222,217
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,222,225
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm12
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,223,208
+       pand    %xmm8,%xmm9
+.byte  102,15,56,223,216
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,223,224
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,223,232
+.byte  102,15,56,223,240
+.byte  102,15,56,223,248
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm13
+       paddq   %xmm15,%xmm15
+       xorps   0(%rsp),%xmm2
+       pand    %xmm8,%xmm9
+       xorps   16(%rsp),%xmm3
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+
+       xorps   32(%rsp),%xmm4
+       movups  %xmm2,0(%rsi)
+       xorps   48(%rsp),%xmm5
+       movups  %xmm3,16(%rsi)
+       xorps   64(%rsp),%xmm6
+       movups  %xmm4,32(%rsi)
+       xorps   80(%rsp),%xmm7
+       movups  %xmm5,48(%rsi)
+       movl    %r10d,%eax
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       leaq    96(%rsi),%rsi
+       subq    $96,%rdx
+       jnc     .Lxts_dec_grandloop
+
+       leal    3(%rax,%rax,1),%eax
+       movq    %r11,%rcx
+       movl    %eax,%r10d
+
+.Lxts_dec_short:
+       addq    $96,%rdx
+       jz      .Lxts_dec_done
+
+       cmpq    $32,%rdx
+       jb      .Lxts_dec_one
+       je      .Lxts_dec_two
+
+       cmpq    $64,%rdx
+       jb      .Lxts_dec_three
+       je      .Lxts_dec_four
+
+       pshufd  $19,%xmm14,%xmm9
+       movdqa  %xmm15,%xmm14
+       paddq   %xmm15,%xmm15
+       movdqu  (%rdi),%xmm2
+       pand    %xmm8,%xmm9
+       movdqu  16(%rdi),%xmm3
+       pxor    %xmm9,%xmm15
+
+       movdqu  32(%rdi),%xmm4
+       pxor    %xmm10,%xmm2
+       movdqu  48(%rdi),%xmm5
+       pxor    %xmm11,%xmm3
+       movdqu  64(%rdi),%xmm6
+       leaq    80(%rdi),%rdi
+       pxor    %xmm12,%xmm4
+       pxor    %xmm13,%xmm5
+       pxor    %xmm14,%xmm6
+
+       call    _aesni_decrypt6
+
+       xorps   %xmm10,%xmm2
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+       movdqu  %xmm2,(%rsi)
+       xorps   %xmm13,%xmm5
+       movdqu  %xmm3,16(%rsi)
+       xorps   %xmm14,%xmm6
+       movdqu  %xmm4,32(%rsi)
+       pxor    %xmm14,%xmm14
+       movdqu  %xmm5,48(%rsi)
+       pcmpgtd %xmm15,%xmm14
+       movdqu  %xmm6,64(%rsi)
+       leaq    80(%rsi),%rsi
+       pshufd  $19,%xmm14,%xmm11
+       andq    $15,%r9
+       jz      .Lxts_dec_ret
+
+       movdqa  %xmm15,%xmm10
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm11
+       pxor    %xmm15,%xmm11
+       jmp     .Lxts_dec_done2
+
+.p2align       4
+.Lxts_dec_one:
+       movups  (%rdi),%xmm2
+       leaq    16(%rdi),%rdi
+       xorps   %xmm10,%xmm2
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_dec1_12:
+.byte  102,15,56,222,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_dec1_12   
+.byte  102,15,56,223,209
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm11,%xmm10
+       movups  %xmm2,(%rsi)
+       movdqa  %xmm12,%xmm11
+       leaq    16(%rsi),%rsi
+       jmp     .Lxts_dec_done
+
+.p2align       4
+.Lxts_dec_two:
+       movups  (%rdi),%xmm2
+       movups  16(%rdi),%xmm3
+       leaq    32(%rdi),%rdi
+       xorps   %xmm10,%xmm2
+       xorps   %xmm11,%xmm3
+
+       call    _aesni_decrypt3
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm12,%xmm10
+       xorps   %xmm11,%xmm3
+       movdqa  %xmm13,%xmm11
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       leaq    32(%rsi),%rsi
+       jmp     .Lxts_dec_done
+
+.p2align       4
+.Lxts_dec_three:
+       movups  (%rdi),%xmm2
+       movups  16(%rdi),%xmm3
+       movups  32(%rdi),%xmm4
+       leaq    48(%rdi),%rdi
+       xorps   %xmm10,%xmm2
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+
+       call    _aesni_decrypt3
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm13,%xmm10
+       xorps   %xmm11,%xmm3
+       movdqa  %xmm15,%xmm11
+       xorps   %xmm12,%xmm4
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       leaq    48(%rsi),%rsi
+       jmp     .Lxts_dec_done
+
+.p2align       4
+.Lxts_dec_four:
+       pshufd  $19,%xmm14,%xmm9
+       movdqa  %xmm15,%xmm14
+       paddq   %xmm15,%xmm15
+       movups  (%rdi),%xmm2
+       pand    %xmm8,%xmm9
+       movups  16(%rdi),%xmm3
+       pxor    %xmm9,%xmm15
+
+       movups  32(%rdi),%xmm4
+       xorps   %xmm10,%xmm2
+       movups  48(%rdi),%xmm5
+       leaq    64(%rdi),%rdi
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+       xorps   %xmm13,%xmm5
+
+       call    _aesni_decrypt4
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm14,%xmm10
+       xorps   %xmm11,%xmm3
+       movdqa  %xmm15,%xmm11
+       xorps   %xmm12,%xmm4
+       movups  %xmm2,(%rsi)
+       xorps   %xmm13,%xmm5
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       leaq    64(%rsi),%rsi
+       jmp     .Lxts_dec_done
+
+.p2align       4
+.Lxts_dec_done:
+       andq    $15,%r9
+       jz      .Lxts_dec_ret
+.Lxts_dec_done2:
+       movq    %r9,%rdx
+       movq    %r11,%rcx
+       movl    %r10d,%eax
+
+       movups  (%rdi),%xmm2
+       xorps   %xmm11,%xmm2
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_dec1_13:
+.byte  102,15,56,222,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_dec1_13   
+.byte  102,15,56,223,209
+       xorps   %xmm11,%xmm2
+       movups  %xmm2,(%rsi)
+
+.Lxts_dec_steal:
+       movzbl  16(%rdi),%eax
+       movzbl  (%rsi),%ecx
+       leaq    1(%rdi),%rdi
+       movb    %al,(%rsi)
+       movb    %cl,16(%rsi)
+       leaq    1(%rsi),%rsi
+       subq    $1,%rdx
+       jnz     .Lxts_dec_steal
+
+       subq    %r9,%rsi
+       movq    %r11,%rcx
+       movl    %r10d,%eax
+
+       movups  (%rsi),%xmm2
+       xorps   %xmm10,%xmm2
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_dec1_14:
+.byte  102,15,56,222,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_dec1_14   
+.byte  102,15,56,223,209
+       xorps   %xmm10,%xmm2
+       movups  %xmm2,(%rsi)
+
+.Lxts_dec_ret:
+       movaps  96(%rsp),%xmm6
+       movaps  112(%rsp),%xmm7
+       movaps  128(%rsp),%xmm8
+       movaps  144(%rsp),%xmm9
+       movaps  160(%rsp),%xmm10
+       movaps  176(%rsp),%xmm11
+       movaps  192(%rsp),%xmm12
+       movaps  208(%rsp),%xmm13
+       movaps  224(%rsp),%xmm14
+       movaps  240(%rsp),%xmm15
+       leaq    264(%rsp),%rsp
+.Lxts_dec_epilogue:
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_aesni_xts_decrypt:
+.globl aesni_cbc_encrypt
+.def   aesni_cbc_encrypt;      .scl 2; .type 32;       .endef
+.p2align       4
+aesni_cbc_encrypt:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_aesni_cbc_encrypt:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+       movq    %r9,%rcx
+       movq    40(%rsp),%r8
+       movq    48(%rsp),%r9
+
+       testq   %rdx,%rdx
+       jz      .Lcbc_ret
+
+       movl    240(%rcx),%r10d
+       movq    %rcx,%r11
+       testl   %r9d,%r9d
+       jz      .Lcbc_decrypt
+
+       movups  (%r8),%xmm2
+       movl    %r10d,%eax
+       cmpq    $16,%rdx
+       jb      .Lcbc_enc_tail
+       subq    $16,%rdx
+       jmp     .Lcbc_enc_loop
+.p2align       4
+.Lcbc_enc_loop:
+       movups  (%rdi),%xmm3
+       leaq    16(%rdi),%rdi
+
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       xorps   %xmm0,%xmm3
+       leaq    32(%rcx),%rcx
+       xorps   %xmm3,%xmm2
+.Loop_enc1_15:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_enc1_15   
+.byte  102,15,56,221,209
+       movl    %r10d,%eax
+       movq    %r11,%rcx
+       movups  %xmm2,0(%rsi)
+       leaq    16(%rsi),%rsi
+       subq    $16,%rdx
+       jnc     .Lcbc_enc_loop
+       addq    $16,%rdx
+       jnz     .Lcbc_enc_tail
+       movups  %xmm2,(%r8)
+       jmp     .Lcbc_ret
+
+.Lcbc_enc_tail:
+       movq    %rdx,%rcx
+       xchgq   %rdi,%rsi
+.long  0x9066A4F3      
+       movl    $16,%ecx
+       subq    %rdx,%rcx
+       xorl    %eax,%eax
+.long  0x9066AAF3      
+       leaq    -16(%rdi),%rdi
+       movl    %r10d,%eax
+       movq    %rdi,%rsi
+       movq    %r11,%rcx
+       xorq    %rdx,%rdx
+       jmp     .Lcbc_enc_loop  
+
+.p2align       4
+.Lcbc_decrypt:
+       leaq    -88(%rsp),%rsp
+       movaps  %xmm6,(%rsp)
+       movaps  %xmm7,16(%rsp)
+       movaps  %xmm8,32(%rsp)
+       movaps  %xmm9,48(%rsp)
+.Lcbc_decrypt_body:
+       movups  (%r8),%xmm9
+       movl    %r10d,%eax
+       cmpq    $112,%rdx
+       jbe     .Lcbc_dec_tail
+       shrl    $1,%r10d
+       subq    $112,%rdx
+       movl    %r10d,%eax
+       movaps  %xmm9,64(%rsp)
+       jmp     .Lcbc_dec_loop8_enter
+.p2align       4
+.Lcbc_dec_loop8:
+       movaps  %xmm0,64(%rsp)
+       movups  %xmm9,(%rsi)
+       leaq    16(%rsi),%rsi
+.Lcbc_dec_loop8_enter:
+       movups  (%rcx),%xmm0
+       movups  (%rdi),%xmm2
+       movups  16(%rdi),%xmm3
+       movups  16(%rcx),%xmm1
+
+       leaq    32(%rcx),%rcx
+       movdqu  32(%rdi),%xmm4
+       xorps   %xmm0,%xmm2
+       movdqu  48(%rdi),%xmm5
+       xorps   %xmm0,%xmm3
+       movdqu  64(%rdi),%xmm6
+.byte  102,15,56,222,209
+       pxor    %xmm0,%xmm4
+       movdqu  80(%rdi),%xmm7
+.byte  102,15,56,222,217
+       pxor    %xmm0,%xmm5
+       movdqu  96(%rdi),%xmm8
+.byte  102,15,56,222,225
+       pxor    %xmm0,%xmm6
+       movdqu  112(%rdi),%xmm9
+.byte  102,15,56,222,233
+       pxor    %xmm0,%xmm7
+       decl    %eax
+.byte  102,15,56,222,241
+       pxor    %xmm0,%xmm8
+.byte  102,15,56,222,249
+       pxor    %xmm0,%xmm9
+       movups  (%rcx),%xmm0
+.byte  102,68,15,56,222,193
+.byte  102,68,15,56,222,201
+       movups  16(%rcx),%xmm1
+
+       call    .Ldec_loop8_enter
+
+       movups  (%rdi),%xmm1
+       movups  16(%rdi),%xmm0
+       xorps   64(%rsp),%xmm2
+       xorps   %xmm1,%xmm3
+       movups  32(%rdi),%xmm1
+       xorps   %xmm0,%xmm4
+       movups  48(%rdi),%xmm0
+       xorps   %xmm1,%xmm5
+       movups  64(%rdi),%xmm1
+       xorps   %xmm0,%xmm6
+       movups  80(%rdi),%xmm0
+       xorps   %xmm1,%xmm7
+       movups  96(%rdi),%xmm1
+       xorps   %xmm0,%xmm8
+       movups  112(%rdi),%xmm0
+       xorps   %xmm1,%xmm9
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movl    %r10d,%eax
+       movups  %xmm6,64(%rsi)
+       movq    %r11,%rcx
+       movups  %xmm7,80(%rsi)
+       leaq    128(%rdi),%rdi
+       movups  %xmm8,96(%rsi)
+       leaq    112(%rsi),%rsi
+       subq    $128,%rdx
+       ja      .Lcbc_dec_loop8
+
+       movaps  %xmm9,%xmm2
+       movaps  %xmm0,%xmm9
+       addq    $112,%rdx
+       jle     .Lcbc_dec_tail_collected
+       movups  %xmm2,(%rsi)
+       leal    1(%r10,%r10,1),%eax
+       leaq    16(%rsi),%rsi
+.Lcbc_dec_tail:
+       movups  (%rdi),%xmm2
+       movaps  %xmm2,%xmm8
+       cmpq    $16,%rdx
+       jbe     .Lcbc_dec_one
+
+       movups  16(%rdi),%xmm3
+       movaps  %xmm3,%xmm7
+       cmpq    $32,%rdx
+       jbe     .Lcbc_dec_two
+
+       movups  32(%rdi),%xmm4
+       movaps  %xmm4,%xmm6
+       cmpq    $48,%rdx
+       jbe     .Lcbc_dec_three
+
+       movups  48(%rdi),%xmm5
+       cmpq    $64,%rdx
+       jbe     .Lcbc_dec_four
+
+       movups  64(%rdi),%xmm6
+       cmpq    $80,%rdx
+       jbe     .Lcbc_dec_five
+
+       movups  80(%rdi),%xmm7
+       cmpq    $96,%rdx
+       jbe     .Lcbc_dec_six
+
+       movups  96(%rdi),%xmm8
+       movaps  %xmm9,64(%rsp)
+       call    _aesni_decrypt8
+       movups  (%rdi),%xmm1
+       movups  16(%rdi),%xmm0
+       xorps   64(%rsp),%xmm2
+       xorps   %xmm1,%xmm3
+       movups  32(%rdi),%xmm1
+       xorps   %xmm0,%xmm4
+       movups  48(%rdi),%xmm0
+       xorps   %xmm1,%xmm5
+       movups  64(%rdi),%xmm1
+       xorps   %xmm0,%xmm6
+       movups  80(%rdi),%xmm0
+       xorps   %xmm1,%xmm7
+       movups  96(%rdi),%xmm9
+       xorps   %xmm0,%xmm8
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       leaq    96(%rsi),%rsi
+       movaps  %xmm8,%xmm2
+       subq    $112,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.p2align       4
+.Lcbc_dec_one:
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_dec1_16:
+.byte  102,15,56,222,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_dec1_16   
+.byte  102,15,56,223,209
+       xorps   %xmm9,%xmm2
+       movaps  %xmm8,%xmm9
+       subq    $16,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.p2align       4
+.Lcbc_dec_two:
+       xorps   %xmm4,%xmm4
+       call    _aesni_decrypt3
+       xorps   %xmm9,%xmm2
+       xorps   %xmm8,%xmm3
+       movups  %xmm2,(%rsi)
+       movaps  %xmm7,%xmm9
+       movaps  %xmm3,%xmm2
+       leaq    16(%rsi),%rsi
+       subq    $32,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.p2align       4
+.Lcbc_dec_three:
+       call    _aesni_decrypt3
+       xorps   %xmm9,%xmm2
+       xorps   %xmm8,%xmm3
+       movups  %xmm2,(%rsi)
+       xorps   %xmm7,%xmm4
+       movups  %xmm3,16(%rsi)
+       movaps  %xmm6,%xmm9
+       movaps  %xmm4,%xmm2
+       leaq    32(%rsi),%rsi
+       subq    $48,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.p2align       4
+.Lcbc_dec_four:
+       call    _aesni_decrypt4
+       xorps   %xmm9,%xmm2
+       movups  48(%rdi),%xmm9
+       xorps   %xmm8,%xmm3
+       movups  %xmm2,(%rsi)
+       xorps   %xmm7,%xmm4
+       movups  %xmm3,16(%rsi)
+       xorps   %xmm6,%xmm5
+       movups  %xmm4,32(%rsi)
+       movaps  %xmm5,%xmm2
+       leaq    48(%rsi),%rsi
+       subq    $64,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.p2align       4
+.Lcbc_dec_five:
+       xorps   %xmm7,%xmm7
+       call    _aesni_decrypt6
+       movups  16(%rdi),%xmm1
+       movups  32(%rdi),%xmm0
+       xorps   %xmm9,%xmm2
+       xorps   %xmm8,%xmm3
+       xorps   %xmm1,%xmm4
+       movups  48(%rdi),%xmm1
+       xorps   %xmm0,%xmm5
+       movups  64(%rdi),%xmm9
+       xorps   %xmm1,%xmm6
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       leaq    64(%rsi),%rsi
+       movaps  %xmm6,%xmm2
+       subq    $80,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.p2align       4
+.Lcbc_dec_six:
+       call    _aesni_decrypt6
+       movups  16(%rdi),%xmm1
+       movups  32(%rdi),%xmm0
+       xorps   %xmm9,%xmm2
+       xorps   %xmm8,%xmm3
+       xorps   %xmm1,%xmm4
+       movups  48(%rdi),%xmm1
+       xorps   %xmm0,%xmm5
+       movups  64(%rdi),%xmm0
+       xorps   %xmm1,%xmm6
+       movups  80(%rdi),%xmm9
+       xorps   %xmm0,%xmm7
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       leaq    80(%rsi),%rsi
+       movaps  %xmm7,%xmm2
+       subq    $96,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.p2align       4
+.Lcbc_dec_tail_collected:
+       andq    $15,%rdx
+       movups  %xmm9,(%r8)
+       jnz     .Lcbc_dec_tail_partial
+       movups  %xmm2,(%rsi)
+       jmp     .Lcbc_dec_ret
+.p2align       4
+.Lcbc_dec_tail_partial:
+       movaps  %xmm2,64(%rsp)
+       movq    $16,%rcx
+       movq    %rsi,%rdi
+       subq    %rdx,%rcx
+       leaq    64(%rsp),%rsi
+.long  0x9066A4F3      
+
+.Lcbc_dec_ret:
+       movaps  (%rsp),%xmm6
+       movaps  16(%rsp),%xmm7
+       movaps  32(%rsp),%xmm8
+       movaps  48(%rsp),%xmm9
+       leaq    88(%rsp),%rsp
+.Lcbc_ret:
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_aesni_cbc_encrypt:
+.globl aesni_set_decrypt_key
+.def   aesni_set_decrypt_key;  .scl 2; .type 32;       .endef
+.p2align       4
+aesni_set_decrypt_key:
+.byte  0x48,0x83,0xEC,0x08     
+       call    __aesni_set_encrypt_key
+       shll    $4,%edx
+       testl   %eax,%eax
+       jnz     .Ldec_key_ret
+       leaq    16(%r8,%rdx,1),%rcx
+
+       movups  (%r8),%xmm0
+       movups  (%rcx),%xmm1
+       movups  %xmm0,(%rcx)
+       movups  %xmm1,(%r8)
+       leaq    16(%r8),%r8
+       leaq    -16(%rcx),%rcx
+
+.Ldec_key_inverse:
+       movups  (%r8),%xmm0
+       movups  (%rcx),%xmm1
+.byte  102,15,56,219,192
+.byte  102,15,56,219,201
+       leaq    16(%r8),%r8
+       leaq    -16(%rcx),%rcx
+       movups  %xmm0,16(%rcx)
+       movups  %xmm1,-16(%r8)
+       cmpq    %r8,%rcx
+       ja      .Ldec_key_inverse
+
+       movups  (%r8),%xmm0
+.byte  102,15,56,219,192
+       movups  %xmm0,(%rcx)
+.Ldec_key_ret:
+       addq    $8,%rsp
+       .byte   0xf3,0xc3
+.LSEH_end_set_decrypt_key:
+
+.globl aesni_set_encrypt_key
+.def   aesni_set_encrypt_key;  .scl 2; .type 32;       .endef
+.p2align       4
+aesni_set_encrypt_key:
+__aesni_set_encrypt_key:
+.byte  0x48,0x83,0xEC,0x08     
+       movq    $-1,%rax
+       testq   %rcx,%rcx
+       jz      .Lenc_key_ret
+       testq   %r8,%r8
+       jz      .Lenc_key_ret
+
+       movups  (%rcx),%xmm0
+       xorps   %xmm4,%xmm4
+       leaq    16(%r8),%rax
+       cmpl    $256,%edx
+       je      .L14rounds
+       cmpl    $192,%edx
+       je      .L12rounds
+       cmpl    $128,%edx
+       jne     .Lbad_keybits
+
+.L10rounds:
+       movl    $9,%edx
+       movups  %xmm0,(%r8)
+.byte  102,15,58,223,200,1
+       call    .Lkey_expansion_128_cold
+.byte  102,15,58,223,200,2
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,4
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,8
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,16
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,32
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,64
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,128
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,27
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,54
+       call    .Lkey_expansion_128
+       movups  %xmm0,(%rax)
+       movl    %edx,80(%rax)
+       xorl    %eax,%eax
+       jmp     .Lenc_key_ret
+
+.p2align       4
+.L12rounds:
+       movq    16(%rcx),%xmm2
+       movl    $11,%edx
+       movups  %xmm0,(%r8)
+.byte  102,15,58,223,202,1
+       call    .Lkey_expansion_192a_cold
+.byte  102,15,58,223,202,2
+       call    .Lkey_expansion_192b
+.byte  102,15,58,223,202,4
+       call    .Lkey_expansion_192a
+.byte  102,15,58,223,202,8
+       call    .Lkey_expansion_192b
+.byte  102,15,58,223,202,16
+       call    .Lkey_expansion_192a
+.byte  102,15,58,223,202,32
+       call    .Lkey_expansion_192b
+.byte  102,15,58,223,202,64
+       call    .Lkey_expansion_192a
+.byte  102,15,58,223,202,128
+       call    .Lkey_expansion_192b
+       movups  %xmm0,(%rax)
+       movl    %edx,48(%rax)
+       xorq    %rax,%rax
+       jmp     .Lenc_key_ret
+
+.p2align       4
+.L14rounds:
+       movups  16(%rcx),%xmm2
+       movl    $13,%edx
+       leaq    16(%rax),%rax
+       movups  %xmm0,(%r8)
+       movups  %xmm2,16(%r8)
+.byte  102,15,58,223,202,1
+       call    .Lkey_expansion_256a_cold
+.byte  102,15,58,223,200,1
+       call    .Lkey_expansion_256b
+.byte  102,15,58,223,202,2
+       call    .Lkey_expansion_256a
+.byte  102,15,58,223,200,2
+       call    .Lkey_expansion_256b
+.byte  102,15,58,223,202,4
+       call    .Lkey_expansion_256a
+.byte  102,15,58,223,200,4
+       call    .Lkey_expansion_256b
+.byte  102,15,58,223,202,8
+       call    .Lkey_expansion_256a
+.byte  102,15,58,223,200,8
+       call    .Lkey_expansion_256b
+.byte  102,15,58,223,202,16
+       call    .Lkey_expansion_256a
+.byte  102,15,58,223,200,16
+       call    .Lkey_expansion_256b
+.byte  102,15,58,223,202,32
+       call    .Lkey_expansion_256a
+.byte  102,15,58,223,200,32
+       call    .Lkey_expansion_256b
+.byte  102,15,58,223,202,64
+       call    .Lkey_expansion_256a
+       movups  %xmm0,(%rax)
+       movl    %edx,16(%rax)
+       xorq    %rax,%rax
+       jmp     .Lenc_key_ret
+
+.p2align       4
+.Lbad_keybits:
+       movq    $-2,%rax
+.Lenc_key_ret:
+       addq    $8,%rsp
+       .byte   0xf3,0xc3
+.LSEH_end_set_encrypt_key:
+
+.p2align       4
+.Lkey_expansion_128:
+       movups  %xmm0,(%rax)
+       leaq    16(%rax),%rax
+.Lkey_expansion_128_cold:
+       shufps  $16,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $140,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $255,%xmm1,%xmm1
+       xorps   %xmm1,%xmm0
+       .byte   0xf3,0xc3
+
+.p2align       4
+.Lkey_expansion_192a:
+       movups  %xmm0,(%rax)
+       leaq    16(%rax),%rax
+.Lkey_expansion_192a_cold:
+       movaps  %xmm2,%xmm5
+.Lkey_expansion_192b_warm:
+       shufps  $16,%xmm0,%xmm4
+       movdqa  %xmm2,%xmm3
+       xorps   %xmm4,%xmm0
+       shufps  $140,%xmm0,%xmm4
+       pslldq  $4,%xmm3
+       xorps   %xmm4,%xmm0
+       pshufd  $85,%xmm1,%xmm1
+       pxor    %xmm3,%xmm2
+       pxor    %xmm1,%xmm0
+       pshufd  $255,%xmm0,%xmm3
+       pxor    %xmm3,%xmm2
+       .byte   0xf3,0xc3
+
+.p2align       4
+.Lkey_expansion_192b:
+       movaps  %xmm0,%xmm3
+       shufps  $68,%xmm0,%xmm5
+       movups  %xmm5,(%rax)
+       shufps  $78,%xmm2,%xmm3
+       movups  %xmm3,16(%rax)
+       leaq    32(%rax),%rax
+       jmp     .Lkey_expansion_192b_warm
+
+.p2align       4
+.Lkey_expansion_256a:
+       movups  %xmm2,(%rax)
+       leaq    16(%rax),%rax
+.Lkey_expansion_256a_cold:
+       shufps  $16,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $140,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $255,%xmm1,%xmm1
+       xorps   %xmm1,%xmm0
+       .byte   0xf3,0xc3
+
+.p2align       4
+.Lkey_expansion_256b:
+       movups  %xmm0,(%rax)
+       leaq    16(%rax),%rax
+
+       shufps  $16,%xmm2,%xmm4
+       xorps   %xmm4,%xmm2
+       shufps  $140,%xmm2,%xmm4
+       xorps   %xmm4,%xmm2
+       shufps  $170,%xmm1,%xmm1
+       xorps   %xmm1,%xmm2
+       .byte   0xf3,0xc3
+
+
+.p2align       6
+.Lbswap_mask:
+.byte  15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
+.Lincrement32:
+.long  6,6,6,0
+.Lincrement64:
+.long  1,0,0,0
+.Lxts_magic:
+.long  0x87,0,1,0
+
+.byte  
65,69,83,32,102,111,114,32,73,110,116,101,108,32,65,69,83,45,78,73,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
+.p2align       6
+
+.def   ecb_se_handler; .scl 3; .type 32;       .endef
+.p2align       4
+ecb_se_handler:
+       pushq   %rsi
+       pushq   %rdi
+       pushq   %rbx
+       pushq   %rbp
+       pushq   %r12
+       pushq   %r13
+       pushq   %r14
+       pushq   %r15
+       pushfq
+       subq    $64,%rsp
+
+       movq    152(%r8),%rax
+
+       jmp     .Lcommon_seh_tail
+
+
+.def   ccm64_se_handler;       .scl 3; .type 32;       .endef
+.p2align       4
+ccm64_se_handler:
+       pushq   %rsi
+       pushq   %rdi
+       pushq   %rbx
+       pushq   %rbp
+       pushq   %r12
+       pushq   %r13
+       pushq   %r14
+       pushq   %r15
+       pushfq
+       subq    $64,%rsp
+
+       movq    120(%r8),%rax
+       movq    248(%r8),%rbx
+
+       movq    8(%r9),%rsi
+       movq    56(%r9),%r11
+
+       movl    0(%r11),%r10d
+       leaq    (%rsi,%r10,1),%r10
+       cmpq    %r10,%rbx
+       jb      .Lcommon_seh_tail
+
+       movq    152(%r8),%rax
+
+       movl    4(%r11),%r10d
+       leaq    (%rsi,%r10,1),%r10
+       cmpq    %r10,%rbx
+       jae     .Lcommon_seh_tail
+
+       leaq    0(%rax),%rsi
+       leaq    512(%r8),%rdi
+       movl    $8,%ecx
+.long  0xa548f3fc              
+       leaq    88(%rax),%rax
+
+       jmp     .Lcommon_seh_tail
+
+
+.def   ctr32_se_handler;       .scl 3; .type 32;       .endef
+.p2align       4
+ctr32_se_handler:
+       pushq   %rsi
+       pushq   %rdi
+       pushq   %rbx
+       pushq   %rbp
+       pushq   %r12
+       pushq   %r13
+       pushq   %r14
+       pushq   %r15
+       pushfq
+       subq    $64,%rsp
+
+       movq    120(%r8),%rax
+       movq    248(%r8),%rbx
+
+       leaq    .Lctr32_body(%rip),%r10
+       cmpq    %r10,%rbx
+       jb      .Lcommon_seh_tail
+
+       movq    152(%r8),%rax
+
+       leaq    .Lctr32_ret(%rip),%r10
+       cmpq    %r10,%rbx
+       jae     .Lcommon_seh_tail
+
+       leaq    32(%rax),%rsi
+       leaq    512(%r8),%rdi
+       movl    $20,%ecx
+.long  0xa548f3fc              
+       leaq    200(%rax),%rax
+
+       jmp     .Lcommon_seh_tail
+
+
+.def   xts_se_handler; .scl 3; .type 32;       .endef
+.p2align       4
+xts_se_handler:
+       pushq   %rsi
+       pushq   %rdi
+       pushq   %rbx
+       pushq   %rbp
+       pushq   %r12
+       pushq   %r13
+       pushq   %r14
+       pushq   %r15
+       pushfq
+       subq    $64,%rsp
+
+       movq    120(%r8),%rax
+       movq    248(%r8),%rbx
+
+       movq    8(%r9),%rsi
+       movq    56(%r9),%r11
+
+       movl    0(%r11),%r10d
+       leaq    (%rsi,%r10,1),%r10
+       cmpq    %r10,%rbx
+       jb      .Lcommon_seh_tail
+
+       movq    152(%r8),%rax
+
+       movl    4(%r11),%r10d
+       leaq    (%rsi,%r10,1),%r10
+       cmpq    %r10,%rbx
+       jae     .Lcommon_seh_tail
+
+       leaq    96(%rax),%rsi
+       leaq    512(%r8),%rdi
+       movl    $20,%ecx
+.long  0xa548f3fc              
+       leaq    104+160(%rax),%rax
+
+       jmp     .Lcommon_seh_tail
+
+.def   cbc_se_handler; .scl 3; .type 32;       .endef
+.p2align       4
+cbc_se_handler:
+       pushq   %rsi
+       pushq   %rdi
+       pushq   %rbx
+       pushq   %rbp
+       pushq   %r12
+       pushq   %r13
+       pushq   %r14
+       pushq   %r15
+       pushfq
+       subq    $64,%rsp
+
+       movq    152(%r8),%rax
+       movq    248(%r8),%rbx
+
+       leaq    .Lcbc_decrypt(%rip),%r10
+       cmpq    %r10,%rbx
+       jb      .Lcommon_seh_tail
+
+       leaq    .Lcbc_decrypt_body(%rip),%r10
+       cmpq    %r10,%rbx
+       jb      .Lrestore_cbc_rax
+
+       leaq    .Lcbc_ret(%rip),%r10
+       cmpq    %r10,%rbx
+       jae     .Lcommon_seh_tail
+
+       leaq    0(%rax),%rsi
+       leaq    512(%r8),%rdi
+       movl    $8,%ecx
+.long  0xa548f3fc              
+       leaq    88(%rax),%rax
+       jmp     .Lcommon_seh_tail
+
+.Lrestore_cbc_rax:
+       movq    120(%r8),%rax
+
+.Lcommon_seh_tail:
+       movq    8(%rax),%rdi
+       movq    16(%rax),%rsi
+       movq    %rax,152(%r8)
+       movq    %rsi,168(%r8)
+       movq    %rdi,176(%r8)
+
+       movq    40(%r9),%rdi
+       movq    %r8,%rsi
+       movl    $154,%ecx
+.long  0xa548f3fc              
+
+       movq    %r9,%rsi
+       xorq    %rcx,%rcx
+       movq    8(%rsi),%rdx
+       movq    0(%rsi),%r8
+       movq    16(%rsi),%r9
+       movq    40(%rsi),%r10
+       leaq    56(%rsi),%r11
+       leaq    24(%rsi),%r12
+       movq    %r10,32(%rsp)
+       movq    %r11,40(%rsp)
+       movq    %r12,48(%rsp)
+       movq    %rcx,56(%rsp)
+       call    *__imp_RtlVirtualUnwind(%rip)
+
+       movl    $1,%eax
+       addq    $64,%rsp
+       popfq
+       popq    %r15
+       popq    %r14
+       popq    %r13
+       popq    %r12
+       popq    %rbp
+       popq    %rbx
+       popq    %rdi
+       popq    %rsi
+       .byte   0xf3,0xc3
+
+
+.section       .pdata
+.p2align       2
+.rva   .LSEH_begin_aesni_ecb_encrypt
+.rva   .LSEH_end_aesni_ecb_encrypt
+.rva   .LSEH_info_ecb
+
+.rva   .LSEH_begin_aesni_ccm64_encrypt_blocks
+.rva   .LSEH_end_aesni_ccm64_encrypt_blocks
+.rva   .LSEH_info_ccm64_enc
+
+.rva   .LSEH_begin_aesni_ccm64_decrypt_blocks
+.rva   .LSEH_end_aesni_ccm64_decrypt_blocks
+.rva   .LSEH_info_ccm64_dec
+
+.rva   .LSEH_begin_aesni_ctr32_encrypt_blocks
+.rva   .LSEH_end_aesni_ctr32_encrypt_blocks
+.rva   .LSEH_info_ctr32
+
+.rva   .LSEH_begin_aesni_xts_encrypt
+.rva   .LSEH_end_aesni_xts_encrypt
+.rva   .LSEH_info_xts_enc
+
+.rva   .LSEH_begin_aesni_xts_decrypt
+.rva   .LSEH_end_aesni_xts_decrypt
+.rva   .LSEH_info_xts_dec
+.rva   .LSEH_begin_aesni_cbc_encrypt
+.rva   .LSEH_end_aesni_cbc_encrypt
+.rva   .LSEH_info_cbc
+
+.rva   aesni_set_decrypt_key
+.rva   .LSEH_end_set_decrypt_key
+.rva   .LSEH_info_key
+
+.rva   aesni_set_encrypt_key
+.rva   .LSEH_end_set_encrypt_key
+.rva   .LSEH_info_key
+.section       .xdata
+.p2align       3
+.LSEH_info_ecb:
+.byte  9,0,0,0
+.rva   ecb_se_handler
+.LSEH_info_ccm64_enc:
+.byte  9,0,0,0
+.rva   ccm64_se_handler
+.rva   .Lccm64_enc_body,.Lccm64_enc_ret        
+.LSEH_info_ccm64_dec:
+.byte  9,0,0,0
+.rva   ccm64_se_handler
+.rva   .Lccm64_dec_body,.Lccm64_dec_ret        
+.LSEH_info_ctr32:
+.byte  9,0,0,0
+.rva   ctr32_se_handler
+.LSEH_info_xts_enc:
+.byte  9,0,0,0
+.rva   xts_se_handler
+.rva   .Lxts_enc_body,.Lxts_enc_epilogue       
+.LSEH_info_xts_dec:
+.byte  9,0,0,0
+.rva   xts_se_handler
+.rva   .Lxts_dec_body,.Lxts_dec_epilogue       
+.LSEH_info_cbc:
+.byte  9,0,0,0
+.rva   cbc_se_handler
+.LSEH_info_key:
+.byte  0x01,0x04,0x01,0x00
+.byte  0x04,0x02,0x00,0x00     
diff --git a/lib/accelerated/x86/asm-coff/appro-aes-x86-coff.s 
b/lib/accelerated/x86/asm-coff/appro-aes-x86-coff.s
new file mode 100644
index 0000000..2f9a6bc
--- /dev/null
+++ b/lib/accelerated/x86/asm-coff/appro-aes-x86-coff.s
@@ -0,0 +1,2162 @@
+# Copyright (c) 2011, Andy Polyakov by <address@hidden>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 
+#     * Redistributions of source code must retain copyright notices,
+#      this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+#
+#     * Neither the name of the Andy Polyakov nor the names of its
+#      copyright holder and contributors may be used to endorse or
+#      promote products derived from this software without specific
+#      prior written permission.
+#
+# ALTERNATIVELY, provided that this notice is retained in full, this
+# product may be distributed under the terms of the GNU General Public
+# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+# those given above.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.file  "aesni-x86.s"
+.text
+.globl _aesni_encrypt
+.def   _aesni_encrypt; .scl    2;      .type   32;     .endef
+.align 16
+_aesni_encrypt:
+.L_aesni_encrypt_begin:
+       movl    4(%esp),%eax
+       movl    12(%esp),%edx
+       movups  (%eax),%xmm2
+       movl    240(%edx),%ecx
+       movl    8(%esp),%eax
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L000enc1_loop_1:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L000enc1_loop_1
+.byte  102,15,56,221,209
+       movups  %xmm2,(%eax)
+       ret
+.globl _aesni_decrypt
+.def   _aesni_decrypt; .scl    2;      .type   32;     .endef
+.align 16
+_aesni_decrypt:
+.L_aesni_decrypt_begin:
+       movl    4(%esp),%eax
+       movl    12(%esp),%edx
+       movups  (%eax),%xmm2
+       movl    240(%edx),%ecx
+       movl    8(%esp),%eax
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L001dec1_loop_2:
+.byte  102,15,56,222,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L001dec1_loop_2
+.byte  102,15,56,223,209
+       movups  %xmm2,(%eax)
+       ret
+.def   __aesni_encrypt3;       .scl    3;      .type   32;     .endef
+.align 16
+__aesni_encrypt3:
+       movups  (%edx),%xmm0
+       shrl    $1,%ecx
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+       pxor    %xmm0,%xmm4
+       movups  (%edx),%xmm0
+.L002enc3_loop:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %ecx
+.byte  102,15,56,220,225
+       movups  16(%edx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leal    32(%edx),%edx
+.byte  102,15,56,220,224
+       movups  (%edx),%xmm0
+       jnz     .L002enc3_loop
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+       ret
+.def   __aesni_decrypt3;       .scl    3;      .type   32;     .endef
+.align 16
+__aesni_decrypt3:
+       movups  (%edx),%xmm0
+       shrl    $1,%ecx
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+       pxor    %xmm0,%xmm4
+       movups  (%edx),%xmm0
+.L003dec3_loop:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %ecx
+.byte  102,15,56,222,225
+       movups  16(%edx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leal    32(%edx),%edx
+.byte  102,15,56,222,224
+       movups  (%edx),%xmm0
+       jnz     .L003dec3_loop
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+       ret
+.def   __aesni_encrypt4;       .scl    3;      .type   32;     .endef
+.align 16
+__aesni_encrypt4:
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       shrl    $1,%ecx
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+       pxor    %xmm0,%xmm4
+       pxor    %xmm0,%xmm5
+       movups  (%edx),%xmm0
+.L004enc4_loop:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %ecx
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+       movups  16(%edx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leal    32(%edx),%edx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+       movups  (%edx),%xmm0
+       jnz     .L004enc4_loop
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+.byte  102,15,56,221,232
+       ret
+.def   __aesni_decrypt4;       .scl    3;      .type   32;     .endef
+.align 16
+__aesni_decrypt4:
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       shrl    $1,%ecx
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+       pxor    %xmm0,%xmm4
+       pxor    %xmm0,%xmm5
+       movups  (%edx),%xmm0
+.L005dec4_loop:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %ecx
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+       movups  16(%edx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leal    32(%edx),%edx
+.byte  102,15,56,222,224
+.byte  102,15,56,222,232
+       movups  (%edx),%xmm0
+       jnz     .L005dec4_loop
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+.byte  102,15,56,223,232
+       ret
+.def   __aesni_encrypt6;       .scl    3;      .type   32;     .endef
+.align 16
+__aesni_encrypt6:
+       movups  (%edx),%xmm0
+       shrl    $1,%ecx
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+.byte  102,15,56,220,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,220,217
+       pxor    %xmm0,%xmm5
+       decl    %ecx
+.byte  102,15,56,220,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+.byte  102,15,56,220,241
+       movups  (%edx),%xmm0
+.byte  102,15,56,220,249
+       jmp     .L_aesni_encrypt6_enter
+.align 16
+.L006enc6_loop:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %ecx
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.align 16
+.L_aesni_encrypt6_enter:
+       movups  16(%edx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leal    32(%edx),%edx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+.byte  102,15,56,220,240
+.byte  102,15,56,220,248
+       movups  (%edx),%xmm0
+       jnz     .L006enc6_loop
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+.byte  102,15,56,221,232
+.byte  102,15,56,221,240
+.byte  102,15,56,221,248
+       ret
+.def   __aesni_decrypt6;       .scl    3;      .type   32;     .endef
+.align 16
+__aesni_decrypt6:
+       movups  (%edx),%xmm0
+       shrl    $1,%ecx
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+.byte  102,15,56,222,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,222,217
+       pxor    %xmm0,%xmm5
+       decl    %ecx
+.byte  102,15,56,222,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,222,233
+       pxor    %xmm0,%xmm7
+.byte  102,15,56,222,241
+       movups  (%edx),%xmm0
+.byte  102,15,56,222,249
+       jmp     .L_aesni_decrypt6_enter
+.align 16
+.L007dec6_loop:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %ecx
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.align 16
+.L_aesni_decrypt6_enter:
+       movups  16(%edx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leal    32(%edx),%edx
+.byte  102,15,56,222,224
+.byte  102,15,56,222,232
+.byte  102,15,56,222,240
+.byte  102,15,56,222,248
+       movups  (%edx),%xmm0
+       jnz     .L007dec6_loop
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+.byte  102,15,56,223,232
+.byte  102,15,56,223,240
+.byte  102,15,56,223,248
+       ret
+.globl _aesni_ecb_encrypt
+.def   _aesni_ecb_encrypt;     .scl    2;      .type   32;     .endef
+.align 16
+_aesni_ecb_encrypt:
+.L_aesni_ecb_encrypt_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%esi
+       movl    24(%esp),%edi
+       movl    28(%esp),%eax
+       movl    32(%esp),%edx
+       movl    36(%esp),%ebx
+       andl    $-16,%eax
+       jz      .L008ecb_ret
+       movl    240(%edx),%ecx
+       testl   %ebx,%ebx
+       jz      .L009ecb_decrypt
+       movl    %edx,%ebp
+       movl    %ecx,%ebx
+       cmpl    $96,%eax
+       jb      .L010ecb_enc_tail
+       movdqu  (%esi),%xmm2
+       movdqu  16(%esi),%xmm3
+       movdqu  32(%esi),%xmm4
+       movdqu  48(%esi),%xmm5
+       movdqu  64(%esi),%xmm6
+       movdqu  80(%esi),%xmm7
+       leal    96(%esi),%esi
+       subl    $96,%eax
+       jmp     .L011ecb_enc_loop6_enter
+.align 16
+.L012ecb_enc_loop6:
+       movups  %xmm2,(%edi)
+       movdqu  (%esi),%xmm2
+       movups  %xmm3,16(%edi)
+       movdqu  16(%esi),%xmm3
+       movups  %xmm4,32(%edi)
+       movdqu  32(%esi),%xmm4
+       movups  %xmm5,48(%edi)
+       movdqu  48(%esi),%xmm5
+       movups  %xmm6,64(%edi)
+       movdqu  64(%esi),%xmm6
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       movdqu  80(%esi),%xmm7
+       leal    96(%esi),%esi
+.L011ecb_enc_loop6_enter:
+       call    __aesni_encrypt6
+       movl    %ebp,%edx
+       movl    %ebx,%ecx
+       subl    $96,%eax
+       jnc     .L012ecb_enc_loop6
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       addl    $96,%eax
+       jz      .L008ecb_ret
+.L010ecb_enc_tail:
+       movups  (%esi),%xmm2
+       cmpl    $32,%eax
+       jb      .L013ecb_enc_one
+       movups  16(%esi),%xmm3
+       je      .L014ecb_enc_two
+       movups  32(%esi),%xmm4
+       cmpl    $64,%eax
+       jb      .L015ecb_enc_three
+       movups  48(%esi),%xmm5
+       je      .L016ecb_enc_four
+       movups  64(%esi),%xmm6
+       xorps   %xmm7,%xmm7
+       call    __aesni_encrypt6
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L013ecb_enc_one:
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L017enc1_loop_3:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L017enc1_loop_3
+.byte  102,15,56,221,209
+       movups  %xmm2,(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L014ecb_enc_two:
+       xorps   %xmm4,%xmm4
+       call    __aesni_encrypt3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L015ecb_enc_three:
+       call    __aesni_encrypt3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L016ecb_enc_four:
+       call    __aesni_encrypt4
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L009ecb_decrypt:
+       movl    %edx,%ebp
+       movl    %ecx,%ebx
+       cmpl    $96,%eax
+       jb      .L018ecb_dec_tail
+       movdqu  (%esi),%xmm2
+       movdqu  16(%esi),%xmm3
+       movdqu  32(%esi),%xmm4
+       movdqu  48(%esi),%xmm5
+       movdqu  64(%esi),%xmm6
+       movdqu  80(%esi),%xmm7
+       leal    96(%esi),%esi
+       subl    $96,%eax
+       jmp     .L019ecb_dec_loop6_enter
+.align 16
+.L020ecb_dec_loop6:
+       movups  %xmm2,(%edi)
+       movdqu  (%esi),%xmm2
+       movups  %xmm3,16(%edi)
+       movdqu  16(%esi),%xmm3
+       movups  %xmm4,32(%edi)
+       movdqu  32(%esi),%xmm4
+       movups  %xmm5,48(%edi)
+       movdqu  48(%esi),%xmm5
+       movups  %xmm6,64(%edi)
+       movdqu  64(%esi),%xmm6
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       movdqu  80(%esi),%xmm7
+       leal    96(%esi),%esi
+.L019ecb_dec_loop6_enter:
+       call    __aesni_decrypt6
+       movl    %ebp,%edx
+       movl    %ebx,%ecx
+       subl    $96,%eax
+       jnc     .L020ecb_dec_loop6
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       addl    $96,%eax
+       jz      .L008ecb_ret
+.L018ecb_dec_tail:
+       movups  (%esi),%xmm2
+       cmpl    $32,%eax
+       jb      .L021ecb_dec_one
+       movups  16(%esi),%xmm3
+       je      .L022ecb_dec_two
+       movups  32(%esi),%xmm4
+       cmpl    $64,%eax
+       jb      .L023ecb_dec_three
+       movups  48(%esi),%xmm5
+       je      .L024ecb_dec_four
+       movups  64(%esi),%xmm6
+       xorps   %xmm7,%xmm7
+       call    __aesni_decrypt6
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L021ecb_dec_one:
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L025dec1_loop_4:
+.byte  102,15,56,222,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L025dec1_loop_4
+.byte  102,15,56,223,209
+       movups  %xmm2,(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L022ecb_dec_two:
+       xorps   %xmm4,%xmm4
+       call    __aesni_decrypt3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L023ecb_dec_three:
+       call    __aesni_decrypt3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L024ecb_dec_four:
+       call    __aesni_decrypt4
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+.L008ecb_ret:
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.globl _aesni_ccm64_encrypt_blocks
+.def   _aesni_ccm64_encrypt_blocks;    .scl    2;      .type   32;     .endef
+.align 16
+_aesni_ccm64_encrypt_blocks:
+.L_aesni_ccm64_encrypt_blocks_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%esi
+       movl    24(%esp),%edi
+       movl    28(%esp),%eax
+       movl    32(%esp),%edx
+       movl    36(%esp),%ebx
+       movl    40(%esp),%ecx
+       movl    %esp,%ebp
+       subl    $60,%esp
+       andl    $-16,%esp
+       movl    %ebp,48(%esp)
+       movdqu  (%ebx),%xmm7
+       movdqu  (%ecx),%xmm3
+       movl    240(%edx),%ecx
+       movl    $202182159,(%esp)
+       movl    $134810123,4(%esp)
+       movl    $67438087,8(%esp)
+       movl    $66051,12(%esp)
+       movl    $1,%ebx
+       xorl    %ebp,%ebp
+       movl    %ebx,16(%esp)
+       movl    %ebp,20(%esp)
+       movl    %ebp,24(%esp)
+       movl    %ebp,28(%esp)
+       shrl    $1,%ecx
+       leal    (%edx),%ebp
+       movdqa  (%esp),%xmm5
+       movdqa  %xmm7,%xmm2
+       movl    %ecx,%ebx
+.byte  102,15,56,0,253
+.L026ccm64_enc_outer:
+       movups  (%ebp),%xmm0
+       movl    %ebx,%ecx
+       movups  (%esi),%xmm6
+       xorps   %xmm0,%xmm2
+       movups  16(%ebp),%xmm1
+       xorps   %xmm6,%xmm0
+       leal    32(%ebp),%edx
+       xorps   %xmm0,%xmm3
+       movups  (%edx),%xmm0
+.L027ccm64_enc2_loop:
+.byte  102,15,56,220,209
+       decl    %ecx
+.byte  102,15,56,220,217
+       movups  16(%edx),%xmm1
+.byte  102,15,56,220,208
+       leal    32(%edx),%edx
+.byte  102,15,56,220,216
+       movups  (%edx),%xmm0
+       jnz     .L027ccm64_enc2_loop
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       paddq   16(%esp),%xmm7
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+       decl    %eax
+       leal    16(%esi),%esi
+       xorps   %xmm2,%xmm6
+       movdqa  %xmm7,%xmm2
+       movups  %xmm6,(%edi)
+       leal    16(%edi),%edi
+.byte  102,15,56,0,213
+       jnz     .L026ccm64_enc_outer
+       movl    48(%esp),%esp
+       movl    40(%esp),%edi
+       movups  %xmm3,(%edi)
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.globl _aesni_ccm64_decrypt_blocks
+.def   _aesni_ccm64_decrypt_blocks;    .scl    2;      .type   32;     .endef
+.align 16
+_aesni_ccm64_decrypt_blocks:
+.L_aesni_ccm64_decrypt_blocks_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%esi
+       movl    24(%esp),%edi
+       movl    28(%esp),%eax
+       movl    32(%esp),%edx
+       movl    36(%esp),%ebx
+       movl    40(%esp),%ecx
+       movl    %esp,%ebp
+       subl    $60,%esp
+       andl    $-16,%esp
+       movl    %ebp,48(%esp)
+       movdqu  (%ebx),%xmm7
+       movdqu  (%ecx),%xmm3
+       movl    240(%edx),%ecx
+       movl    $202182159,(%esp)
+       movl    $134810123,4(%esp)
+       movl    $67438087,8(%esp)
+       movl    $66051,12(%esp)
+       movl    $1,%ebx
+       xorl    %ebp,%ebp
+       movl    %ebx,16(%esp)
+       movl    %ebp,20(%esp)
+       movl    %ebp,24(%esp)
+       movl    %ebp,28(%esp)
+       movdqa  (%esp),%xmm5
+       movdqa  %xmm7,%xmm2
+       movl    %edx,%ebp
+       movl    %ecx,%ebx
+.byte  102,15,56,0,253
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L028enc1_loop_5:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L028enc1_loop_5
+.byte  102,15,56,221,209
+       movups  (%esi),%xmm6
+       paddq   16(%esp),%xmm7
+       leal    16(%esi),%esi
+       jmp     .L029ccm64_dec_outer
+.align 16
+.L029ccm64_dec_outer:
+       xorps   %xmm2,%xmm6
+       movdqa  %xmm7,%xmm2
+       movl    %ebx,%ecx
+       movups  %xmm6,(%edi)
+       leal    16(%edi),%edi
+.byte  102,15,56,0,213
+       subl    $1,%eax
+       jz      .L030ccm64_dec_break
+       movups  (%ebp),%xmm0
+       shrl    $1,%ecx
+       movups  16(%ebp),%xmm1
+       xorps   %xmm0,%xmm6
+       leal    32(%ebp),%edx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm6,%xmm3
+       movups  (%edx),%xmm0
+.L031ccm64_dec2_loop:
+.byte  102,15,56,220,209
+       decl    %ecx
+.byte  102,15,56,220,217
+       movups  16(%edx),%xmm1
+.byte  102,15,56,220,208
+       leal    32(%edx),%edx
+.byte  102,15,56,220,216
+       movups  (%edx),%xmm0
+       jnz     .L031ccm64_dec2_loop
+       movups  (%esi),%xmm6
+       paddq   16(%esp),%xmm7
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       leal    16(%esi),%esi
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+       jmp     .L029ccm64_dec_outer
+.align 16
+.L030ccm64_dec_break:
+       movl    %ebp,%edx
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       xorps   %xmm0,%xmm6
+       leal    32(%edx),%edx
+       xorps   %xmm6,%xmm3
+.L032enc1_loop_6:
+.byte  102,15,56,220,217
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L032enc1_loop_6
+.byte  102,15,56,221,217
+       movl    48(%esp),%esp
+       movl    40(%esp),%edi
+       movups  %xmm3,(%edi)
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.globl _aesni_ctr32_encrypt_blocks
+.def   _aesni_ctr32_encrypt_blocks;    .scl    2;      .type   32;     .endef
+.align 16
+_aesni_ctr32_encrypt_blocks:
+.L_aesni_ctr32_encrypt_blocks_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%esi
+       movl    24(%esp),%edi
+       movl    28(%esp),%eax
+       movl    32(%esp),%edx
+       movl    36(%esp),%ebx
+       movl    %esp,%ebp
+       subl    $88,%esp
+       andl    $-16,%esp
+       movl    %ebp,80(%esp)
+       cmpl    $1,%eax
+       je      .L033ctr32_one_shortcut
+       movdqu  (%ebx),%xmm7
+       movl    $202182159,(%esp)
+       movl    $134810123,4(%esp)
+       movl    $67438087,8(%esp)
+       movl    $66051,12(%esp)
+       movl    $6,%ecx
+       xorl    %ebp,%ebp
+       movl    %ecx,16(%esp)
+       movl    %ecx,20(%esp)
+       movl    %ecx,24(%esp)
+       movl    %ebp,28(%esp)
+.byte  102,15,58,22,251,3
+.byte  102,15,58,34,253,3
+       movl    240(%edx),%ecx
+       bswap   %ebx
+       pxor    %xmm1,%xmm1
+       pxor    %xmm0,%xmm0
+       movdqa  (%esp),%xmm2
+.byte  102,15,58,34,203,0
+       leal    3(%ebx),%ebp
+.byte  102,15,58,34,197,0
+       incl    %ebx
+.byte  102,15,58,34,203,1
+       incl    %ebp
+.byte  102,15,58,34,197,1
+       incl    %ebx
+.byte  102,15,58,34,203,2
+       incl    %ebp
+.byte  102,15,58,34,197,2
+       movdqa  %xmm1,48(%esp)
+.byte  102,15,56,0,202
+       movdqa  %xmm0,64(%esp)
+.byte  102,15,56,0,194
+       pshufd  $192,%xmm1,%xmm2
+       pshufd  $128,%xmm1,%xmm3
+       cmpl    $6,%eax
+       jb      .L034ctr32_tail
+       movdqa  %xmm7,32(%esp)
+       shrl    $1,%ecx
+       movl    %edx,%ebp
+       movl    %ecx,%ebx
+       subl    $6,%eax
+       jmp     .L035ctr32_loop6
+.align 16
+.L035ctr32_loop6:
+       pshufd  $64,%xmm1,%xmm4
+       movdqa  32(%esp),%xmm1
+       pshufd  $192,%xmm0,%xmm5
+       por     %xmm1,%xmm2
+       pshufd  $128,%xmm0,%xmm6
+       por     %xmm1,%xmm3
+       pshufd  $64,%xmm0,%xmm7
+       por     %xmm1,%xmm4
+       por     %xmm1,%xmm5
+       por     %xmm1,%xmm6
+       por     %xmm1,%xmm7
+       movups  (%ebp),%xmm0
+       movups  16(%ebp),%xmm1
+       leal    32(%ebp),%edx
+       decl    %ecx
+       pxor    %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+.byte  102,15,56,220,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,220,217
+       pxor    %xmm0,%xmm5
+.byte  102,15,56,220,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+.byte  102,15,56,220,241
+       movups  (%edx),%xmm0
+.byte  102,15,56,220,249
+       call    .L_aesni_encrypt6_enter
+       movups  (%esi),%xmm1
+       movups  16(%esi),%xmm0
+       xorps   %xmm1,%xmm2
+       movups  32(%esi),%xmm1
+       xorps   %xmm0,%xmm3
+       movups  %xmm2,(%edi)
+       movdqa  16(%esp),%xmm0
+       xorps   %xmm1,%xmm4
+       movdqa  48(%esp),%xmm1
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       paddd   %xmm0,%xmm1
+       paddd   64(%esp),%xmm0
+       movdqa  (%esp),%xmm2
+       movups  48(%esi),%xmm3
+       movups  64(%esi),%xmm4
+       xorps   %xmm3,%xmm5
+       movups  80(%esi),%xmm3
+       leal    96(%esi),%esi
+       movdqa  %xmm1,48(%esp)
+.byte  102,15,56,0,202
+       xorps   %xmm4,%xmm6
+       movups  %xmm5,48(%edi)
+       xorps   %xmm3,%xmm7
+       movdqa  %xmm0,64(%esp)
+.byte  102,15,56,0,194
+       movups  %xmm6,64(%edi)
+       pshufd  $192,%xmm1,%xmm2
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       movl    %ebx,%ecx
+       pshufd  $128,%xmm1,%xmm3
+       subl    $6,%eax
+       jnc     .L035ctr32_loop6
+       addl    $6,%eax
+       jz      .L036ctr32_ret
+       movl    %ebp,%edx
+       leal    1(,%ecx,2),%ecx
+       movdqa  32(%esp),%xmm7
+.L034ctr32_tail:
+       por     %xmm7,%xmm2
+       cmpl    $2,%eax
+       jb      .L037ctr32_one
+       pshufd  $64,%xmm1,%xmm4
+       por     %xmm7,%xmm3
+       je      .L038ctr32_two
+       pshufd  $192,%xmm0,%xmm5
+       por     %xmm7,%xmm4
+       cmpl    $4,%eax
+       jb      .L039ctr32_three
+       pshufd  $128,%xmm0,%xmm6
+       por     %xmm7,%xmm5
+       je      .L040ctr32_four
+       por     %xmm7,%xmm6
+       call    __aesni_encrypt6
+       movups  (%esi),%xmm1
+       movups  16(%esi),%xmm0
+       xorps   %xmm1,%xmm2
+       movups  32(%esi),%xmm1
+       xorps   %xmm0,%xmm3
+       movups  48(%esi),%xmm0
+       xorps   %xmm1,%xmm4
+       movups  64(%esi),%xmm1
+       xorps   %xmm0,%xmm5
+       movups  %xmm2,(%edi)
+       xorps   %xmm1,%xmm6
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       jmp     .L036ctr32_ret
+.align 16
+.L033ctr32_one_shortcut:
+       movups  (%ebx),%xmm2
+       movl    240(%edx),%ecx
+.L037ctr32_one:
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L041enc1_loop_7:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L041enc1_loop_7
+.byte  102,15,56,221,209
+       movups  (%esi),%xmm6
+       xorps   %xmm2,%xmm6
+       movups  %xmm6,(%edi)
+       jmp     .L036ctr32_ret
+.align 16
+.L038ctr32_two:
+       call    __aesni_encrypt3
+       movups  (%esi),%xmm5
+       movups  16(%esi),%xmm6
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       jmp     .L036ctr32_ret
+.align 16
+.L039ctr32_three:
+       call    __aesni_encrypt3
+       movups  (%esi),%xmm5
+       movups  16(%esi),%xmm6
+       xorps   %xmm5,%xmm2
+       movups  32(%esi),%xmm7
+       xorps   %xmm6,%xmm3
+       movups  %xmm2,(%edi)
+       xorps   %xmm7,%xmm4
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       jmp     .L036ctr32_ret
+.align 16
+.L040ctr32_four:
+       call    __aesni_encrypt4
+       movups  (%esi),%xmm6
+       movups  16(%esi),%xmm7
+       movups  32(%esi),%xmm1
+       xorps   %xmm6,%xmm2
+       movups  48(%esi),%xmm0
+       xorps   %xmm7,%xmm3
+       movups  %xmm2,(%edi)
+       xorps   %xmm1,%xmm4
+       movups  %xmm3,16(%edi)
+       xorps   %xmm0,%xmm5
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+.L036ctr32_ret:
+       movl    80(%esp),%esp
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.globl _aesni_xts_encrypt
+.def   _aesni_xts_encrypt;     .scl    2;      .type   32;     .endef
+.align 16
+_aesni_xts_encrypt:
+.L_aesni_xts_encrypt_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    36(%esp),%edx
+       movl    40(%esp),%esi
+       movl    240(%edx),%ecx
+       movups  (%esi),%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L042enc1_loop_8:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L042enc1_loop_8
+.byte  102,15,56,221,209
+       movl    20(%esp),%esi
+       movl    24(%esp),%edi
+       movl    28(%esp),%eax
+       movl    32(%esp),%edx
+       movl    %esp,%ebp
+       subl    $120,%esp
+       movl    240(%edx),%ecx
+       andl    $-16,%esp
+       movl    $135,96(%esp)
+       movl    $0,100(%esp)
+       movl    $1,104(%esp)
+       movl    $0,108(%esp)
+       movl    %eax,112(%esp)
+       movl    %ebp,116(%esp)
+       movdqa  %xmm2,%xmm1
+       pxor    %xmm0,%xmm0
+       movdqa  96(%esp),%xmm3
+       pcmpgtd %xmm1,%xmm0
+       andl    $-16,%eax
+       movl    %edx,%ebp
+       movl    %ecx,%ebx
+       subl    $96,%eax
+       jc      .L043xts_enc_short
+       shrl    $1,%ecx
+       movl    %ecx,%ebx
+       jmp     .L044xts_enc_loop6
+.align 16
+.L044xts_enc_loop6:
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,16(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,32(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,48(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm7
+       movdqa  %xmm1,64(%esp)
+       paddq   %xmm1,%xmm1
+       movups  (%ebp),%xmm0
+       pand    %xmm3,%xmm7
+       movups  (%esi),%xmm2
+       pxor    %xmm1,%xmm7
+       movdqu  16(%esi),%xmm3
+       xorps   %xmm0,%xmm2
+       movdqu  32(%esi),%xmm4
+       pxor    %xmm0,%xmm3
+       movdqu  48(%esi),%xmm5
+       pxor    %xmm0,%xmm4
+       movdqu  64(%esi),%xmm6
+       pxor    %xmm0,%xmm5
+       movdqu  80(%esi),%xmm1
+       pxor    %xmm0,%xmm6
+       leal    96(%esi),%esi
+       pxor    (%esp),%xmm2
+       movdqa  %xmm7,80(%esp)
+       pxor    %xmm1,%xmm7
+       movups  16(%ebp),%xmm1
+       leal    32(%ebp),%edx
+       pxor    16(%esp),%xmm3
+.byte  102,15,56,220,209
+       pxor    32(%esp),%xmm4
+.byte  102,15,56,220,217
+       pxor    48(%esp),%xmm5
+       decl    %ecx
+.byte  102,15,56,220,225
+       pxor    64(%esp),%xmm6
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+.byte  102,15,56,220,241
+       movups  (%edx),%xmm0
+.byte  102,15,56,220,249
+       call    .L_aesni_encrypt6_enter
+       movdqa  80(%esp),%xmm1
+       pxor    %xmm0,%xmm0
+       xorps   (%esp),%xmm2
+       pcmpgtd %xmm1,%xmm0
+       xorps   16(%esp),%xmm3
+       movups  %xmm2,(%edi)
+       xorps   32(%esp),%xmm4
+       movups  %xmm3,16(%edi)
+       xorps   48(%esp),%xmm5
+       movups  %xmm4,32(%edi)
+       xorps   64(%esp),%xmm6
+       movups  %xmm5,48(%edi)
+       xorps   %xmm1,%xmm7
+       movups  %xmm6,64(%edi)
+       pshufd  $19,%xmm0,%xmm2
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       movdqa  96(%esp),%xmm3
+       pxor    %xmm0,%xmm0
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       movl    %ebx,%ecx
+       pxor    %xmm2,%xmm1
+       subl    $96,%eax
+       jnc     .L044xts_enc_loop6
+       leal    1(,%ecx,2),%ecx
+       movl    %ebp,%edx
+       movl    %ecx,%ebx
+.L043xts_enc_short:
+       addl    $96,%eax
+       jz      .L045xts_enc_done6x
+       movdqa  %xmm1,%xmm5
+       cmpl    $32,%eax
+       jb      .L046xts_enc_one
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       je      .L047xts_enc_two
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,%xmm6
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       cmpl    $64,%eax
+       jb      .L048xts_enc_three
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,%xmm7
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       movdqa  %xmm5,(%esp)
+       movdqa  %xmm6,16(%esp)
+       je      .L049xts_enc_four
+       movdqa  %xmm7,32(%esp)
+       pshufd  $19,%xmm0,%xmm7
+       movdqa  %xmm1,48(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm7
+       pxor    %xmm1,%xmm7
+       movdqu  (%esi),%xmm2
+       movdqu  16(%esi),%xmm3
+       movdqu  32(%esi),%xmm4
+       pxor    (%esp),%xmm2
+       movdqu  48(%esi),%xmm5
+       pxor    16(%esp),%xmm3
+       movdqu  64(%esi),%xmm6
+       pxor    32(%esp),%xmm4
+       leal    80(%esi),%esi
+       pxor    48(%esp),%xmm5
+       movdqa  %xmm7,64(%esp)
+       pxor    %xmm7,%xmm6
+       call    __aesni_encrypt6
+       movaps  64(%esp),%xmm1
+       xorps   (%esp),%xmm2
+       xorps   16(%esp),%xmm3
+       xorps   32(%esp),%xmm4
+       movups  %xmm2,(%edi)
+       xorps   48(%esp),%xmm5
+       movups  %xmm3,16(%edi)
+       xorps   %xmm1,%xmm6
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       leal    80(%edi),%edi
+       jmp     .L050xts_enc_done
+.align 16
+.L046xts_enc_one:
+       movups  (%esi),%xmm2
+       leal    16(%esi),%esi
+       xorps   %xmm5,%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L051enc1_loop_9:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L051enc1_loop_9
+.byte  102,15,56,221,209
+       xorps   %xmm5,%xmm2
+       movups  %xmm2,(%edi)
+       leal    16(%edi),%edi
+       movdqa  %xmm5,%xmm1
+       jmp     .L050xts_enc_done
+.align 16
+.L047xts_enc_two:
+       movaps  %xmm1,%xmm6
+       movups  (%esi),%xmm2
+       movups  16(%esi),%xmm3
+       leal    32(%esi),%esi
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       xorps   %xmm4,%xmm4
+       call    __aesni_encrypt3
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       leal    32(%edi),%edi
+       movdqa  %xmm6,%xmm1
+       jmp     .L050xts_enc_done
+.align 16
+.L048xts_enc_three:
+       movaps  %xmm1,%xmm7
+       movups  (%esi),%xmm2
+       movups  16(%esi),%xmm3
+       movups  32(%esi),%xmm4
+       leal    48(%esi),%esi
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       xorps   %xmm7,%xmm4
+       call    __aesni_encrypt3
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       xorps   %xmm7,%xmm4
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       leal    48(%edi),%edi
+       movdqa  %xmm7,%xmm1
+       jmp     .L050xts_enc_done
+.align 16
+.L049xts_enc_four:
+       movaps  %xmm1,%xmm6
+       movups  (%esi),%xmm2
+       movups  16(%esi),%xmm3
+       movups  32(%esi),%xmm4
+       xorps   (%esp),%xmm2
+       movups  48(%esi),%xmm5
+       leal    64(%esi),%esi
+       xorps   16(%esp),%xmm3
+       xorps   %xmm7,%xmm4
+       xorps   %xmm6,%xmm5
+       call    __aesni_encrypt4
+       xorps   (%esp),%xmm2
+       xorps   16(%esp),%xmm3
+       xorps   %xmm7,%xmm4
+       movups  %xmm2,(%edi)
+       xorps   %xmm6,%xmm5
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       leal    64(%edi),%edi
+       movdqa  %xmm6,%xmm1
+       jmp     .L050xts_enc_done
+.align 16
+.L045xts_enc_done6x:
+       movl    112(%esp),%eax
+       andl    $15,%eax
+       jz      .L052xts_enc_ret
+       movdqa  %xmm1,%xmm5
+       movl    %eax,112(%esp)
+       jmp     .L053xts_enc_steal
+.align 16
+.L050xts_enc_done:
+       movl    112(%esp),%eax
+       pxor    %xmm0,%xmm0
+       andl    $15,%eax
+       jz      .L052xts_enc_ret
+       pcmpgtd %xmm1,%xmm0
+       movl    %eax,112(%esp)
+       pshufd  $19,%xmm0,%xmm5
+       paddq   %xmm1,%xmm1
+       pand    96(%esp),%xmm5
+       pxor    %xmm1,%xmm5
+.L053xts_enc_steal:
+       movzbl  (%esi),%ecx
+       movzbl  -16(%edi),%edx
+       leal    1(%esi),%esi
+       movb    %cl,-16(%edi)
+       movb    %dl,(%edi)
+       leal    1(%edi),%edi
+       subl    $1,%eax
+       jnz     .L053xts_enc_steal
+       subl    112(%esp),%edi
+       movl    %ebp,%edx
+       movl    %ebx,%ecx
+       movups  -16(%edi),%xmm2
+       xorps   %xmm5,%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L054enc1_loop_10:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L054enc1_loop_10
+.byte  102,15,56,221,209
+       xorps   %xmm5,%xmm2
+       movups  %xmm2,-16(%edi)
+.L052xts_enc_ret:
+       movl    116(%esp),%esp
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.globl _aesni_xts_decrypt
+.def   _aesni_xts_decrypt;     .scl    2;      .type   32;     .endef
+.align 16
+_aesni_xts_decrypt:
+.L_aesni_xts_decrypt_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    36(%esp),%edx
+       movl    40(%esp),%esi
+       movl    240(%edx),%ecx
+       movups  (%esi),%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L055enc1_loop_11:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L055enc1_loop_11
+.byte  102,15,56,221,209
+       movl    20(%esp),%esi
+       movl    24(%esp),%edi
+       movl    28(%esp),%eax
+       movl    32(%esp),%edx
+       movl    %esp,%ebp
+       subl    $120,%esp
+       andl    $-16,%esp
+       xorl    %ebx,%ebx
+       testl   $15,%eax
+       setnz   %bl
+       shll    $4,%ebx
+       subl    %ebx,%eax
+       movl    $135,96(%esp)
+       movl    $0,100(%esp)
+       movl    $1,104(%esp)
+       movl    $0,108(%esp)
+       movl    %eax,112(%esp)
+       movl    %ebp,116(%esp)
+       movl    240(%edx),%ecx
+       movl    %edx,%ebp
+       movl    %ecx,%ebx
+       movdqa  %xmm2,%xmm1
+       pxor    %xmm0,%xmm0
+       movdqa  96(%esp),%xmm3
+       pcmpgtd %xmm1,%xmm0
+       andl    $-16,%eax
+       subl    $96,%eax
+       jc      .L056xts_dec_short
+       shrl    $1,%ecx
+       movl    %ecx,%ebx
+       jmp     .L057xts_dec_loop6
+.align 16
+.L057xts_dec_loop6:
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,16(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,32(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,48(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm7
+       movdqa  %xmm1,64(%esp)
+       paddq   %xmm1,%xmm1
+       movups  (%ebp),%xmm0
+       pand    %xmm3,%xmm7
+       movups  (%esi),%xmm2
+       pxor    %xmm1,%xmm7
+       movdqu  16(%esi),%xmm3
+       xorps   %xmm0,%xmm2
+       movdqu  32(%esi),%xmm4
+       pxor    %xmm0,%xmm3
+       movdqu  48(%esi),%xmm5
+       pxor    %xmm0,%xmm4
+       movdqu  64(%esi),%xmm6
+       pxor    %xmm0,%xmm5
+       movdqu  80(%esi),%xmm1
+       pxor    %xmm0,%xmm6
+       leal    96(%esi),%esi
+       pxor    (%esp),%xmm2
+       movdqa  %xmm7,80(%esp)
+       pxor    %xmm1,%xmm7
+       movups  16(%ebp),%xmm1
+       leal    32(%ebp),%edx
+       pxor    16(%esp),%xmm3
+.byte  102,15,56,222,209
+       pxor    32(%esp),%xmm4
+.byte  102,15,56,222,217
+       pxor    48(%esp),%xmm5
+       decl    %ecx
+.byte  102,15,56,222,225
+       pxor    64(%esp),%xmm6
+.byte  102,15,56,222,233
+       pxor    %xmm0,%xmm7
+.byte  102,15,56,222,241
+       movups  (%edx),%xmm0
+.byte  102,15,56,222,249
+       call    .L_aesni_decrypt6_enter
+       movdqa  80(%esp),%xmm1
+       pxor    %xmm0,%xmm0
+       xorps   (%esp),%xmm2
+       pcmpgtd %xmm1,%xmm0
+       xorps   16(%esp),%xmm3
+       movups  %xmm2,(%edi)
+       xorps   32(%esp),%xmm4
+       movups  %xmm3,16(%edi)
+       xorps   48(%esp),%xmm5
+       movups  %xmm4,32(%edi)
+       xorps   64(%esp),%xmm6
+       movups  %xmm5,48(%edi)
+       xorps   %xmm1,%xmm7
+       movups  %xmm6,64(%edi)
+       pshufd  $19,%xmm0,%xmm2
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       movdqa  96(%esp),%xmm3
+       pxor    %xmm0,%xmm0
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       movl    %ebx,%ecx
+       pxor    %xmm2,%xmm1
+       subl    $96,%eax
+       jnc     .L057xts_dec_loop6
+       leal    1(,%ecx,2),%ecx
+       movl    %ebp,%edx
+       movl    %ecx,%ebx
+.L056xts_dec_short:
+       addl    $96,%eax
+       jz      .L058xts_dec_done6x
+       movdqa  %xmm1,%xmm5
+       cmpl    $32,%eax
+       jb      .L059xts_dec_one
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       je      .L060xts_dec_two
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,%xmm6
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       cmpl    $64,%eax
+       jb      .L061xts_dec_three
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,%xmm7
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       movdqa  %xmm5,(%esp)
+       movdqa  %xmm6,16(%esp)
+       je      .L062xts_dec_four
+       movdqa  %xmm7,32(%esp)
+       pshufd  $19,%xmm0,%xmm7
+       movdqa  %xmm1,48(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm7
+       pxor    %xmm1,%xmm7
+       movdqu  (%esi),%xmm2
+       movdqu  16(%esi),%xmm3
+       movdqu  32(%esi),%xmm4
+       pxor    (%esp),%xmm2
+       movdqu  48(%esi),%xmm5
+       pxor    16(%esp),%xmm3
+       movdqu  64(%esi),%xmm6
+       pxor    32(%esp),%xmm4
+       leal    80(%esi),%esi
+       pxor    48(%esp),%xmm5
+       movdqa  %xmm7,64(%esp)
+       pxor    %xmm7,%xmm6
+       call    __aesni_decrypt6
+       movaps  64(%esp),%xmm1
+       xorps   (%esp),%xmm2
+       xorps   16(%esp),%xmm3
+       xorps   32(%esp),%xmm4
+       movups  %xmm2,(%edi)
+       xorps   48(%esp),%xmm5
+       movups  %xmm3,16(%edi)
+       xorps   %xmm1,%xmm6
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       leal    80(%edi),%edi
+       jmp     .L063xts_dec_done
+.align 16
+.L059xts_dec_one:
+       movups  (%esi),%xmm2
+       leal    16(%esi),%esi
+       xorps   %xmm5,%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L064dec1_loop_12:
+.byte  102,15,56,222,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L064dec1_loop_12
+.byte  102,15,56,223,209
+       xorps   %xmm5,%xmm2
+       movups  %xmm2,(%edi)
+       leal    16(%edi),%edi
+       movdqa  %xmm5,%xmm1
+       jmp     .L063xts_dec_done
+.align 16
+.L060xts_dec_two:
+       movaps  %xmm1,%xmm6
+       movups  (%esi),%xmm2
+       movups  16(%esi),%xmm3
+       leal    32(%esi),%esi
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       call    __aesni_decrypt3
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       leal    32(%edi),%edi
+       movdqa  %xmm6,%xmm1
+       jmp     .L063xts_dec_done
+.align 16
+.L061xts_dec_three:
+       movaps  %xmm1,%xmm7
+       movups  (%esi),%xmm2
+       movups  16(%esi),%xmm3
+       movups  32(%esi),%xmm4
+       leal    48(%esi),%esi
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       xorps   %xmm7,%xmm4
+       call    __aesni_decrypt3
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       xorps   %xmm7,%xmm4
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       leal    48(%edi),%edi
+       movdqa  %xmm7,%xmm1
+       jmp     .L063xts_dec_done
+.align 16
+.L062xts_dec_four:
+       movaps  %xmm1,%xmm6
+       movups  (%esi),%xmm2
+       movups  16(%esi),%xmm3
+       movups  32(%esi),%xmm4
+       xorps   (%esp),%xmm2
+       movups  48(%esi),%xmm5
+       leal    64(%esi),%esi
+       xorps   16(%esp),%xmm3
+       xorps   %xmm7,%xmm4
+       xorps   %xmm6,%xmm5
+       call    __aesni_decrypt4
+       xorps   (%esp),%xmm2
+       xorps   16(%esp),%xmm3
+       xorps   %xmm7,%xmm4
+       movups  %xmm2,(%edi)
+       xorps   %xmm6,%xmm5
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       leal    64(%edi),%edi
+       movdqa  %xmm6,%xmm1
+       jmp     .L063xts_dec_done
+.align 16
+.L058xts_dec_done6x:
+       movl    112(%esp),%eax
+       andl    $15,%eax
+       jz      .L065xts_dec_ret
+       movl    %eax,112(%esp)
+       jmp     .L066xts_dec_only_one_more
+.align 16
+.L063xts_dec_done:
+       movl    112(%esp),%eax
+       pxor    %xmm0,%xmm0
+       andl    $15,%eax
+       jz      .L065xts_dec_ret
+       pcmpgtd %xmm1,%xmm0
+       movl    %eax,112(%esp)
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  96(%esp),%xmm3
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+.L066xts_dec_only_one_more:
+       pshufd  $19,%xmm0,%xmm5
+       movdqa  %xmm1,%xmm6
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm5
+       pxor    %xmm1,%xmm5
+       movl    %ebp,%edx
+       movl    %ebx,%ecx
+       movups  (%esi),%xmm2
+       xorps   %xmm5,%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L067dec1_loop_13:
+.byte  102,15,56,222,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L067dec1_loop_13
+.byte  102,15,56,223,209
+       xorps   %xmm5,%xmm2
+       movups  %xmm2,(%edi)
+.L068xts_dec_steal:
+       movzbl  16(%esi),%ecx
+       movzbl  (%edi),%edx
+       leal    1(%esi),%esi
+       movb    %cl,(%edi)
+       movb    %dl,16(%edi)
+       leal    1(%edi),%edi
+       subl    $1,%eax
+       jnz     .L068xts_dec_steal
+       subl    112(%esp),%edi
+       movl    %ebp,%edx
+       movl    %ebx,%ecx
+       movups  (%edi),%xmm2
+       xorps   %xmm6,%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L069dec1_loop_14:
+.byte  102,15,56,222,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L069dec1_loop_14
+.byte  102,15,56,223,209
+       xorps   %xmm6,%xmm2
+       movups  %xmm2,(%edi)
+.L065xts_dec_ret:
+       movl    116(%esp),%esp
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.globl _aesni_cbc_encrypt
+.def   _aesni_cbc_encrypt;     .scl    2;      .type   32;     .endef
+.align 16
+_aesni_cbc_encrypt:
+.L_aesni_cbc_encrypt_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%esi
+       movl    %esp,%ebx
+       movl    24(%esp),%edi
+       subl    $24,%ebx
+       movl    28(%esp),%eax
+       andl    $-16,%ebx
+       movl    32(%esp),%edx
+       movl    36(%esp),%ebp
+       testl   %eax,%eax
+       jz      .L070cbc_abort
+       cmpl    $0,40(%esp)
+       xchgl   %esp,%ebx
+       movups  (%ebp),%xmm7
+       movl    240(%edx),%ecx
+       movl    %edx,%ebp
+       movl    %ebx,16(%esp)
+       movl    %ecx,%ebx
+       je      .L071cbc_decrypt
+       movaps  %xmm7,%xmm2
+       cmpl    $16,%eax
+       jb      .L072cbc_enc_tail
+       subl    $16,%eax
+       jmp     .L073cbc_enc_loop
+.align 16
+.L073cbc_enc_loop:
+       movups  (%esi),%xmm7
+       leal    16(%esi),%esi
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       xorps   %xmm0,%xmm7
+       leal    32(%edx),%edx
+       xorps   %xmm7,%xmm2
+.L074enc1_loop_15:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L074enc1_loop_15
+.byte  102,15,56,221,209
+       movl    %ebx,%ecx
+       movl    %ebp,%edx
+       movups  %xmm2,(%edi)
+       leal    16(%edi),%edi
+       subl    $16,%eax
+       jnc     .L073cbc_enc_loop
+       addl    $16,%eax
+       jnz     .L072cbc_enc_tail
+       movaps  %xmm2,%xmm7
+       jmp     .L075cbc_ret
+.L072cbc_enc_tail:
+       movl    %eax,%ecx
+.long  2767451785
+       movl    $16,%ecx
+       subl    %eax,%ecx
+       xorl    %eax,%eax
+.long  2868115081
+       leal    -16(%edi),%edi
+       movl    %ebx,%ecx
+       movl    %edi,%esi
+       movl    %ebp,%edx
+       jmp     .L073cbc_enc_loop
+.align 16
+.L071cbc_decrypt:
+       cmpl    $80,%eax
+       jbe     .L076cbc_dec_tail
+       movaps  %xmm7,(%esp)
+       subl    $80,%eax
+       jmp     .L077cbc_dec_loop6_enter
+.align 16
+.L078cbc_dec_loop6:
+       movaps  %xmm0,(%esp)
+       movups  %xmm7,(%edi)
+       leal    16(%edi),%edi
+.L077cbc_dec_loop6_enter:
+       movdqu  (%esi),%xmm2
+       movdqu  16(%esi),%xmm3
+       movdqu  32(%esi),%xmm4
+       movdqu  48(%esi),%xmm5
+       movdqu  64(%esi),%xmm6
+       movdqu  80(%esi),%xmm7
+       call    __aesni_decrypt6
+       movups  (%esi),%xmm1
+       movups  16(%esi),%xmm0
+       xorps   (%esp),%xmm2
+       xorps   %xmm1,%xmm3
+       movups  32(%esi),%xmm1
+       xorps   %xmm0,%xmm4
+       movups  48(%esi),%xmm0
+       xorps   %xmm1,%xmm5
+       movups  64(%esi),%xmm1
+       xorps   %xmm0,%xmm6
+       movups  80(%esi),%xmm0
+       xorps   %xmm1,%xmm7
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       leal    96(%esi),%esi
+       movups  %xmm4,32(%edi)
+       movl    %ebx,%ecx
+       movups  %xmm5,48(%edi)
+       movl    %ebp,%edx
+       movups  %xmm6,64(%edi)
+       leal    80(%edi),%edi
+       subl    $96,%eax
+       ja      .L078cbc_dec_loop6
+       movaps  %xmm7,%xmm2
+       movaps  %xmm0,%xmm7
+       addl    $80,%eax
+       jle     .L079cbc_dec_tail_collected
+       movups  %xmm2,(%edi)
+       leal    16(%edi),%edi
+.L076cbc_dec_tail:
+       movups  (%esi),%xmm2
+       movaps  %xmm2,%xmm6
+       cmpl    $16,%eax
+       jbe     .L080cbc_dec_one
+       movups  16(%esi),%xmm3
+       movaps  %xmm3,%xmm5
+       cmpl    $32,%eax
+       jbe     .L081cbc_dec_two
+       movups  32(%esi),%xmm4
+       cmpl    $48,%eax
+       jbe     .L082cbc_dec_three
+       movups  48(%esi),%xmm5
+       cmpl    $64,%eax
+       jbe     .L083cbc_dec_four
+       movups  64(%esi),%xmm6
+       movaps  %xmm7,(%esp)
+       movups  (%esi),%xmm2
+       xorps   %xmm7,%xmm7
+       call    __aesni_decrypt6
+       movups  (%esi),%xmm1
+       movups  16(%esi),%xmm0
+       xorps   (%esp),%xmm2
+       xorps   %xmm1,%xmm3
+       movups  32(%esi),%xmm1
+       xorps   %xmm0,%xmm4
+       movups  48(%esi),%xmm0
+       xorps   %xmm1,%xmm5
+       movups  64(%esi),%xmm7
+       xorps   %xmm0,%xmm6
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       leal    64(%edi),%edi
+       movaps  %xmm6,%xmm2
+       subl    $80,%eax
+       jmp     .L079cbc_dec_tail_collected
+.align 16
+.L080cbc_dec_one:
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L084dec1_loop_16:
+.byte  102,15,56,222,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L084dec1_loop_16
+.byte  102,15,56,223,209
+       xorps   %xmm7,%xmm2
+       movaps  %xmm6,%xmm7
+       subl    $16,%eax
+       jmp     .L079cbc_dec_tail_collected
+.align 16
+.L081cbc_dec_two:
+       xorps   %xmm4,%xmm4
+       call    __aesni_decrypt3
+       xorps   %xmm7,%xmm2
+       xorps   %xmm6,%xmm3
+       movups  %xmm2,(%edi)
+       movaps  %xmm3,%xmm2
+       leal    16(%edi),%edi
+       movaps  %xmm5,%xmm7
+       subl    $32,%eax
+       jmp     .L079cbc_dec_tail_collected
+.align 16
+.L082cbc_dec_three:
+       call    __aesni_decrypt3
+       xorps   %xmm7,%xmm2
+       xorps   %xmm6,%xmm3
+       xorps   %xmm5,%xmm4
+       movups  %xmm2,(%edi)
+       movaps  %xmm4,%xmm2
+       movups  %xmm3,16(%edi)
+       leal    32(%edi),%edi
+       movups  32(%esi),%xmm7
+       subl    $48,%eax
+       jmp     .L079cbc_dec_tail_collected
+.align 16
+.L083cbc_dec_four:
+       call    __aesni_decrypt4
+       movups  16(%esi),%xmm1
+       movups  32(%esi),%xmm0
+       xorps   %xmm7,%xmm2
+       movups  48(%esi),%xmm7
+       xorps   %xmm6,%xmm3
+       movups  %xmm2,(%edi)
+       xorps   %xmm1,%xmm4
+       movups  %xmm3,16(%edi)
+       xorps   %xmm0,%xmm5
+       movups  %xmm4,32(%edi)
+       leal    48(%edi),%edi
+       movaps  %xmm5,%xmm2
+       subl    $64,%eax
+.L079cbc_dec_tail_collected:
+       andl    $15,%eax
+       jnz     .L085cbc_dec_tail_partial
+       movups  %xmm2,(%edi)
+       jmp     .L075cbc_ret
+.align 16
+.L085cbc_dec_tail_partial:
+       movaps  %xmm2,(%esp)
+       movl    $16,%ecx
+       movl    %esp,%esi
+       subl    %eax,%ecx
+.long  2767451785
+.L075cbc_ret:
+       movl    16(%esp),%esp
+       movl    36(%esp),%ebp
+       movups  %xmm7,(%ebp)
+.L070cbc_abort:
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.def   __aesni_set_encrypt_key;        .scl    3;      .type   32;     .endef
+.align 16
+__aesni_set_encrypt_key:
+       testl   %eax,%eax
+       jz      .L086bad_pointer
+       testl   %edx,%edx
+       jz      .L086bad_pointer
+       movups  (%eax),%xmm0
+       xorps   %xmm4,%xmm4
+       leal    16(%edx),%edx
+       cmpl    $256,%ecx
+       je      .L08714rounds
+       cmpl    $192,%ecx
+       je      .L08812rounds
+       cmpl    $128,%ecx
+       jne     .L089bad_keybits
+.align 16
+.L09010rounds:
+       movl    $9,%ecx
+       movups  %xmm0,-16(%edx)
+.byte  102,15,58,223,200,1
+       call    .L091key_128_cold
+.byte  102,15,58,223,200,2
+       call    .L092key_128
+.byte  102,15,58,223,200,4
+       call    .L092key_128
+.byte  102,15,58,223,200,8
+       call    .L092key_128
+.byte  102,15,58,223,200,16
+       call    .L092key_128
+.byte  102,15,58,223,200,32
+       call    .L092key_128
+.byte  102,15,58,223,200,64
+       call    .L092key_128
+.byte  102,15,58,223,200,128
+       call    .L092key_128
+.byte  102,15,58,223,200,27
+       call    .L092key_128
+.byte  102,15,58,223,200,54
+       call    .L092key_128
+       movups  %xmm0,(%edx)
+       movl    %ecx,80(%edx)
+       xorl    %eax,%eax
+       ret
+.align 16
+.L092key_128:
+       movups  %xmm0,(%edx)
+       leal    16(%edx),%edx
+.L091key_128_cold:
+       shufps  $16,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $140,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $255,%xmm1,%xmm1
+       xorps   %xmm1,%xmm0
+       ret
+.align 16
+.L08812rounds:
+       movq    16(%eax),%xmm2
+       movl    $11,%ecx
+       movups  %xmm0,-16(%edx)
+.byte  102,15,58,223,202,1
+       call    .L093key_192a_cold
+.byte  102,15,58,223,202,2
+       call    .L094key_192b
+.byte  102,15,58,223,202,4
+       call    .L095key_192a
+.byte  102,15,58,223,202,8
+       call    .L094key_192b
+.byte  102,15,58,223,202,16
+       call    .L095key_192a
+.byte  102,15,58,223,202,32
+       call    .L094key_192b
+.byte  102,15,58,223,202,64
+       call    .L095key_192a
+.byte  102,15,58,223,202,128
+       call    .L094key_192b
+       movups  %xmm0,(%edx)
+       movl    %ecx,48(%edx)
+       xorl    %eax,%eax
+       ret
+.align 16
+.L095key_192a:
+       movups  %xmm0,(%edx)
+       leal    16(%edx),%edx
+.align 16
+.L093key_192a_cold:
+       movaps  %xmm2,%xmm5
+.L096key_192b_warm:
+       shufps  $16,%xmm0,%xmm4
+       movdqa  %xmm2,%xmm3
+       xorps   %xmm4,%xmm0
+       shufps  $140,%xmm0,%xmm4
+       pslldq  $4,%xmm3
+       xorps   %xmm4,%xmm0
+       pshufd  $85,%xmm1,%xmm1
+       pxor    %xmm3,%xmm2
+       pxor    %xmm1,%xmm0
+       pshufd  $255,%xmm0,%xmm3
+       pxor    %xmm3,%xmm2
+       ret
+.align 16
+.L094key_192b:
+       movaps  %xmm0,%xmm3
+       shufps  $68,%xmm0,%xmm5
+       movups  %xmm5,(%edx)
+       shufps  $78,%xmm2,%xmm3
+       movups  %xmm3,16(%edx)
+       leal    32(%edx),%edx
+       jmp     .L096key_192b_warm
+.align 16
+.L08714rounds:
+       movups  16(%eax),%xmm2
+       movl    $13,%ecx
+       leal    16(%edx),%edx
+       movups  %xmm0,-32(%edx)
+       movups  %xmm2,-16(%edx)
+.byte  102,15,58,223,202,1
+       call    .L097key_256a_cold
+.byte  102,15,58,223,200,1
+       call    .L098key_256b
+.byte  102,15,58,223,202,2
+       call    .L099key_256a
+.byte  102,15,58,223,200,2
+       call    .L098key_256b
+.byte  102,15,58,223,202,4
+       call    .L099key_256a
+.byte  102,15,58,223,200,4
+       call    .L098key_256b
+.byte  102,15,58,223,202,8
+       call    .L099key_256a
+.byte  102,15,58,223,200,8
+       call    .L098key_256b
+.byte  102,15,58,223,202,16
+       call    .L099key_256a
+.byte  102,15,58,223,200,16
+       call    .L098key_256b
+.byte  102,15,58,223,202,32
+       call    .L099key_256a
+.byte  102,15,58,223,200,32
+       call    .L098key_256b
+.byte  102,15,58,223,202,64
+       call    .L099key_256a
+       movups  %xmm0,(%edx)
+       movl    %ecx,16(%edx)
+       xorl    %eax,%eax
+       ret
+.align 16
+.L099key_256a:
+       movups  %xmm2,(%edx)
+       leal    16(%edx),%edx
+.L097key_256a_cold:
+       shufps  $16,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $140,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $255,%xmm1,%xmm1
+       xorps   %xmm1,%xmm0
+       ret
+.align 16
+.L098key_256b:
+       movups  %xmm0,(%edx)
+       leal    16(%edx),%edx
+       shufps  $16,%xmm2,%xmm4
+       xorps   %xmm4,%xmm2
+       shufps  $140,%xmm2,%xmm4
+       xorps   %xmm4,%xmm2
+       shufps  $170,%xmm1,%xmm1
+       xorps   %xmm1,%xmm2
+       ret
+.align 4
+.L086bad_pointer:
+       movl    $-1,%eax
+       ret
+.align 4
+.L089bad_keybits:
+       movl    $-2,%eax
+       ret
+.globl _aesni_set_encrypt_key
+.def   _aesni_set_encrypt_key; .scl    2;      .type   32;     .endef
+.align 16
+_aesni_set_encrypt_key:
+.L_aesni_set_encrypt_key_begin:
+       movl    4(%esp),%eax
+       movl    8(%esp),%ecx
+       movl    12(%esp),%edx
+       call    __aesni_set_encrypt_key
+       ret
+.globl _aesni_set_decrypt_key
+.def   _aesni_set_decrypt_key; .scl    2;      .type   32;     .endef
+.align 16
+_aesni_set_decrypt_key:
+.L_aesni_set_decrypt_key_begin:
+       movl    4(%esp),%eax
+       movl    8(%esp),%ecx
+       movl    12(%esp),%edx
+       call    __aesni_set_encrypt_key
+       movl    12(%esp),%edx
+       shll    $4,%ecx
+       testl   %eax,%eax
+       jnz     .L100dec_key_ret
+       leal    16(%edx,%ecx,1),%eax
+       movups  (%edx),%xmm0
+       movups  (%eax),%xmm1
+       movups  %xmm0,(%eax)
+       movups  %xmm1,(%edx)
+       leal    16(%edx),%edx
+       leal    -16(%eax),%eax
+.L101dec_key_inverse:
+       movups  (%edx),%xmm0
+       movups  (%eax),%xmm1
+.byte  102,15,56,219,192
+.byte  102,15,56,219,201
+       leal    16(%edx),%edx
+       leal    -16(%eax),%eax
+       movups  %xmm0,16(%eax)
+       movups  %xmm1,-16(%edx)
+       cmpl    %edx,%eax
+       ja      .L101dec_key_inverse
+       movups  (%edx),%xmm0
+.byte  102,15,56,219,192
+       movups  %xmm0,(%edx)
+       xorl    %eax,%eax
+.L100dec_key_ret:
+       ret
+.byte  65,69,83,32,102,111,114,32,73,110,116,101,108,32,65,69
+.byte  83,45,78,73,44,32,67,82,89,80,84,79,71,65,77,83
+.byte  32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115
+.byte  115,108,46,111,114,103,62,0
diff --git a/lib/accelerated/x86/asm-coff/cpuid-x86-64-coff.s 
b/lib/accelerated/x86/asm-coff/cpuid-x86-64-coff.s
new file mode 100644
index 0000000..d2336e7
--- /dev/null
+++ b/lib/accelerated/x86/asm-coff/cpuid-x86-64-coff.s
@@ -0,0 +1,56 @@
+#
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# Author: Nikos Mavrogiannopoulos
+#
+# This file is part of GnuTLS.
+#
+# The GnuTLS is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 3 of
+# the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+       .file "cpuid.asm"
+        
+       .text
+.globl __gnutls_cpuid
+.def   __gnutls_cpuid; .scl 2; .type 32;       .endef
+.p2align 4
+__gnutls_cpuid:
+       pushq   %rbp
+       movq    %rsp, %rbp
+       pushq   %rbx
+       movl    %edi, -12(%rbp)
+       movq    %rsi, -24(%rbp)
+       movq    %rdx, -32(%rbp)
+       movq    %rcx, -40(%rbp)
+       movq    %r8, -48(%rbp)
+       movl    -12(%rbp), %eax
+       movl    %eax, -60(%rbp)
+       movl    -60(%rbp), %eax
+       cpuid
+       movl    %edx, -56(%rbp)
+       movl    %ecx, %esi
+       movl    %eax, -52(%rbp)
+       movq    -24(%rbp), %rax
+       movl    -52(%rbp), %edx
+       movl    %edx, (%rax)
+       movq    -32(%rbp), %rax
+       movl    %ebx, (%rax)
+       movq    -40(%rbp), %rax
+       movl    %esi, (%rax)
+       movq    -48(%rbp), %rax
+       movl    -56(%rbp), %ecx
+       movl    %ecx, (%rax)
+       popq    %rbx
+       leave
+       ret
diff --git a/lib/accelerated/x86/asm-coff/cpuid-x86-coff.s 
b/lib/accelerated/x86/asm-coff/cpuid-x86-coff.s
new file mode 100644
index 0000000..92b95db
--- /dev/null
+++ b/lib/accelerated/x86/asm-coff/cpuid-x86-coff.s
@@ -0,0 +1,68 @@
+#
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# Author: Nikos Mavrogiannopoulos
+#
+# This file is part of GnuTLS.
+#
+# The GnuTLS is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 3 of
+# the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+       .file "cpuid.asm"
+        
+       .text
+.globl __gnutls_cpuid
+.def   __gnutls_cpuid; .scl    2;      .type   32;     .endef
+.align 16
+__gnutls_cpuid:
+       pushl   %ebp
+       movl    %esp, %ebp
+       subl    $12, %esp
+       movl    %ebx, (%esp)
+       movl    8(%ebp), %eax
+       movl    %esi, 4(%esp)
+       movl    %edi, 8(%esp)
+       pushl %ebx
+       cpuid
+       movl %ebx, %edi
+       popl %ebx
+       movl    %edx, %esi
+       movl    12(%ebp), %edx
+       movl    %eax, (%edx)
+       movl    16(%ebp), %eax
+       movl    %edi, (%eax)
+       movl    20(%ebp), %eax
+       movl    %ecx, (%eax)
+       movl    24(%ebp), %eax
+       movl    %esi, (%eax)
+       movl    (%esp), %ebx
+       movl    4(%esp), %esi
+       movl    8(%esp), %edi
+       movl    %ebp, %esp
+       popl    %ebp
+       ret
+
+.globl __gnutls_have_cpuid
+.def   __gnutls_have_cpuid;    .scl    2;      .type   32;     .endef
+.align 16
+__gnutls_have_cpuid:
+       pushfl  
+       pop %eax        
+       orl $0x200000, %eax     
+       push %eax       
+       popfl   
+       pushfl  
+       pop %eax        
+       andl $0x200000, %eax    
+       ret
diff --git a/lib/accelerated/x86/asm-coff/padlock-x86-64-coff.s 
b/lib/accelerated/x86/asm-coff/padlock-x86-64-coff.s
new file mode 100644
index 0000000..4701809
--- /dev/null
+++ b/lib/accelerated/x86/asm-coff/padlock-x86-64-coff.s
@@ -0,0 +1,606 @@
+# Copyright (c) 2011, Andy Polyakov by <address@hidden>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 
+#     * Redistributions of source code must retain copyright notices,
+#      this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+#
+#     * Neither the name of the Andy Polyakov nor the names of its
+#      copyright holder and contributors may be used to endorse or
+#      promote products derived from this software without specific
+#      prior written permission.
+#
+# ALTERNATIVELY, provided that this notice is retained in full, this
+# product may be distributed under the terms of the GNU General Public
+# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+# those given above.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.text  
+.globl padlock_capability
+.def   padlock_capability;     .scl 2; .type 32;       .endef
+.p2align       4
+padlock_capability:
+       movq    %rbx,%r8
+       xorl    %eax,%eax
+       cpuid
+       xorl    %eax,%eax
+       cmpl    $1953391939,%ebx
+       jne     .Lnoluck
+       cmpl    $1215460705,%edx
+       jne     .Lnoluck
+       cmpl    $1936487777,%ecx
+       jne     .Lnoluck
+       movl    $3221225472,%eax
+       cpuid
+       movl    %eax,%edx
+       xorl    %eax,%eax
+       cmpl    $3221225473,%edx
+       jb      .Lnoluck
+       movl    $3221225473,%eax
+       cpuid
+       movl    %edx,%eax
+       andl    $4294967279,%eax
+       orl     $16,%eax
+.Lnoluck:
+       movq    %r8,%rbx
+       .byte   0xf3,0xc3
+
+
+.globl padlock_key_bswap
+.def   padlock_key_bswap;      .scl 2; .type 32;       .endef
+.p2align       4
+padlock_key_bswap:
+       movl    240(%rcx),%edx
+.Lbswap_loop:
+       movl    (%rcx),%eax
+       bswapl  %eax
+       movl    %eax,(%rcx)
+       leaq    4(%rcx),%rcx
+       subl    $1,%edx
+       jnz     .Lbswap_loop
+       .byte   0xf3,0xc3
+
+
+.globl padlock_verify_context
+.def   padlock_verify_context; .scl 2; .type 32;       .endef
+.p2align       4
+padlock_verify_context:
+       movq    %rcx,%rdx
+       pushf
+       leaq    .Lpadlock_saved_context(%rip),%rax
+       call    _padlock_verify_ctx
+       leaq    8(%rsp),%rsp
+       .byte   0xf3,0xc3
+
+
+.def   _padlock_verify_ctx;    .scl 3; .type 32;       .endef
+.p2align       4
+_padlock_verify_ctx:
+       movq    8(%rsp),%r8
+       btq     $30,%r8
+       jnc     .Lverified
+       cmpq    (%rax),%rdx
+       je      .Lverified
+       pushf
+       popf
+.Lverified:
+       movq    %rdx,(%rax)
+       .byte   0xf3,0xc3
+
+
+.globl padlock_reload_key
+.def   padlock_reload_key;     .scl 2; .type 32;       .endef
+.p2align       4
+padlock_reload_key:
+       pushf
+       popf
+       .byte   0xf3,0xc3
+
+
+.globl padlock_aes_block
+.def   padlock_aes_block;      .scl 2; .type 32;       .endef
+.p2align       4
+padlock_aes_block:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_padlock_aes_block:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+
+       movq    %rbx,%r8
+       movq    $1,%rcx
+       leaq    32(%rdx),%rbx
+       leaq    16(%rdx),%rdx
+.byte  0xf3,0x0f,0xa7,0xc8     
+       movq    %r8,%rbx
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_padlock_aes_block:
+
+.globl padlock_xstore
+.def   padlock_xstore; .scl 2; .type 32;       .endef
+.p2align       4
+padlock_xstore:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_padlock_xstore:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+
+       movl    %esi,%edx
+.byte  0x0f,0xa7,0xc0          
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_padlock_xstore:
+
+.globl padlock_sha1_oneshot
+.def   padlock_sha1_oneshot;   .scl 2; .type 32;       .endef
+.p2align       4
+padlock_sha1_oneshot:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_padlock_sha1_oneshot:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+
+       movq    %rdx,%rcx
+       movq    %rdi,%rdx
+       movups  (%rdi),%xmm0
+       subq    $128+8,%rsp
+       movl    16(%rdi),%eax
+       movaps  %xmm0,(%rsp)
+       movq    %rsp,%rdi
+       movl    %eax,16(%rsp)
+       xorq    %rax,%rax
+.byte  0xf3,0x0f,0xa6,0xc8     
+       movaps  (%rsp),%xmm0
+       movl    16(%rsp),%eax
+       addq    $128+8,%rsp
+       movups  %xmm0,(%rdx)
+       movl    %eax,16(%rdx)
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_padlock_sha1_oneshot:
+
+.globl padlock_sha1_blocks
+.def   padlock_sha1_blocks;    .scl 2; .type 32;       .endef
+.p2align       4
+padlock_sha1_blocks:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_padlock_sha1_blocks:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+
+       movq    %rdx,%rcx
+       movq    %rdi,%rdx
+       movups  (%rdi),%xmm0
+       subq    $128+8,%rsp
+       movl    16(%rdi),%eax
+       movaps  %xmm0,(%rsp)
+       movq    %rsp,%rdi
+       movl    %eax,16(%rsp)
+       movq    $-1,%rax
+.byte  0xf3,0x0f,0xa6,0xc8     
+       movaps  (%rsp),%xmm0
+       movl    16(%rsp),%eax
+       addq    $128+8,%rsp
+       movups  %xmm0,(%rdx)
+       movl    %eax,16(%rdx)
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_padlock_sha1_blocks:
+
+.globl padlock_sha256_oneshot
+.def   padlock_sha256_oneshot; .scl 2; .type 32;       .endef
+.p2align       4
+padlock_sha256_oneshot:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_padlock_sha256_oneshot:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+
+       movq    %rdx,%rcx
+       movq    %rdi,%rdx
+       movups  (%rdi),%xmm0
+       subq    $128+8,%rsp
+       movups  16(%rdi),%xmm1
+       movaps  %xmm0,(%rsp)
+       movq    %rsp,%rdi
+       movaps  %xmm1,16(%rsp)
+       xorq    %rax,%rax
+.byte  0xf3,0x0f,0xa6,0xd0     
+       movaps  (%rsp),%xmm0
+       movaps  16(%rsp),%xmm1
+       addq    $128+8,%rsp
+       movups  %xmm0,(%rdx)
+       movups  %xmm1,16(%rdx)
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_padlock_sha256_oneshot:
+
+.globl padlock_sha256_blocks
+.def   padlock_sha256_blocks;  .scl 2; .type 32;       .endef
+.p2align       4
+padlock_sha256_blocks:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_padlock_sha256_blocks:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+
+       movq    %rdx,%rcx
+       movq    %rdi,%rdx
+       movups  (%rdi),%xmm0
+       subq    $128+8,%rsp
+       movups  16(%rdi),%xmm1
+       movaps  %xmm0,(%rsp)
+       movq    %rsp,%rdi
+       movaps  %xmm1,16(%rsp)
+       movq    $-1,%rax
+.byte  0xf3,0x0f,0xa6,0xd0     
+       movaps  (%rsp),%xmm0
+       movaps  16(%rsp),%xmm1
+       addq    $128+8,%rsp
+       movups  %xmm0,(%rdx)
+       movups  %xmm1,16(%rdx)
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_padlock_sha256_blocks:
+
+.globl padlock_sha512_blocks
+.def   padlock_sha512_blocks;  .scl 2; .type 32;       .endef
+.p2align       4
+padlock_sha512_blocks:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_padlock_sha512_blocks:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+
+       movq    %rdx,%rcx
+       movq    %rdi,%rdx
+       movups  (%rdi),%xmm0
+       subq    $128+8,%rsp
+       movups  16(%rdi),%xmm1
+       movups  32(%rdi),%xmm2
+       movups  48(%rdi),%xmm3
+       movaps  %xmm0,(%rsp)
+       movq    %rsp,%rdi
+       movaps  %xmm1,16(%rsp)
+       movaps  %xmm2,32(%rsp)
+       movaps  %xmm3,48(%rsp)
+.byte  0xf3,0x0f,0xa6,0xe0     
+       movaps  (%rsp),%xmm0
+       movaps  16(%rsp),%xmm1
+       movaps  32(%rsp),%xmm2
+       movaps  48(%rsp),%xmm3
+       addq    $128+8,%rsp
+       movups  %xmm0,(%rdx)
+       movups  %xmm1,16(%rdx)
+       movups  %xmm2,32(%rdx)
+       movups  %xmm3,48(%rdx)
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_padlock_sha512_blocks:
+.globl padlock_ecb_encrypt
+.def   padlock_ecb_encrypt;    .scl 2; .type 32;       .endef
+.p2align       4
+padlock_ecb_encrypt:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_padlock_ecb_encrypt:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+       movq    %r9,%rcx
+
+       pushq   %rbp
+       pushq   %rbx
+
+       xorl    %eax,%eax
+       testq   $15,%rdx
+       jnz     .Lecb_abort
+       testq   $15,%rcx
+       jnz     .Lecb_abort
+       leaq    .Lpadlock_saved_context(%rip),%rax
+       pushf
+       cld
+       call    _padlock_verify_ctx
+       leaq    16(%rdx),%rdx
+       xorl    %eax,%eax
+       xorl    %ebx,%ebx
+       cmpq    $128,%rcx
+       jbe     .Lecb_short
+       testl   $32,(%rdx)
+       jnz     .Lecb_aligned
+       testq   $15,%rdi
+       setz    %al
+       testq   $15,%rsi
+       setz    %bl
+       testl   %ebx,%eax
+       jnz     .Lecb_aligned
+       negq    %rax
+       movq    $512,%rbx
+       notq    %rax
+       leaq    (%rsp),%rbp
+       cmpq    %rbx,%rcx
+       cmovcq  %rcx,%rbx
+       andq    %rbx,%rax
+       movq    %rcx,%rbx
+       negq    %rax
+       andq    $512-1,%rbx
+       leaq    (%rax,%rbp,1),%rsp
+       jmp     .Lecb_loop
+.p2align       4
+.Lecb_loop:
+       cmpq    %rcx,%rbx
+       cmovaq  %rcx,%rbx
+       movq    %rdi,%r8
+       movq    %rsi,%r9
+       movq    %rcx,%r10
+       movq    %rbx,%rcx
+       movq    %rbx,%r11
+       testq   $15,%rdi
+       cmovnzq %rsp,%rdi
+       testq   $15,%rsi
+       jz      .Lecb_inp_aligned
+       shrq    $3,%rcx
+.byte  0xf3,0x48,0xa5          
+       subq    %rbx,%rdi
+       movq    %rbx,%rcx
+       movq    %rdi,%rsi
+.Lecb_inp_aligned:
+       leaq    -16(%rdx),%rax
+       leaq    16(%rdx),%rbx
+       shrq    $4,%rcx
+.byte  0xf3,0x0f,0xa7,200      
+       movq    %r8,%rdi
+       movq    %r11,%rbx
+       testq   $15,%rdi
+       jz      .Lecb_out_aligned
+       movq    %rbx,%rcx
+       shrq    $3,%rcx
+       leaq    (%rsp),%rsi
+.byte  0xf3,0x48,0xa5          
+       subq    %rbx,%rdi
+.Lecb_out_aligned:
+       movq    %r9,%rsi
+       movq    %r10,%rcx
+       addq    %rbx,%rdi
+       addq    %rbx,%rsi
+       subq    %rbx,%rcx
+       movq    $512,%rbx
+       jnz     .Lecb_loop
+
+       cmpq    %rsp,%rbp
+       je      .Lecb_done
+
+       pxor    %xmm0,%xmm0
+       leaq    (%rsp),%rax
+.Lecb_bzero:
+       movaps  %xmm0,(%rax)
+       leaq    16(%rax),%rax
+       cmpq    %rax,%rbp
+       ja      .Lecb_bzero
+
+.Lecb_done:
+       leaq    (%rbp),%rsp
+       jmp     .Lecb_exit
+.p2align       4
+.Lecb_short:
+       movq    %rsp,%rbp
+       subq    %rcx,%rsp
+       xorq    %rbx,%rbx
+.Lecb_short_copy:
+       movups  (%rsi,%rbx,1),%xmm0
+       leaq    16(%rbx),%rbx
+       cmpq    %rbx,%rcx
+       movaps  %xmm0,-16(%rsp,%rbx,1)
+       ja      .Lecb_short_copy
+       movq    %rsp,%rsi
+       movq    %rcx,%rbx
+       jmp     .Lecb_loop
+.p2align       4
+.Lecb_aligned:
+       leaq    -16(%rdx),%rax
+       leaq    16(%rdx),%rbx
+       shrq    $4,%rcx
+.byte  0xf3,0x0f,0xa7,200      
+.Lecb_exit:
+       movl    $1,%eax
+       leaq    8(%rsp),%rsp
+.Lecb_abort:
+       popq    %rbx
+       popq    %rbp
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_padlock_ecb_encrypt:
+.globl padlock_cbc_encrypt
+.def   padlock_cbc_encrypt;    .scl 2; .type 32;       .endef
+.p2align       4
+padlock_cbc_encrypt:
+       movq    %rdi,8(%rsp)
+       movq    %rsi,16(%rsp)
+       movq    %rsp,%rax
+.LSEH_begin_padlock_cbc_encrypt:
+       movq    %rcx,%rdi
+       movq    %rdx,%rsi
+       movq    %r8,%rdx
+       movq    %r9,%rcx
+
+       pushq   %rbp
+       pushq   %rbx
+
+       xorl    %eax,%eax
+       testq   $15,%rdx
+       jnz     .Lcbc_abort
+       testq   $15,%rcx
+       jnz     .Lcbc_abort
+       leaq    .Lpadlock_saved_context(%rip),%rax
+       pushf
+       cld
+       call    _padlock_verify_ctx
+       leaq    16(%rdx),%rdx
+       xorl    %eax,%eax
+       xorl    %ebx,%ebx
+       cmpq    $64,%rcx
+       jbe     .Lcbc_short
+       testl   $32,(%rdx)
+       jnz     .Lcbc_aligned
+       testq   $15,%rdi
+       setz    %al
+       testq   $15,%rsi
+       setz    %bl
+       testl   %ebx,%eax
+       jnz     .Lcbc_aligned
+       negq    %rax
+       movq    $512,%rbx
+       notq    %rax
+       leaq    (%rsp),%rbp
+       cmpq    %rbx,%rcx
+       cmovcq  %rcx,%rbx
+       andq    %rbx,%rax
+       movq    %rcx,%rbx
+       negq    %rax
+       andq    $512-1,%rbx
+       leaq    (%rax,%rbp,1),%rsp
+       jmp     .Lcbc_loop
+.p2align       4
+.Lcbc_loop:
+       cmpq    %rcx,%rbx
+       cmovaq  %rcx,%rbx
+       movq    %rdi,%r8
+       movq    %rsi,%r9
+       movq    %rcx,%r10
+       movq    %rbx,%rcx
+       movq    %rbx,%r11
+       testq   $15,%rdi
+       cmovnzq %rsp,%rdi
+       testq   $15,%rsi
+       jz      .Lcbc_inp_aligned
+       shrq    $3,%rcx
+.byte  0xf3,0x48,0xa5          
+       subq    %rbx,%rdi
+       movq    %rbx,%rcx
+       movq    %rdi,%rsi
+.Lcbc_inp_aligned:
+       leaq    -16(%rdx),%rax
+       leaq    16(%rdx),%rbx
+       shrq    $4,%rcx
+.byte  0xf3,0x0f,0xa7,208      
+       movdqa  (%rax),%xmm0
+       movdqa  %xmm0,-16(%rdx)
+       movq    %r8,%rdi
+       movq    %r11,%rbx
+       testq   $15,%rdi
+       jz      .Lcbc_out_aligned
+       movq    %rbx,%rcx
+       shrq    $3,%rcx
+       leaq    (%rsp),%rsi
+.byte  0xf3,0x48,0xa5          
+       subq    %rbx,%rdi
+.Lcbc_out_aligned:
+       movq    %r9,%rsi
+       movq    %r10,%rcx
+       addq    %rbx,%rdi
+       addq    %rbx,%rsi
+       subq    %rbx,%rcx
+       movq    $512,%rbx
+       jnz     .Lcbc_loop
+
+       cmpq    %rsp,%rbp
+       je      .Lcbc_done
+
+       pxor    %xmm0,%xmm0
+       leaq    (%rsp),%rax
+.Lcbc_bzero:
+       movaps  %xmm0,(%rax)
+       leaq    16(%rax),%rax
+       cmpq    %rax,%rbp
+       ja      .Lcbc_bzero
+
+.Lcbc_done:
+       leaq    (%rbp),%rsp
+       jmp     .Lcbc_exit
+.p2align       4
+.Lcbc_short:
+       movq    %rsp,%rbp
+       subq    %rcx,%rsp
+       xorq    %rbx,%rbx
+.Lcbc_short_copy:
+       movups  (%rsi,%rbx,1),%xmm0
+       leaq    16(%rbx),%rbx
+       cmpq    %rbx,%rcx
+       movaps  %xmm0,-16(%rsp,%rbx,1)
+       ja      .Lcbc_short_copy
+       movq    %rsp,%rsi
+       movq    %rcx,%rbx
+       jmp     .Lcbc_loop
+.p2align       4
+.Lcbc_aligned:
+       leaq    -16(%rdx),%rax
+       leaq    16(%rdx),%rbx
+       shrq    $4,%rcx
+.byte  0xf3,0x0f,0xa7,208      
+       movdqa  (%rax),%xmm0
+       movdqa  %xmm0,-16(%rdx)
+.Lcbc_exit:
+       movl    $1,%eax
+       leaq    8(%rsp),%rsp
+.Lcbc_abort:
+       popq    %rbx
+       popq    %rbp
+       movq    8(%rsp),%rdi
+       movq    16(%rsp),%rsi
+       .byte   0xf3,0xc3
+.LSEH_end_padlock_cbc_encrypt:
+.byte  
86,73,65,32,80,97,100,108,111,99,107,32,120,56,54,95,54,52,32,109,111,100,117,108,101,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
+.p2align       4
+.data  
+.p2align       3
+.Lpadlock_saved_context:
+.quad  0
diff --git a/lib/accelerated/x86/asm-coff/padlock-x86-coff.s 
b/lib/accelerated/x86/asm-coff/padlock-x86-coff.s
new file mode 100644
index 0000000..c1014bd
--- /dev/null
+++ b/lib/accelerated/x86/asm-coff/padlock-x86-coff.s
@@ -0,0 +1,615 @@
+# Copyright (c) 2011, Andy Polyakov by <address@hidden>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 
+#     * Redistributions of source code must retain copyright notices,
+#      this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+#
+#     * Neither the name of the Andy Polyakov nor the names of its
+#      copyright holder and contributors may be used to endorse or
+#      promote products derived from this software without specific
+#      prior written permission.
+#
+# ALTERNATIVELY, provided that this notice is retained in full, this
+# product may be distributed under the terms of the GNU General Public
+# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+# those given above.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.file  "./engines/asm/e_padlock-x86.s"
+.text
+.globl _padlock_capability
+.def   _padlock_capability;    .scl    2;      .type   32;     .endef
+.align 16
+_padlock_capability:
+.L_padlock_capability_begin:
+       pushl   %ebx
+       pushfl
+       popl    %eax
+       movl    %eax,%ecx
+       xorl    $2097152,%eax
+       pushl   %eax
+       popfl
+       pushfl
+       popl    %eax
+       xorl    %eax,%ecx
+       xorl    %eax,%eax
+       btl     $21,%ecx
+       jnc     .L000noluck
+       .byte   0x0f,0xa2
+       xorl    %eax,%eax
+       cmpl    $0x746e6543,%ebx
+       jne     .L000noluck
+       cmpl    $0x48727561,%edx
+       jne     .L000noluck
+       cmpl    $0x736c7561,%ecx
+       jne     .L000noluck
+       movl    $3221225472,%eax
+       .byte   0x0f,0xa2
+       movl    %eax,%edx
+       xorl    %eax,%eax
+       cmpl    $3221225473,%edx
+       jb      .L000noluck
+       movl    $1,%eax
+       .byte   0x0f,0xa2
+       orl     $15,%eax
+       xorl    %ebx,%ebx
+       andl    $4095,%eax
+       cmpl    $1791,%eax
+       sete    %bl
+       movl    $3221225473,%eax
+       pushl   %ebx
+       .byte   0x0f,0xa2
+       popl    %ebx
+       movl    %edx,%eax
+       shll    $4,%ebx
+       andl    $4294967279,%eax
+       orl     %ebx,%eax
+.L000noluck:
+       popl    %ebx
+       ret
+.globl _padlock_key_bswap
+.def   _padlock_key_bswap;     .scl    2;      .type   32;     .endef
+.align 16
+_padlock_key_bswap:
+.L_padlock_key_bswap_begin:
+       movl    4(%esp),%edx
+       movl    240(%edx),%ecx
+.L001bswap_loop:
+       movl    (%edx),%eax
+       bswap   %eax
+       movl    %eax,(%edx)
+       leal    4(%edx),%edx
+       subl    $1,%ecx
+       jnz     .L001bswap_loop
+       ret
+.globl _padlock_verify_context
+.def   _padlock_verify_context;        .scl    2;      .type   32;     .endef
+.align 16
+_padlock_verify_context:
+.L_padlock_verify_context_begin:
+       movl    4(%esp),%edx
+       leal    .Lpadlock_saved_context,%eax
+       pushfl
+       call    __padlock_verify_ctx
+.L002verify_pic_point:
+       leal    4(%esp),%esp
+       ret
+.def   __padlock_verify_ctx;   .scl    3;      .type   32;     .endef
+.align 16
+__padlock_verify_ctx:
+       btl     $30,4(%esp)
+       jnc     .L003verified
+       cmpl    (%eax),%edx
+       je      .L003verified
+       pushfl
+       popfl
+.L003verified:
+       movl    %edx,(%eax)
+       ret
+.globl _padlock_reload_key
+.def   _padlock_reload_key;    .scl    2;      .type   32;     .endef
+.align 16
+_padlock_reload_key:
+.L_padlock_reload_key_begin:
+       pushfl
+       popfl
+       ret
+.globl _padlock_aes_block
+.def   _padlock_aes_block;     .scl    2;      .type   32;     .endef
+.align 16
+_padlock_aes_block:
+.L_padlock_aes_block_begin:
+       pushl   %edi
+       pushl   %esi
+       pushl   %ebx
+       movl    16(%esp),%edi
+       movl    20(%esp),%esi
+       movl    24(%esp),%edx
+       movl    $1,%ecx
+       leal    32(%edx),%ebx
+       leal    16(%edx),%edx
+.byte  243,15,167,200
+       popl    %ebx
+       popl    %esi
+       popl    %edi
+       ret
+.globl _padlock_ecb_encrypt
+.def   _padlock_ecb_encrypt;   .scl    2;      .type   32;     .endef
+.align 16
+_padlock_ecb_encrypt:
+.L_padlock_ecb_encrypt_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%edi
+       movl    24(%esp),%esi
+       movl    28(%esp),%edx
+       movl    32(%esp),%ecx
+       testl   $15,%edx
+       jnz     .L004ecb_abort
+       testl   $15,%ecx
+       jnz     .L004ecb_abort
+       leal    .Lpadlock_saved_context,%eax
+       pushfl
+       cld
+       call    __padlock_verify_ctx
+.L005ecb_pic_point:
+       leal    16(%edx),%edx
+       xorl    %eax,%eax
+       xorl    %ebx,%ebx
+       cmpl    $128,%ecx
+       jbe     .L006ecb_short
+       testl   $32,(%edx)
+       jnz     .L007ecb_aligned
+       testl   $15,%edi
+       setz    %al
+       testl   $15,%esi
+       setz    %bl
+       testl   %ebx,%eax
+       jnz     .L007ecb_aligned
+       negl    %eax
+       movl    $512,%ebx
+       notl    %eax
+       leal    -24(%esp),%ebp
+       cmpl    %ebx,%ecx
+       cmovcl  %ecx,%ebx
+       andl    %ebx,%eax
+       movl    %ecx,%ebx
+       negl    %eax
+       andl    $511,%ebx
+       leal    (%eax,%ebp,1),%esp
+       andl    $-16,%esp
+       jmp     .L008ecb_loop
+.align 16
+.L008ecb_loop:
+       movl    %edi,(%ebp)
+       movl    %esi,4(%ebp)
+       movl    %ecx,8(%ebp)
+       movl    %ebx,%ecx
+       movl    %ebx,12(%ebp)
+       testl   $15,%edi
+       cmovnzl %esp,%edi
+       testl   $15,%esi
+       jz      .L009ecb_inp_aligned
+       shrl    $2,%ecx
+.byte  243,165
+       subl    %ebx,%edi
+       movl    %ebx,%ecx
+       movl    %edi,%esi
+.L009ecb_inp_aligned:
+       leal    -16(%edx),%eax
+       leal    16(%edx),%ebx
+       shrl    $4,%ecx
+.byte  243,15,167,200
+       movl    (%ebp),%edi
+       movl    12(%ebp),%ebx
+       testl   $15,%edi
+       jz      .L010ecb_out_aligned
+       movl    %ebx,%ecx
+       shrl    $2,%ecx
+       leal    (%esp),%esi
+.byte  243,165
+       subl    %ebx,%edi
+.L010ecb_out_aligned:
+       movl    4(%ebp),%esi
+       movl    8(%ebp),%ecx
+       addl    %ebx,%edi
+       addl    %ebx,%esi
+       subl    %ebx,%ecx
+       movl    $512,%ebx
+       jnz     .L008ecb_loop
+       cmpl    %ebp,%esp
+       je      .L011ecb_done
+       pxor    %xmm0,%xmm0
+       leal    (%esp),%eax
+.L012ecb_bzero:
+       movaps  %xmm0,(%eax)
+       leal    16(%eax),%eax
+       cmpl    %eax,%ebp
+       ja      .L012ecb_bzero
+.L011ecb_done:
+       leal    24(%ebp),%esp
+       jmp     .L013ecb_exit
+.align 16
+.L006ecb_short:
+       xorl    %eax,%eax
+       leal    -24(%esp),%ebp
+       subl    %ecx,%eax
+       leal    (%eax,%ebp,1),%esp
+       andl    $-16,%esp
+       xorl    %ebx,%ebx
+.L014ecb_short_copy:
+       movups  (%esi,%ebx,1),%xmm0
+       leal    16(%ebx),%ebx
+       cmpl    %ebx,%ecx
+       movaps  %xmm0,-16(%esp,%ebx,1)
+       ja      .L014ecb_short_copy
+       movl    %esp,%esi
+       movl    %ecx,%ebx
+       jmp     .L008ecb_loop
+.align 16
+.L007ecb_aligned:
+       leal    -16(%edx),%eax
+       leal    16(%edx),%ebx
+       shrl    $4,%ecx
+.byte  243,15,167,200
+.L013ecb_exit:
+       movl    $1,%eax
+       leal    4(%esp),%esp
+.L004ecb_abort:
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.globl _padlock_cbc_encrypt
+.def   _padlock_cbc_encrypt;   .scl    2;      .type   32;     .endef
+.align 16
+_padlock_cbc_encrypt:
+.L_padlock_cbc_encrypt_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%edi
+       movl    24(%esp),%esi
+       movl    28(%esp),%edx
+       movl    32(%esp),%ecx
+       testl   $15,%edx
+       jnz     .L015cbc_abort
+       testl   $15,%ecx
+       jnz     .L015cbc_abort
+       leal    .Lpadlock_saved_context,%eax
+       pushfl
+       cld
+       call    __padlock_verify_ctx
+.L016cbc_pic_point:
+       leal    16(%edx),%edx
+       xorl    %eax,%eax
+       xorl    %ebx,%ebx
+       cmpl    $64,%ecx
+       jbe     .L017cbc_short
+       testl   $32,(%edx)
+       jnz     .L018cbc_aligned
+       testl   $15,%edi
+       setz    %al
+       testl   $15,%esi
+       setz    %bl
+       testl   %ebx,%eax
+       jnz     .L018cbc_aligned
+       negl    %eax
+       movl    $512,%ebx
+       notl    %eax
+       leal    -24(%esp),%ebp
+       cmpl    %ebx,%ecx
+       cmovcl  %ecx,%ebx
+       andl    %ebx,%eax
+       movl    %ecx,%ebx
+       negl    %eax
+       andl    $511,%ebx
+       leal    (%eax,%ebp,1),%esp
+       andl    $-16,%esp
+       jmp     .L019cbc_loop
+.align 16
+.L019cbc_loop:
+       movl    %edi,(%ebp)
+       movl    %esi,4(%ebp)
+       movl    %ecx,8(%ebp)
+       movl    %ebx,%ecx
+       movl    %ebx,12(%ebp)
+       testl   $15,%edi
+       cmovnzl %esp,%edi
+       testl   $15,%esi
+       jz      .L020cbc_inp_aligned
+       shrl    $2,%ecx
+.byte  243,165
+       subl    %ebx,%edi
+       movl    %ebx,%ecx
+       movl    %edi,%esi
+.L020cbc_inp_aligned:
+       leal    -16(%edx),%eax
+       leal    16(%edx),%ebx
+       shrl    $4,%ecx
+.byte  243,15,167,208
+       movaps  (%eax),%xmm0
+       movaps  %xmm0,-16(%edx)
+       movl    (%ebp),%edi
+       movl    12(%ebp),%ebx
+       testl   $15,%edi
+       jz      .L021cbc_out_aligned
+       movl    %ebx,%ecx
+       shrl    $2,%ecx
+       leal    (%esp),%esi
+.byte  243,165
+       subl    %ebx,%edi
+.L021cbc_out_aligned:
+       movl    4(%ebp),%esi
+       movl    8(%ebp),%ecx
+       addl    %ebx,%edi
+       addl    %ebx,%esi
+       subl    %ebx,%ecx
+       movl    $512,%ebx
+       jnz     .L019cbc_loop
+       cmpl    %ebp,%esp
+       je      .L022cbc_done
+       pxor    %xmm0,%xmm0
+       leal    (%esp),%eax
+.L023cbc_bzero:
+       movaps  %xmm0,(%eax)
+       leal    16(%eax),%eax
+       cmpl    %eax,%ebp
+       ja      .L023cbc_bzero
+.L022cbc_done:
+       leal    24(%ebp),%esp
+       jmp     .L024cbc_exit
+.align 16
+.L017cbc_short:
+       xorl    %eax,%eax
+       leal    -24(%esp),%ebp
+       subl    %ecx,%eax
+       leal    (%eax,%ebp,1),%esp
+       andl    $-16,%esp
+       xorl    %ebx,%ebx
+.L025cbc_short_copy:
+       movups  (%esi,%ebx,1),%xmm0
+       leal    16(%ebx),%ebx
+       cmpl    %ebx,%ecx
+       movaps  %xmm0,-16(%esp,%ebx,1)
+       ja      .L025cbc_short_copy
+       movl    %esp,%esi
+       movl    %ecx,%ebx
+       jmp     .L019cbc_loop
+.align 16
+.L018cbc_aligned:
+       leal    -16(%edx),%eax
+       leal    16(%edx),%ebx
+       shrl    $4,%ecx
+.byte  243,15,167,208
+       movaps  (%eax),%xmm0
+       movaps  %xmm0,-16(%edx)
+.L024cbc_exit:
+       movl    $1,%eax
+       leal    4(%esp),%esp
+.L015cbc_abort:
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.globl _padlock_xstore
+.def   _padlock_xstore;        .scl    2;      .type   32;     .endef
+.align 16
+_padlock_xstore:
+.L_padlock_xstore_begin:
+       pushl   %edi
+       movl    8(%esp),%edi
+       movl    12(%esp),%edx
+.byte  15,167,192
+       popl    %edi
+       ret
+.def   __win32_segv_handler;   .scl    3;      .type   32;     .endef
+.align 16
+__win32_segv_handler:
+       movl    $1,%eax
+       movl    4(%esp),%edx
+       movl    12(%esp),%ecx
+       cmpl    $3221225477,(%edx)
+       jne     .L026ret
+       addl    $4,184(%ecx)
+       movl    $0,%eax
+.L026ret:
+       ret
+.globl _padlock_sha1_oneshot
+.def   _padlock_sha1_oneshot;  .scl    2;      .type   32;     .endef
+.align 16
+_padlock_sha1_oneshot:
+.L_padlock_sha1_oneshot_begin:
+       pushl   %edi
+       pushl   %esi
+       xorl    %eax,%eax
+       movl    12(%esp),%edi
+       movl    16(%esp),%esi
+       movl    20(%esp),%ecx
+       pushl   __win32_segv_handler
+.byte  100,255,48
+.byte  100,137,32
+       movl    %esp,%edx
+       addl    $-128,%esp
+       movups  (%edi),%xmm0
+       andl    $-16,%esp
+       movl    16(%edi),%eax
+       movaps  %xmm0,(%esp)
+       movl    %esp,%edi
+       movl    %eax,16(%esp)
+       xorl    %eax,%eax
+.byte  243,15,166,200
+       movaps  (%esp),%xmm0
+       movl    16(%esp),%eax
+       movl    %edx,%esp
+.byte  100,143,5,0,0,0,0
+       leal    4(%esp),%esp
+       movl    16(%esp),%edi
+       movups  %xmm0,(%edi)
+       movl    %eax,16(%edi)
+       popl    %esi
+       popl    %edi
+       ret
+.globl _padlock_sha1_blocks
+.def   _padlock_sha1_blocks;   .scl    2;      .type   32;     .endef
+.align 16
+_padlock_sha1_blocks:
+.L_padlock_sha1_blocks_begin:
+       pushl   %edi
+       pushl   %esi
+       movl    12(%esp),%edi
+       movl    16(%esp),%esi
+       movl    %esp,%edx
+       movl    20(%esp),%ecx
+       addl    $-128,%esp
+       movups  (%edi),%xmm0
+       andl    $-16,%esp
+       movl    16(%edi),%eax
+       movaps  %xmm0,(%esp)
+       movl    %esp,%edi
+       movl    %eax,16(%esp)
+       movl    $-1,%eax
+.byte  243,15,166,200
+       movaps  (%esp),%xmm0
+       movl    16(%esp),%eax
+       movl    %edx,%esp
+       movl    12(%esp),%edi
+       movups  %xmm0,(%edi)
+       movl    %eax,16(%edi)
+       popl    %esi
+       popl    %edi
+       ret
+.globl _padlock_sha256_oneshot
+.def   _padlock_sha256_oneshot;        .scl    2;      .type   32;     .endef
+.align 16
+_padlock_sha256_oneshot:
+.L_padlock_sha256_oneshot_begin:
+       pushl   %edi
+       pushl   %esi
+       xorl    %eax,%eax
+       movl    12(%esp),%edi
+       movl    16(%esp),%esi
+       movl    20(%esp),%ecx
+       pushl   __win32_segv_handler
+.byte  100,255,48
+.byte  100,137,32
+       movl    %esp,%edx
+       addl    $-128,%esp
+       movups  (%edi),%xmm0
+       andl    $-16,%esp
+       movups  16(%edi),%xmm1
+       movaps  %xmm0,(%esp)
+       movl    %esp,%edi
+       movaps  %xmm1,16(%esp)
+       xorl    %eax,%eax
+.byte  243,15,166,208
+       movaps  (%esp),%xmm0
+       movaps  16(%esp),%xmm1
+       movl    %edx,%esp
+.byte  100,143,5,0,0,0,0
+       leal    4(%esp),%esp
+       movl    16(%esp),%edi
+       movups  %xmm0,(%edi)
+       movups  %xmm1,16(%edi)
+       popl    %esi
+       popl    %edi
+       ret
+.globl _padlock_sha256_blocks
+.def   _padlock_sha256_blocks; .scl    2;      .type   32;     .endef
+.align 16
+_padlock_sha256_blocks:
+.L_padlock_sha256_blocks_begin:
+       pushl   %edi
+       pushl   %esi
+       movl    12(%esp),%edi
+       movl    16(%esp),%esi
+       movl    20(%esp),%ecx
+       movl    %esp,%edx
+       addl    $-128,%esp
+       movups  (%edi),%xmm0
+       andl    $-16,%esp
+       movups  16(%edi),%xmm1
+       movaps  %xmm0,(%esp)
+       movl    %esp,%edi
+       movaps  %xmm1,16(%esp)
+       movl    $-1,%eax
+.byte  243,15,166,208
+       movaps  (%esp),%xmm0
+       movaps  16(%esp),%xmm1
+       movl    %edx,%esp
+       movl    12(%esp),%edi
+       movups  %xmm0,(%edi)
+       movups  %xmm1,16(%edi)
+       popl    %esi
+       popl    %edi
+       ret
+.globl _padlock_sha512_blocks
+.def   _padlock_sha512_blocks; .scl    2;      .type   32;     .endef
+.align 16
+_padlock_sha512_blocks:
+.L_padlock_sha512_blocks_begin:
+       pushl   %edi
+       pushl   %esi
+       movl    12(%esp),%edi
+       movl    16(%esp),%esi
+       movl    20(%esp),%ecx
+       movl    %esp,%edx
+       addl    $-128,%esp
+       movups  (%edi),%xmm0
+       andl    $-16,%esp
+       movups  16(%edi),%xmm1
+       movups  32(%edi),%xmm2
+       movups  48(%edi),%xmm3
+       movaps  %xmm0,(%esp)
+       movl    %esp,%edi
+       movaps  %xmm1,16(%esp)
+       movaps  %xmm2,32(%esp)
+       movaps  %xmm3,48(%esp)
+.byte  243,15,166,224
+       movaps  (%esp),%xmm0
+       movaps  16(%esp),%xmm1
+       movaps  32(%esp),%xmm2
+       movaps  48(%esp),%xmm3
+       movl    %edx,%esp
+       movl    12(%esp),%edi
+       movups  %xmm0,(%edi)
+       movups  %xmm1,16(%edi)
+       movups  %xmm2,32(%edi)
+       movups  %xmm3,48(%edi)
+       popl    %esi
+       popl    %edi
+       ret
+.byte  86,73,65,32,80,97,100,108,111,99,107,32,120,56,54,32
+.byte  109,111,100,117,108,101,44,32,67,82,89,80,84,79,71,65
+.byte  77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101
+.byte  110,115,115,108,46,111,114,103,62,0
+.align 16
+.data
+.align 4
+.Lpadlock_saved_context:
+.long  0
diff --git a/lib/accelerated/x86/asm/appro-aes-gcm-x86-64.s 
b/lib/accelerated/x86/asm/appro-aes-gcm-x86-64.s
new file mode 100644
index 0000000..620cf47
--- /dev/null
+++ b/lib/accelerated/x86/asm/appro-aes-gcm-x86-64.s
@@ -0,0 +1,1068 @@
+# Copyright (c) 2011, Andy Polyakov by <address@hidden>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 
+#     * Redistributions of source code must retain copyright notices,
+#      this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+#
+#     * Neither the name of the Andy Polyakov nor the names of its
+#      copyright holder and contributors may be used to endorse or
+#      promote products derived from this software without specific
+#      prior written permission.
+#
+# ALTERNATIVELY, provided that this notice is retained in full, this
+# product may be distributed under the terms of the GNU General Public
+# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+# those given above.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+.text  
+
+.globl gcm_gmult_4bit
+.type  gcm_gmult_4bit,@function
+.align 16
+gcm_gmult_4bit:
+       pushq   %rbx
+       pushq   %rbp
+       pushq   %r12
+.Lgmult_prologue:
+
+       movzbq  15(%rdi),%r8
+       leaq    .Lrem_4bit(%rip),%r11
+       xorq    %rax,%rax
+       xorq    %rbx,%rbx
+       movb    %r8b,%al
+       movb    %r8b,%bl
+       shlb    $4,%al
+       movq    $14,%rcx
+       movq    8(%rsi,%rax,1),%r8
+       movq    (%rsi,%rax,1),%r9
+       andb    $240,%bl
+       movq    %r8,%rdx
+       jmp     .Loop1
+
+.align 16
+.Loop1:
+       shrq    $4,%r8
+       andq    $15,%rdx
+       movq    %r9,%r10
+       movb    (%rdi,%rcx,1),%al
+       shrq    $4,%r9
+       xorq    8(%rsi,%rbx,1),%r8
+       shlq    $60,%r10
+       xorq    (%rsi,%rbx,1),%r9
+       movb    %al,%bl
+       xorq    (%r11,%rdx,8),%r9
+       movq    %r8,%rdx
+       shlb    $4,%al
+       xorq    %r10,%r8
+       decq    %rcx
+       js      .Lbreak1
+
+       shrq    $4,%r8
+       andq    $15,%rdx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       xorq    8(%rsi,%rax,1),%r8
+       shlq    $60,%r10
+       xorq    (%rsi,%rax,1),%r9
+       andb    $240,%bl
+       xorq    (%r11,%rdx,8),%r9
+       movq    %r8,%rdx
+       xorq    %r10,%r8
+       jmp     .Loop1
+
+.align 16
+.Lbreak1:
+       shrq    $4,%r8
+       andq    $15,%rdx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       xorq    8(%rsi,%rax,1),%r8
+       shlq    $60,%r10
+       xorq    (%rsi,%rax,1),%r9
+       andb    $240,%bl
+       xorq    (%r11,%rdx,8),%r9
+       movq    %r8,%rdx
+       xorq    %r10,%r8
+
+       shrq    $4,%r8
+       andq    $15,%rdx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       xorq    8(%rsi,%rbx,1),%r8
+       shlq    $60,%r10
+       xorq    (%rsi,%rbx,1),%r9
+       xorq    %r10,%r8
+       xorq    (%r11,%rdx,8),%r9
+
+       bswapq  %r8
+       bswapq  %r9
+       movq    %r8,8(%rdi)
+       movq    %r9,(%rdi)
+
+       movq    16(%rsp),%rbx
+       leaq    24(%rsp),%rsp
+.Lgmult_epilogue:
+       .byte   0xf3,0xc3
+.size  gcm_gmult_4bit,.-gcm_gmult_4bit
+.globl gcm_ghash_4bit
+.type  gcm_ghash_4bit,@function
+.align 16
+gcm_ghash_4bit:
+       pushq   %rbx
+       pushq   %rbp
+       pushq   %r12
+       pushq   %r13
+       pushq   %r14
+       pushq   %r15
+       subq    $280,%rsp
+.Lghash_prologue:
+       movq    %rdx,%r14
+       movq    %rcx,%r15
+       subq    $-128,%rsi
+       leaq    16+128(%rsp),%rbp
+       xorl    %edx,%edx
+       movq    0+0-128(%rsi),%r8
+       movq    0+8-128(%rsi),%rax
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    16+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    16+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,0(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,0(%rbp)
+       movq    32+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,0-128(%rbp)
+       movq    32+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,1(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,8(%rbp)
+       movq    48+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,8-128(%rbp)
+       movq    48+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,2(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,16(%rbp)
+       movq    64+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,16-128(%rbp)
+       movq    64+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,3(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,24(%rbp)
+       movq    80+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,24-128(%rbp)
+       movq    80+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,4(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,32(%rbp)
+       movq    96+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,32-128(%rbp)
+       movq    96+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,5(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,40(%rbp)
+       movq    112+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,40-128(%rbp)
+       movq    112+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,6(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,48(%rbp)
+       movq    128+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,48-128(%rbp)
+       movq    128+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,7(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,56(%rbp)
+       movq    144+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,56-128(%rbp)
+       movq    144+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,8(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,64(%rbp)
+       movq    160+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,64-128(%rbp)
+       movq    160+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,9(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,72(%rbp)
+       movq    176+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,72-128(%rbp)
+       movq    176+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,10(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,80(%rbp)
+       movq    192+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,80-128(%rbp)
+       movq    192+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,11(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,88(%rbp)
+       movq    208+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,88-128(%rbp)
+       movq    208+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,12(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,96(%rbp)
+       movq    224+0-128(%rsi),%r8
+       shlb    $4,%dl
+       movq    %rax,96-128(%rbp)
+       movq    224+8-128(%rsi),%rax
+       shlq    $60,%r10
+       movb    %dl,13(%rsp)
+       orq     %r10,%rbx
+       movb    %al,%dl
+       shrq    $4,%rax
+       movq    %r8,%r10
+       shrq    $4,%r8
+       movq    %r9,104(%rbp)
+       movq    240+0-128(%rsi),%r9
+       shlb    $4,%dl
+       movq    %rbx,104-128(%rbp)
+       movq    240+8-128(%rsi),%rbx
+       shlq    $60,%r10
+       movb    %dl,14(%rsp)
+       orq     %r10,%rax
+       movb    %bl,%dl
+       shrq    $4,%rbx
+       movq    %r9,%r10
+       shrq    $4,%r9
+       movq    %r8,112(%rbp)
+       shlb    $4,%dl
+       movq    %rax,112-128(%rbp)
+       shlq    $60,%r10
+       movb    %dl,15(%rsp)
+       orq     %r10,%rbx
+       movq    %r9,120(%rbp)
+       movq    %rbx,120-128(%rbp)
+       addq    $-128,%rsi
+       movq    8(%rdi),%r8
+       movq    0(%rdi),%r9
+       addq    %r14,%r15
+       leaq    .Lrem_8bit(%rip),%r11
+       jmp     .Louter_loop
+.align 16
+.Louter_loop:
+       xorq    (%r14),%r9
+       movq    8(%r14),%rdx
+       leaq    16(%r14),%r14
+       xorq    %r8,%rdx
+       movq    %r9,(%rdi)
+       movq    %rdx,8(%rdi)
+       shrq    $32,%rdx
+       xorq    %rax,%rax
+       roll    $8,%edx
+       movb    %dl,%al
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       shrl    $4,%ebx
+       roll    $8,%edx
+       movq    8(%rsi,%rax,1),%r8
+       movq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       movl    8(%rdi),%edx
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       movl    4(%rdi),%edx
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       movl    0(%rdi),%edx
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       shrl    $4,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r12,2),%r12
+       movzbl  %dl,%ebx
+       shlb    $4,%al
+       movzbq  (%rsp,%rcx,1),%r13
+       shrl    $4,%ebx
+       shlq    $48,%r12
+       xorq    %r8,%r13
+       movq    %r9,%r10
+       xorq    %r12,%r9
+       shrq    $8,%r8
+       movzbq  %r13b,%r13
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rcx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rcx,8),%r9
+       roll    $8,%edx
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       movb    %dl,%al
+       xorq    %r10,%r8
+       movzwq  (%r11,%r13,2),%r13
+       movzbl  %dl,%ecx
+       shlb    $4,%al
+       movzbq  (%rsp,%rbx,1),%r12
+       andl    $240,%ecx
+       shlq    $48,%r13
+       xorq    %r8,%r12
+       movq    %r9,%r10
+       xorq    %r13,%r9
+       shrq    $8,%r8
+       movzbq  %r12b,%r12
+       movl    -4(%rdi),%edx
+       shrq    $8,%r9
+       xorq    -128(%rbp,%rbx,8),%r8
+       shlq    $56,%r10
+       xorq    (%rbp,%rbx,8),%r9
+       movzwq  (%r11,%r12,2),%r12
+       xorq    8(%rsi,%rax,1),%r8
+       xorq    (%rsi,%rax,1),%r9
+       shlq    $48,%r12
+       xorq    %r10,%r8
+       xorq    %r12,%r9
+       movzbq  %r8b,%r13
+       shrq    $4,%r8
+       movq    %r9,%r10
+       shlb    $4,%r13b
+       shrq    $4,%r9
+       xorq    8(%rsi,%rcx,1),%r8
+       movzwq  (%r11,%r13,2),%r13
+       shlq    $60,%r10
+       xorq    (%rsi,%rcx,1),%r9
+       xorq    %r10,%r8
+       shlq    $48,%r13
+       bswapq  %r8
+       xorq    %r13,%r9
+       bswapq  %r9
+       cmpq    %r15,%r14
+       jb      .Louter_loop
+       movq    %r8,8(%rdi)
+       movq    %r9,(%rdi)
+
+       leaq    280(%rsp),%rsi
+       movq    0(%rsi),%r15
+       movq    8(%rsi),%r14
+       movq    16(%rsi),%r13
+       movq    24(%rsi),%r12
+       movq    32(%rsi),%rbp
+       movq    40(%rsi),%rbx
+       leaq    48(%rsi),%rsp
+.Lghash_epilogue:
+       .byte   0xf3,0xc3
+.size  gcm_ghash_4bit,.-gcm_ghash_4bit
+.globl gcm_init_clmul
+.type  gcm_init_clmul,@function
+.align 16
+gcm_init_clmul:
+       movdqu  (%rsi),%xmm2
+       pshufd  $78,%xmm2,%xmm2
+
+
+       pshufd  $255,%xmm2,%xmm4
+       movdqa  %xmm2,%xmm3
+       psllq   $1,%xmm2
+       pxor    %xmm5,%xmm5
+       psrlq   $63,%xmm3
+       pcmpgtd %xmm4,%xmm5
+       pslldq  $8,%xmm3
+       por     %xmm3,%xmm2
+
+
+       pand    .L0x1c2_polynomial(%rip),%xmm5
+       pxor    %xmm5,%xmm2
+
+
+       movdqa  %xmm2,%xmm0
+       movdqa  %xmm0,%xmm1
+       pshufd  $78,%xmm0,%xmm3
+       pshufd  $78,%xmm2,%xmm4
+       pxor    %xmm0,%xmm3
+       pxor    %xmm2,%xmm4
+.byte  102,15,58,68,194,0
+.byte  102,15,58,68,202,17
+.byte  102,15,58,68,220,0
+       pxor    %xmm0,%xmm3
+       pxor    %xmm1,%xmm3
+
+       movdqa  %xmm3,%xmm4
+       psrldq  $8,%xmm3
+       pslldq  $8,%xmm4
+       pxor    %xmm3,%xmm1
+       pxor    %xmm4,%xmm0
+
+       movdqa  %xmm0,%xmm3
+       psllq   $1,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $5,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $57,%xmm0
+       movdqa  %xmm0,%xmm4
+       pslldq  $8,%xmm0
+       psrldq  $8,%xmm4
+       pxor    %xmm3,%xmm0
+       pxor    %xmm4,%xmm1
+
+
+       movdqa  %xmm0,%xmm4
+       psrlq   $5,%xmm0
+       pxor    %xmm4,%xmm0
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       pxor    %xmm1,%xmm4
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       movdqu  %xmm2,(%rdi)
+       movdqu  %xmm0,16(%rdi)
+       .byte   0xf3,0xc3
+.size  gcm_init_clmul,.-gcm_init_clmul
+.globl gcm_gmult_clmul
+.type  gcm_gmult_clmul,@function
+.align 16
+gcm_gmult_clmul:
+       movdqu  (%rdi),%xmm0
+       movdqa  .Lbswap_mask(%rip),%xmm5
+       movdqu  (%rsi),%xmm2
+.byte  102,15,56,0,197
+       movdqa  %xmm0,%xmm1
+       pshufd  $78,%xmm0,%xmm3
+       pshufd  $78,%xmm2,%xmm4
+       pxor    %xmm0,%xmm3
+       pxor    %xmm2,%xmm4
+.byte  102,15,58,68,194,0
+.byte  102,15,58,68,202,17
+.byte  102,15,58,68,220,0
+       pxor    %xmm0,%xmm3
+       pxor    %xmm1,%xmm3
+
+       movdqa  %xmm3,%xmm4
+       psrldq  $8,%xmm3
+       pslldq  $8,%xmm4
+       pxor    %xmm3,%xmm1
+       pxor    %xmm4,%xmm0
+
+       movdqa  %xmm0,%xmm3
+       psllq   $1,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $5,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $57,%xmm0
+       movdqa  %xmm0,%xmm4
+       pslldq  $8,%xmm0
+       psrldq  $8,%xmm4
+       pxor    %xmm3,%xmm0
+       pxor    %xmm4,%xmm1
+
+
+       movdqa  %xmm0,%xmm4
+       psrlq   $5,%xmm0
+       pxor    %xmm4,%xmm0
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       pxor    %xmm1,%xmm4
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+.byte  102,15,56,0,197
+       movdqu  %xmm0,(%rdi)
+       .byte   0xf3,0xc3
+.size  gcm_gmult_clmul,.-gcm_gmult_clmul
+.globl gcm_ghash_clmul
+.type  gcm_ghash_clmul,@function
+.align 16
+gcm_ghash_clmul:
+       movdqa  .Lbswap_mask(%rip),%xmm5
+
+       movdqu  (%rdi),%xmm0
+       movdqu  (%rsi),%xmm2
+.byte  102,15,56,0,197
+
+       subq    $16,%rcx
+       jz      .Lodd_tail
+
+       movdqu  16(%rsi),%xmm8
+
+
+
+
+
+       movdqu  (%rdx),%xmm3
+       movdqu  16(%rdx),%xmm6
+.byte  102,15,56,0,221
+.byte  102,15,56,0,245
+       pxor    %xmm3,%xmm0
+       movdqa  %xmm6,%xmm7
+       pshufd  $78,%xmm6,%xmm3
+       pshufd  $78,%xmm2,%xmm4
+       pxor    %xmm6,%xmm3
+       pxor    %xmm2,%xmm4
+.byte  102,15,58,68,242,0
+.byte  102,15,58,68,250,17
+.byte  102,15,58,68,220,0
+       pxor    %xmm6,%xmm3
+       pxor    %xmm7,%xmm3
+
+       movdqa  %xmm3,%xmm4
+       psrldq  $8,%xmm3
+       pslldq  $8,%xmm4
+       pxor    %xmm3,%xmm7
+       pxor    %xmm4,%xmm6
+       movdqa  %xmm0,%xmm1
+       pshufd  $78,%xmm0,%xmm3
+       pshufd  $78,%xmm8,%xmm4
+       pxor    %xmm0,%xmm3
+       pxor    %xmm8,%xmm4
+
+       leaq    32(%rdx),%rdx
+       subq    $32,%rcx
+       jbe     .Leven_tail
+
+.Lmod_loop:
+.byte  102,65,15,58,68,192,0
+.byte  102,65,15,58,68,200,17
+.byte  102,15,58,68,220,0
+       pxor    %xmm0,%xmm3
+       pxor    %xmm1,%xmm3
+
+       movdqa  %xmm3,%xmm4
+       psrldq  $8,%xmm3
+       pslldq  $8,%xmm4
+       pxor    %xmm3,%xmm1
+       pxor    %xmm4,%xmm0
+       movdqu  (%rdx),%xmm3
+       pxor    %xmm6,%xmm0
+       pxor    %xmm7,%xmm1
+
+       movdqu  16(%rdx),%xmm6
+.byte  102,15,56,0,221
+.byte  102,15,56,0,245
+
+       movdqa  %xmm6,%xmm7
+       pshufd  $78,%xmm6,%xmm9
+       pshufd  $78,%xmm2,%xmm10
+       pxor    %xmm6,%xmm9
+       pxor    %xmm2,%xmm10
+       pxor    %xmm3,%xmm1
+
+       movdqa  %xmm0,%xmm3
+       psllq   $1,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $5,%xmm0
+       pxor    %xmm3,%xmm0
+.byte  102,15,58,68,242,0
+       psllq   $57,%xmm0
+       movdqa  %xmm0,%xmm4
+       pslldq  $8,%xmm0
+       psrldq  $8,%xmm4
+       pxor    %xmm3,%xmm0
+       pxor    %xmm4,%xmm1
+
+.byte  102,15,58,68,250,17
+       movdqa  %xmm0,%xmm4
+       psrlq   $5,%xmm0
+       pxor    %xmm4,%xmm0
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       pxor    %xmm1,%xmm4
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+
+.byte  102,69,15,58,68,202,0
+       movdqa  %xmm0,%xmm1
+       pshufd  $78,%xmm0,%xmm3
+       pshufd  $78,%xmm8,%xmm4
+       pxor    %xmm0,%xmm3
+       pxor    %xmm8,%xmm4
+
+       pxor    %xmm6,%xmm9
+       pxor    %xmm7,%xmm9
+       movdqa  %xmm9,%xmm10
+       psrldq  $8,%xmm9
+       pslldq  $8,%xmm10
+       pxor    %xmm9,%xmm7
+       pxor    %xmm10,%xmm6
+
+       leaq    32(%rdx),%rdx
+       subq    $32,%rcx
+       ja      .Lmod_loop
+
+.Leven_tail:
+.byte  102,65,15,58,68,192,0
+.byte  102,65,15,58,68,200,17
+.byte  102,15,58,68,220,0
+       pxor    %xmm0,%xmm3
+       pxor    %xmm1,%xmm3
+
+       movdqa  %xmm3,%xmm4
+       psrldq  $8,%xmm3
+       pslldq  $8,%xmm4
+       pxor    %xmm3,%xmm1
+       pxor    %xmm4,%xmm0
+       pxor    %xmm6,%xmm0
+       pxor    %xmm7,%xmm1
+
+       movdqa  %xmm0,%xmm3
+       psllq   $1,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $5,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $57,%xmm0
+       movdqa  %xmm0,%xmm4
+       pslldq  $8,%xmm0
+       psrldq  $8,%xmm4
+       pxor    %xmm3,%xmm0
+       pxor    %xmm4,%xmm1
+
+
+       movdqa  %xmm0,%xmm4
+       psrlq   $5,%xmm0
+       pxor    %xmm4,%xmm0
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       pxor    %xmm1,%xmm4
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       testq   %rcx,%rcx
+       jnz     .Ldone
+
+.Lodd_tail:
+       movdqu  (%rdx),%xmm3
+.byte  102,15,56,0,221
+       pxor    %xmm3,%xmm0
+       movdqa  %xmm0,%xmm1
+       pshufd  $78,%xmm0,%xmm3
+       pshufd  $78,%xmm2,%xmm4
+       pxor    %xmm0,%xmm3
+       pxor    %xmm2,%xmm4
+.byte  102,15,58,68,194,0
+.byte  102,15,58,68,202,17
+.byte  102,15,58,68,220,0
+       pxor    %xmm0,%xmm3
+       pxor    %xmm1,%xmm3
+
+       movdqa  %xmm3,%xmm4
+       psrldq  $8,%xmm3
+       pslldq  $8,%xmm4
+       pxor    %xmm3,%xmm1
+       pxor    %xmm4,%xmm0
+
+       movdqa  %xmm0,%xmm3
+       psllq   $1,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $5,%xmm0
+       pxor    %xmm3,%xmm0
+       psllq   $57,%xmm0
+       movdqa  %xmm0,%xmm4
+       pslldq  $8,%xmm0
+       psrldq  $8,%xmm4
+       pxor    %xmm3,%xmm0
+       pxor    %xmm4,%xmm1
+
+
+       movdqa  %xmm0,%xmm4
+       psrlq   $5,%xmm0
+       pxor    %xmm4,%xmm0
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+       pxor    %xmm1,%xmm4
+       psrlq   $1,%xmm0
+       pxor    %xmm4,%xmm0
+.Ldone:
+.byte  102,15,56,0,197
+       movdqu  %xmm0,(%rdi)
+       .byte   0xf3,0xc3
+.LSEH_end_gcm_ghash_clmul:
+.size  gcm_ghash_clmul,.-gcm_ghash_clmul
+.align 64
+.Lbswap_mask:
+.byte  15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
+.L0x1c2_polynomial:
+.byte  1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xc2
+.align 64
+.type  .Lrem_4bit,@object
+.Lrem_4bit:
+.long  0,0,0,471859200,0,943718400,0,610271232
+.long  0,1887436800,0,1822425088,0,1220542464,0,1423966208
+.long  0,3774873600,0,4246732800,0,3644850176,0,3311403008
+.long  0,2441084928,0,2376073216,0,2847932416,0,3051356160
+.type  .Lrem_8bit,@object
+.Lrem_8bit:
+.value 0x0000,0x01C2,0x0384,0x0246,0x0708,0x06CA,0x048C,0x054E
+.value 0x0E10,0x0FD2,0x0D94,0x0C56,0x0918,0x08DA,0x0A9C,0x0B5E
+.value 0x1C20,0x1DE2,0x1FA4,0x1E66,0x1B28,0x1AEA,0x18AC,0x196E
+.value 0x1230,0x13F2,0x11B4,0x1076,0x1538,0x14FA,0x16BC,0x177E
+.value 0x3840,0x3982,0x3BC4,0x3A06,0x3F48,0x3E8A,0x3CCC,0x3D0E
+.value 0x3650,0x3792,0x35D4,0x3416,0x3158,0x309A,0x32DC,0x331E
+.value 0x2460,0x25A2,0x27E4,0x2626,0x2368,0x22AA,0x20EC,0x212E
+.value 0x2A70,0x2BB2,0x29F4,0x2836,0x2D78,0x2CBA,0x2EFC,0x2F3E
+.value 0x7080,0x7142,0x7304,0x72C6,0x7788,0x764A,0x740C,0x75CE
+.value 0x7E90,0x7F52,0x7D14,0x7CD6,0x7998,0x785A,0x7A1C,0x7BDE
+.value 0x6CA0,0x6D62,0x6F24,0x6EE6,0x6BA8,0x6A6A,0x682C,0x69EE
+.value 0x62B0,0x6372,0x6134,0x60F6,0x65B8,0x647A,0x663C,0x67FE
+.value 0x48C0,0x4902,0x4B44,0x4A86,0x4FC8,0x4E0A,0x4C4C,0x4D8E
+.value 0x46D0,0x4712,0x4554,0x4496,0x41D8,0x401A,0x425C,0x439E
+.value 0x54E0,0x5522,0x5764,0x56A6,0x53E8,0x522A,0x506C,0x51AE
+.value 0x5AF0,0x5B32,0x5974,0x58B6,0x5DF8,0x5C3A,0x5E7C,0x5FBE
+.value 0xE100,0xE0C2,0xE284,0xE346,0xE608,0xE7CA,0xE58C,0xE44E
+.value 0xEF10,0xEED2,0xEC94,0xED56,0xE818,0xE9DA,0xEB9C,0xEA5E
+.value 0xFD20,0xFCE2,0xFEA4,0xFF66,0xFA28,0xFBEA,0xF9AC,0xF86E
+.value 0xF330,0xF2F2,0xF0B4,0xF176,0xF438,0xF5FA,0xF7BC,0xF67E
+.value 0xD940,0xD882,0xDAC4,0xDB06,0xDE48,0xDF8A,0xDDCC,0xDC0E
+.value 0xD750,0xD692,0xD4D4,0xD516,0xD058,0xD19A,0xD3DC,0xD21E
+.value 0xC560,0xC4A2,0xC6E4,0xC726,0xC268,0xC3AA,0xC1EC,0xC02E
+.value 0xCB70,0xCAB2,0xC8F4,0xC936,0xCC78,0xCDBA,0xCFFC,0xCE3E
+.value 0x9180,0x9042,0x9204,0x93C6,0x9688,0x974A,0x950C,0x94CE
+.value 0x9F90,0x9E52,0x9C14,0x9DD6,0x9898,0x995A,0x9B1C,0x9ADE
+.value 0x8DA0,0x8C62,0x8E24,0x8FE6,0x8AA8,0x8B6A,0x892C,0x88EE
+.value 0x83B0,0x8272,0x8034,0x81F6,0x84B8,0x857A,0x873C,0x86FE
+.value 0xA9C0,0xA802,0xAA44,0xAB86,0xAEC8,0xAF0A,0xAD4C,0xAC8E
+.value 0xA7D0,0xA612,0xA454,0xA596,0xA0D8,0xA11A,0xA35C,0xA29E
+.value 0xB5E0,0xB422,0xB664,0xB7A6,0xB2E8,0xB32A,0xB16C,0xB0AE
+.value 0xBBF0,0xBA32,0xB874,0xB9B6,0xBCF8,0xBD3A,0xBF7C,0xBEBE
+
+.byte  
71,72,65,83,72,32,102,111,114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
+.align 64
+
+#if defined(__ELF__)
+.section .note.GNU-stack,"",%progbits
+#endif
diff --git a/lib/accelerated/x86/asm/appro-aes-x86-64.s 
b/lib/accelerated/x86/asm/appro-aes-x86-64.s
new file mode 100644
index 0000000..efd6375
--- /dev/null
+++ b/lib/accelerated/x86/asm/appro-aes-x86-64.s
@@ -0,0 +1,2578 @@
+# Copyright (c) 2011, Andy Polyakov by <address@hidden>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 
+#     * Redistributions of source code must retain copyright notices,
+#      this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+#
+#     * Neither the name of the Andy Polyakov nor the names of its
+#      copyright holder and contributors may be used to endorse or
+#      promote products derived from this software without specific
+#      prior written permission.
+#
+# ALTERNATIVELY, provided that this notice is retained in full, this
+# product may be distributed under the terms of the GNU General Public
+# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+# those given above.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.text  
+.globl aesni_encrypt
+.type  aesni_encrypt,@function
+.align 16
+aesni_encrypt:
+       movups  (%rdi),%xmm2
+       movl    240(%rdx),%eax
+       movups  (%rdx),%xmm0
+       movups  16(%rdx),%xmm1
+       leaq    32(%rdx),%rdx
+       xorps   %xmm0,%xmm2
+.Loop_enc1_1:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rdx),%xmm1
+       leaq    16(%rdx),%rdx
+       jnz     .Loop_enc1_1    
+.byte  102,15,56,221,209
+       movups  %xmm2,(%rsi)
+       .byte   0xf3,0xc3
+.size  aesni_encrypt,.-aesni_encrypt
+
+.globl aesni_decrypt
+.type  aesni_decrypt,@function
+.align 16
+aesni_decrypt:
+       movups  (%rdi),%xmm2
+       movl    240(%rdx),%eax
+       movups  (%rdx),%xmm0
+       movups  16(%rdx),%xmm1
+       leaq    32(%rdx),%rdx
+       xorps   %xmm0,%xmm2
+.Loop_dec1_2:
+.byte  102,15,56,222,209
+       decl    %eax
+       movups  (%rdx),%xmm1
+       leaq    16(%rdx),%rdx
+       jnz     .Loop_dec1_2    
+.byte  102,15,56,223,209
+       movups  %xmm2,(%rsi)
+       .byte   0xf3,0xc3
+.size  aesni_decrypt, .-aesni_decrypt
+.type  _aesni_encrypt3,@function
+.align 16
+_aesni_encrypt3:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm0,%xmm3
+       xorps   %xmm0,%xmm4
+       movups  (%rcx),%xmm0
+
+.Lenc_loop3:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %eax
+.byte  102,15,56,220,225
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,224
+       movups  (%rcx),%xmm0
+       jnz     .Lenc_loop3
+
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+       .byte   0xf3,0xc3
+.size  _aesni_encrypt3,.-_aesni_encrypt3
+.type  _aesni_decrypt3,@function
+.align 16
+_aesni_decrypt3:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm0,%xmm3
+       xorps   %xmm0,%xmm4
+       movups  (%rcx),%xmm0
+
+.Ldec_loop3:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %eax
+.byte  102,15,56,222,225
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,222,224
+       movups  (%rcx),%xmm0
+       jnz     .Ldec_loop3
+
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+       .byte   0xf3,0xc3
+.size  _aesni_decrypt3,.-_aesni_decrypt3
+.type  _aesni_encrypt4,@function
+.align 16
+_aesni_encrypt4:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm0,%xmm3
+       xorps   %xmm0,%xmm4
+       xorps   %xmm0,%xmm5
+       movups  (%rcx),%xmm0
+
+.Lenc_loop4:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %eax
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+       movups  (%rcx),%xmm0
+       jnz     .Lenc_loop4
+
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+.byte  102,15,56,221,232
+       .byte   0xf3,0xc3
+.size  _aesni_encrypt4,.-_aesni_encrypt4
+.type  _aesni_decrypt4,@function
+.align 16
+_aesni_decrypt4:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm0,%xmm3
+       xorps   %xmm0,%xmm4
+       xorps   %xmm0,%xmm5
+       movups  (%rcx),%xmm0
+
+.Ldec_loop4:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %eax
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,222,224
+.byte  102,15,56,222,232
+       movups  (%rcx),%xmm0
+       jnz     .Ldec_loop4
+
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+.byte  102,15,56,223,232
+       .byte   0xf3,0xc3
+.size  _aesni_decrypt4,.-_aesni_decrypt4
+.type  _aesni_encrypt6,@function
+.align 16
+_aesni_encrypt6:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+.byte  102,15,56,220,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,220,217
+       pxor    %xmm0,%xmm5
+.byte  102,15,56,220,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+       decl    %eax
+.byte  102,15,56,220,241
+       movups  (%rcx),%xmm0
+.byte  102,15,56,220,249
+       jmp     .Lenc_loop6_enter
+.align 16
+.Lenc_loop6:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %eax
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.Lenc_loop6_enter:
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+.byte  102,15,56,220,240
+.byte  102,15,56,220,248
+       movups  (%rcx),%xmm0
+       jnz     .Lenc_loop6
+
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+.byte  102,15,56,221,232
+.byte  102,15,56,221,240
+.byte  102,15,56,221,248
+       .byte   0xf3,0xc3
+.size  _aesni_encrypt6,.-_aesni_encrypt6
+.type  _aesni_decrypt6,@function
+.align 16
+_aesni_decrypt6:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+.byte  102,15,56,222,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,222,217
+       pxor    %xmm0,%xmm5
+.byte  102,15,56,222,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,222,233
+       pxor    %xmm0,%xmm7
+       decl    %eax
+.byte  102,15,56,222,241
+       movups  (%rcx),%xmm0
+.byte  102,15,56,222,249
+       jmp     .Ldec_loop6_enter
+.align 16
+.Ldec_loop6:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %eax
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.Ldec_loop6_enter:
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,222,224
+.byte  102,15,56,222,232
+.byte  102,15,56,222,240
+.byte  102,15,56,222,248
+       movups  (%rcx),%xmm0
+       jnz     .Ldec_loop6
+
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+.byte  102,15,56,223,232
+.byte  102,15,56,223,240
+.byte  102,15,56,223,248
+       .byte   0xf3,0xc3
+.size  _aesni_decrypt6,.-_aesni_decrypt6
+.type  _aesni_encrypt8,@function
+.align 16
+_aesni_encrypt8:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm0,%xmm3
+.byte  102,15,56,220,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,220,217
+       pxor    %xmm0,%xmm5
+.byte  102,15,56,220,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+       decl    %eax
+.byte  102,15,56,220,241
+       pxor    %xmm0,%xmm8
+.byte  102,15,56,220,249
+       pxor    %xmm0,%xmm9
+       movups  (%rcx),%xmm0
+.byte  102,68,15,56,220,193
+.byte  102,68,15,56,220,201
+       movups  16(%rcx),%xmm1
+       jmp     .Lenc_loop8_enter
+.align 16
+.Lenc_loop8:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %eax
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.byte  102,68,15,56,220,193
+.byte  102,68,15,56,220,201
+       movups  16(%rcx),%xmm1
+.Lenc_loop8_enter:
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+.byte  102,15,56,220,240
+.byte  102,15,56,220,248
+.byte  102,68,15,56,220,192
+.byte  102,68,15,56,220,200
+       movups  (%rcx),%xmm0
+       jnz     .Lenc_loop8
+
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.byte  102,68,15,56,220,193
+.byte  102,68,15,56,220,201
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+.byte  102,15,56,221,232
+.byte  102,15,56,221,240
+.byte  102,15,56,221,248
+.byte  102,68,15,56,221,192
+.byte  102,68,15,56,221,200
+       .byte   0xf3,0xc3
+.size  _aesni_encrypt8,.-_aesni_encrypt8
+.type  _aesni_decrypt8,@function
+.align 16
+_aesni_decrypt8:
+       movups  (%rcx),%xmm0
+       shrl    $1,%eax
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm0,%xmm3
+.byte  102,15,56,222,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,222,217
+       pxor    %xmm0,%xmm5
+.byte  102,15,56,222,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,222,233
+       pxor    %xmm0,%xmm7
+       decl    %eax
+.byte  102,15,56,222,241
+       pxor    %xmm0,%xmm8
+.byte  102,15,56,222,249
+       pxor    %xmm0,%xmm9
+       movups  (%rcx),%xmm0
+.byte  102,68,15,56,222,193
+.byte  102,68,15,56,222,201
+       movups  16(%rcx),%xmm1
+       jmp     .Ldec_loop8_enter
+.align 16
+.Ldec_loop8:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %eax
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.byte  102,68,15,56,222,193
+.byte  102,68,15,56,222,201
+       movups  16(%rcx),%xmm1
+.Ldec_loop8_enter:
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,222,224
+.byte  102,15,56,222,232
+.byte  102,15,56,222,240
+.byte  102,15,56,222,248
+.byte  102,68,15,56,222,192
+.byte  102,68,15,56,222,200
+       movups  (%rcx),%xmm0
+       jnz     .Ldec_loop8
+
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.byte  102,68,15,56,222,193
+.byte  102,68,15,56,222,201
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+.byte  102,15,56,223,232
+.byte  102,15,56,223,240
+.byte  102,15,56,223,248
+.byte  102,68,15,56,223,192
+.byte  102,68,15,56,223,200
+       .byte   0xf3,0xc3
+.size  _aesni_decrypt8,.-_aesni_decrypt8
+.globl aesni_ecb_encrypt
+.type  aesni_ecb_encrypt,@function
+.align 16
+aesni_ecb_encrypt:
+       andq    $-16,%rdx
+       jz      .Lecb_ret
+
+       movl    240(%rcx),%eax
+       movups  (%rcx),%xmm0
+       movq    %rcx,%r11
+       movl    %eax,%r10d
+       testl   %r8d,%r8d
+       jz      .Lecb_decrypt
+
+       cmpq    $128,%rdx
+       jb      .Lecb_enc_tail
+
+       movdqu  (%rdi),%xmm2
+       movdqu  16(%rdi),%xmm3
+       movdqu  32(%rdi),%xmm4
+       movdqu  48(%rdi),%xmm5
+       movdqu  64(%rdi),%xmm6
+       movdqu  80(%rdi),%xmm7
+       movdqu  96(%rdi),%xmm8
+       movdqu  112(%rdi),%xmm9
+       leaq    128(%rdi),%rdi
+       subq    $128,%rdx
+       jmp     .Lecb_enc_loop8_enter
+.align 16
+.Lecb_enc_loop8:
+       movups  %xmm2,(%rsi)
+       movq    %r11,%rcx
+       movdqu  (%rdi),%xmm2
+       movl    %r10d,%eax
+       movups  %xmm3,16(%rsi)
+       movdqu  16(%rdi),%xmm3
+       movups  %xmm4,32(%rsi)
+       movdqu  32(%rdi),%xmm4
+       movups  %xmm5,48(%rsi)
+       movdqu  48(%rdi),%xmm5
+       movups  %xmm6,64(%rsi)
+       movdqu  64(%rdi),%xmm6
+       movups  %xmm7,80(%rsi)
+       movdqu  80(%rdi),%xmm7
+       movups  %xmm8,96(%rsi)
+       movdqu  96(%rdi),%xmm8
+       movups  %xmm9,112(%rsi)
+       leaq    128(%rsi),%rsi
+       movdqu  112(%rdi),%xmm9
+       leaq    128(%rdi),%rdi
+.Lecb_enc_loop8_enter:
+
+       call    _aesni_encrypt8
+
+       subq    $128,%rdx
+       jnc     .Lecb_enc_loop8
+
+       movups  %xmm2,(%rsi)
+       movq    %r11,%rcx
+       movups  %xmm3,16(%rsi)
+       movl    %r10d,%eax
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       movups  %xmm8,96(%rsi)
+       movups  %xmm9,112(%rsi)
+       leaq    128(%rsi),%rsi
+       addq    $128,%rdx
+       jz      .Lecb_ret
+
+.Lecb_enc_tail:
+       movups  (%rdi),%xmm2
+       cmpq    $32,%rdx
+       jb      .Lecb_enc_one
+       movups  16(%rdi),%xmm3
+       je      .Lecb_enc_two
+       movups  32(%rdi),%xmm4
+       cmpq    $64,%rdx
+       jb      .Lecb_enc_three
+       movups  48(%rdi),%xmm5
+       je      .Lecb_enc_four
+       movups  64(%rdi),%xmm6
+       cmpq    $96,%rdx
+       jb      .Lecb_enc_five
+       movups  80(%rdi),%xmm7
+       je      .Lecb_enc_six
+       movdqu  96(%rdi),%xmm8
+       call    _aesni_encrypt8
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       movups  %xmm8,96(%rsi)
+       jmp     .Lecb_ret
+.align 16
+.Lecb_enc_one:
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_enc1_3:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_enc1_3    
+.byte  102,15,56,221,209
+       movups  %xmm2,(%rsi)
+       jmp     .Lecb_ret
+.align 16
+.Lecb_enc_two:
+       xorps   %xmm4,%xmm4
+       call    _aesni_encrypt3
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       jmp     .Lecb_ret
+.align 16
+.Lecb_enc_three:
+       call    _aesni_encrypt3
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       jmp     .Lecb_ret
+.align 16
+.Lecb_enc_four:
+       call    _aesni_encrypt4
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       jmp     .Lecb_ret
+.align 16
+.Lecb_enc_five:
+       xorps   %xmm7,%xmm7
+       call    _aesni_encrypt6
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       jmp     .Lecb_ret
+.align 16
+.Lecb_enc_six:
+       call    _aesni_encrypt6
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       jmp     .Lecb_ret
+
+.align 16
+.Lecb_decrypt:
+       cmpq    $128,%rdx
+       jb      .Lecb_dec_tail
+
+       movdqu  (%rdi),%xmm2
+       movdqu  16(%rdi),%xmm3
+       movdqu  32(%rdi),%xmm4
+       movdqu  48(%rdi),%xmm5
+       movdqu  64(%rdi),%xmm6
+       movdqu  80(%rdi),%xmm7
+       movdqu  96(%rdi),%xmm8
+       movdqu  112(%rdi),%xmm9
+       leaq    128(%rdi),%rdi
+       subq    $128,%rdx
+       jmp     .Lecb_dec_loop8_enter
+.align 16
+.Lecb_dec_loop8:
+       movups  %xmm2,(%rsi)
+       movq    %r11,%rcx
+       movdqu  (%rdi),%xmm2
+       movl    %r10d,%eax
+       movups  %xmm3,16(%rsi)
+       movdqu  16(%rdi),%xmm3
+       movups  %xmm4,32(%rsi)
+       movdqu  32(%rdi),%xmm4
+       movups  %xmm5,48(%rsi)
+       movdqu  48(%rdi),%xmm5
+       movups  %xmm6,64(%rsi)
+       movdqu  64(%rdi),%xmm6
+       movups  %xmm7,80(%rsi)
+       movdqu  80(%rdi),%xmm7
+       movups  %xmm8,96(%rsi)
+       movdqu  96(%rdi),%xmm8
+       movups  %xmm9,112(%rsi)
+       leaq    128(%rsi),%rsi
+       movdqu  112(%rdi),%xmm9
+       leaq    128(%rdi),%rdi
+.Lecb_dec_loop8_enter:
+
+       call    _aesni_decrypt8
+
+       movups  (%r11),%xmm0
+       subq    $128,%rdx
+       jnc     .Lecb_dec_loop8
+
+       movups  %xmm2,(%rsi)
+       movq    %r11,%rcx
+       movups  %xmm3,16(%rsi)
+       movl    %r10d,%eax
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       movups  %xmm8,96(%rsi)
+       movups  %xmm9,112(%rsi)
+       leaq    128(%rsi),%rsi
+       addq    $128,%rdx
+       jz      .Lecb_ret
+
+.Lecb_dec_tail:
+       movups  (%rdi),%xmm2
+       cmpq    $32,%rdx
+       jb      .Lecb_dec_one
+       movups  16(%rdi),%xmm3
+       je      .Lecb_dec_two
+       movups  32(%rdi),%xmm4
+       cmpq    $64,%rdx
+       jb      .Lecb_dec_three
+       movups  48(%rdi),%xmm5
+       je      .Lecb_dec_four
+       movups  64(%rdi),%xmm6
+       cmpq    $96,%rdx
+       jb      .Lecb_dec_five
+       movups  80(%rdi),%xmm7
+       je      .Lecb_dec_six
+       movups  96(%rdi),%xmm8
+       movups  (%rcx),%xmm0
+       call    _aesni_decrypt8
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       movups  %xmm8,96(%rsi)
+       jmp     .Lecb_ret
+.align 16
+.Lecb_dec_one:
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_dec1_4:
+.byte  102,15,56,222,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_dec1_4    
+.byte  102,15,56,223,209
+       movups  %xmm2,(%rsi)
+       jmp     .Lecb_ret
+.align 16
+.Lecb_dec_two:
+       xorps   %xmm4,%xmm4
+       call    _aesni_decrypt3
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       jmp     .Lecb_ret
+.align 16
+.Lecb_dec_three:
+       call    _aesni_decrypt3
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       jmp     .Lecb_ret
+.align 16
+.Lecb_dec_four:
+       call    _aesni_decrypt4
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       jmp     .Lecb_ret
+.align 16
+.Lecb_dec_five:
+       xorps   %xmm7,%xmm7
+       call    _aesni_decrypt6
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       jmp     .Lecb_ret
+.align 16
+.Lecb_dec_six:
+       call    _aesni_decrypt6
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+
+.Lecb_ret:
+       .byte   0xf3,0xc3
+.size  aesni_ecb_encrypt,.-aesni_ecb_encrypt
+.globl aesni_ccm64_encrypt_blocks
+.type  aesni_ccm64_encrypt_blocks,@function
+.align 16
+aesni_ccm64_encrypt_blocks:
+       movl    240(%rcx),%eax
+       movdqu  (%r8),%xmm9
+       movdqa  .Lincrement64(%rip),%xmm6
+       movdqa  .Lbswap_mask(%rip),%xmm7
+
+       shrl    $1,%eax
+       leaq    0(%rcx),%r11
+       movdqu  (%r9),%xmm3
+       movdqa  %xmm9,%xmm2
+       movl    %eax,%r10d
+       jmp     .Lccm64_enc_outer
+.align 16
+.Lccm64_enc_outer:
+       movups  (%r11),%xmm0
+       movl    %r10d,%eax
+       movups  (%rdi),%xmm8
+
+       xorps   %xmm0,%xmm2
+       movups  16(%r11),%xmm1
+       xorps   %xmm8,%xmm0
+       leaq    32(%r11),%rcx
+       xorps   %xmm0,%xmm3
+       movups  (%rcx),%xmm0
+
+.Lccm64_enc2_loop:
+.byte  102,15,56,220,209
+       decl    %eax
+.byte  102,15,56,220,217
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,216
+       movups  0(%rcx),%xmm0
+       jnz     .Lccm64_enc2_loop
+.byte  102,68,15,56,0,207
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       paddq   %xmm6,%xmm9
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+
+       decq    %rdx
+       leaq    16(%rdi),%rdi
+       xorps   %xmm2,%xmm8
+       movdqa  %xmm9,%xmm2
+       movups  %xmm8,(%rsi)
+       leaq    16(%rsi),%rsi
+.byte  102,68,15,56,0,207
+       jnz     .Lccm64_enc_outer
+
+       movups  %xmm3,(%r9)
+       .byte   0xf3,0xc3
+.size  aesni_ccm64_encrypt_blocks,.-aesni_ccm64_encrypt_blocks
+.globl aesni_ccm64_decrypt_blocks
+.type  aesni_ccm64_decrypt_blocks,@function
+.align 16
+aesni_ccm64_decrypt_blocks:
+       movl    240(%rcx),%eax
+       movups  (%r8),%xmm9
+       movdqu  (%r9),%xmm3
+       movdqa  .Lincrement64(%rip),%xmm6
+       movdqa  .Lbswap_mask(%rip),%xmm7
+
+       movaps  %xmm9,%xmm2
+       movl    %eax,%r10d
+       movq    %rcx,%r11
+.byte  102,68,15,56,0,207
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_enc1_5:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_enc1_5    
+.byte  102,15,56,221,209
+       movups  (%rdi),%xmm8
+       paddq   %xmm6,%xmm9
+.byte  102,68,15,56,0,207
+       leaq    16(%rdi),%rdi
+       jmp     .Lccm64_dec_outer
+.align 16
+.Lccm64_dec_outer:
+       xorps   %xmm2,%xmm8
+       movdqa  %xmm9,%xmm2
+       movl    %r10d,%eax
+       movups  %xmm8,(%rsi)
+       leaq    16(%rsi),%rsi
+
+       subq    $1,%rdx
+       jz      .Lccm64_dec_break
+
+       movups  (%r11),%xmm0
+       shrl    $1,%eax
+       movups  16(%r11),%xmm1
+       xorps   %xmm0,%xmm8
+       leaq    32(%r11),%rcx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm8,%xmm3
+       movups  (%rcx),%xmm0
+
+.Lccm64_dec2_loop:
+.byte  102,15,56,220,209
+       decl    %eax
+.byte  102,15,56,220,217
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,216
+       movups  0(%rcx),%xmm0
+       jnz     .Lccm64_dec2_loop
+       movups  (%rdi),%xmm8
+       paddq   %xmm6,%xmm9
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,68,15,56,0,207
+       leaq    16(%rdi),%rdi
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+       jmp     .Lccm64_dec_outer
+
+.align 16
+.Lccm64_dec_break:
+
+       movups  (%r11),%xmm0
+       movups  16(%r11),%xmm1
+       xorps   %xmm0,%xmm8
+       leaq    32(%r11),%r11
+       xorps   %xmm8,%xmm3
+.Loop_enc1_6:
+.byte  102,15,56,220,217
+       decl    %eax
+       movups  (%r11),%xmm1
+       leaq    16(%r11),%r11
+       jnz     .Loop_enc1_6    
+.byte  102,15,56,221,217
+       movups  %xmm3,(%r9)
+       .byte   0xf3,0xc3
+.size  aesni_ccm64_decrypt_blocks,.-aesni_ccm64_decrypt_blocks
+.globl aesni_ctr32_encrypt_blocks
+.type  aesni_ctr32_encrypt_blocks,@function
+.align 16
+aesni_ctr32_encrypt_blocks:
+       cmpq    $1,%rdx
+       je      .Lctr32_one_shortcut
+
+       movdqu  (%r8),%xmm14
+       movdqa  .Lbswap_mask(%rip),%xmm15
+       xorl    %eax,%eax
+.byte  102,69,15,58,22,242,3
+.byte  102,68,15,58,34,240,3
+
+       movl    240(%rcx),%eax
+       bswapl  %r10d
+       pxor    %xmm12,%xmm12
+       pxor    %xmm13,%xmm13
+.byte  102,69,15,58,34,226,0
+       leaq    3(%r10),%r11
+.byte  102,69,15,58,34,235,0
+       incl    %r10d
+.byte  102,69,15,58,34,226,1
+       incq    %r11
+.byte  102,69,15,58,34,235,1
+       incl    %r10d
+.byte  102,69,15,58,34,226,2
+       incq    %r11
+.byte  102,69,15,58,34,235,2
+       movdqa  %xmm12,-40(%rsp)
+.byte  102,69,15,56,0,231
+       movdqa  %xmm13,-24(%rsp)
+.byte  102,69,15,56,0,239
+
+       pshufd  $192,%xmm12,%xmm2
+       pshufd  $128,%xmm12,%xmm3
+       pshufd  $64,%xmm12,%xmm4
+       cmpq    $6,%rdx
+       jb      .Lctr32_tail
+       shrl    $1,%eax
+       movq    %rcx,%r11
+       movl    %eax,%r10d
+       subq    $6,%rdx
+       jmp     .Lctr32_loop6
+
+.align 16
+.Lctr32_loop6:
+       pshufd  $192,%xmm13,%xmm5
+       por     %xmm14,%xmm2
+       movups  (%r11),%xmm0
+       pshufd  $128,%xmm13,%xmm6
+       por     %xmm14,%xmm3
+       movups  16(%r11),%xmm1
+       pshufd  $64,%xmm13,%xmm7
+       por     %xmm14,%xmm4
+       por     %xmm14,%xmm5
+       xorps   %xmm0,%xmm2
+       por     %xmm14,%xmm6
+       por     %xmm14,%xmm7
+
+
+
+
+       pxor    %xmm0,%xmm3
+.byte  102,15,56,220,209
+       leaq    32(%r11),%rcx
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,220,217
+       movdqa  .Lincrement32(%rip),%xmm13
+       pxor    %xmm0,%xmm5
+.byte  102,15,56,220,225
+       movdqa  -40(%rsp),%xmm12
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+       movups  (%rcx),%xmm0
+       decl    %eax
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+       jmp     .Lctr32_enc_loop6_enter
+.align 16
+.Lctr32_enc_loop6:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %eax
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.Lctr32_enc_loop6_enter:
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+.byte  102,15,56,220,240
+.byte  102,15,56,220,248
+       movups  (%rcx),%xmm0
+       jnz     .Lctr32_enc_loop6
+
+.byte  102,15,56,220,209
+       paddd   %xmm13,%xmm12
+.byte  102,15,56,220,217
+       paddd   -24(%rsp),%xmm13
+.byte  102,15,56,220,225
+       movdqa  %xmm12,-40(%rsp)
+.byte  102,15,56,220,233
+       movdqa  %xmm13,-24(%rsp)
+.byte  102,15,56,220,241
+.byte  102,69,15,56,0,231
+.byte  102,15,56,220,249
+.byte  102,69,15,56,0,239
+
+.byte  102,15,56,221,208
+       movups  (%rdi),%xmm8
+.byte  102,15,56,221,216
+       movups  16(%rdi),%xmm9
+.byte  102,15,56,221,224
+       movups  32(%rdi),%xmm10
+.byte  102,15,56,221,232
+       movups  48(%rdi),%xmm11
+.byte  102,15,56,221,240
+       movups  64(%rdi),%xmm1
+.byte  102,15,56,221,248
+       movups  80(%rdi),%xmm0
+       leaq    96(%rdi),%rdi
+
+       xorps   %xmm2,%xmm8
+       pshufd  $192,%xmm12,%xmm2
+       xorps   %xmm3,%xmm9
+       pshufd  $128,%xmm12,%xmm3
+       movups  %xmm8,(%rsi)
+       xorps   %xmm4,%xmm10
+       pshufd  $64,%xmm12,%xmm4
+       movups  %xmm9,16(%rsi)
+       xorps   %xmm5,%xmm11
+       movups  %xmm10,32(%rsi)
+       xorps   %xmm6,%xmm1
+       movups  %xmm11,48(%rsi)
+       xorps   %xmm7,%xmm0
+       movups  %xmm1,64(%rsi)
+       movups  %xmm0,80(%rsi)
+       leaq    96(%rsi),%rsi
+       movl    %r10d,%eax
+       subq    $6,%rdx
+       jnc     .Lctr32_loop6
+
+       addq    $6,%rdx
+       jz      .Lctr32_done
+       movq    %r11,%rcx
+       leal    1(%rax,%rax,1),%eax
+
+.Lctr32_tail:
+       por     %xmm14,%xmm2
+       movups  (%rdi),%xmm8
+       cmpq    $2,%rdx
+       jb      .Lctr32_one
+
+       por     %xmm14,%xmm3
+       movups  16(%rdi),%xmm9
+       je      .Lctr32_two
+
+       pshufd  $192,%xmm13,%xmm5
+       por     %xmm14,%xmm4
+       movups  32(%rdi),%xmm10
+       cmpq    $4,%rdx
+       jb      .Lctr32_three
+
+       pshufd  $128,%xmm13,%xmm6
+       por     %xmm14,%xmm5
+       movups  48(%rdi),%xmm11
+       je      .Lctr32_four
+
+       por     %xmm14,%xmm6
+       xorps   %xmm7,%xmm7
+
+       call    _aesni_encrypt6
+
+       movups  64(%rdi),%xmm1
+       xorps   %xmm2,%xmm8
+       xorps   %xmm3,%xmm9
+       movups  %xmm8,(%rsi)
+       xorps   %xmm4,%xmm10
+       movups  %xmm9,16(%rsi)
+       xorps   %xmm5,%xmm11
+       movups  %xmm10,32(%rsi)
+       xorps   %xmm6,%xmm1
+       movups  %xmm11,48(%rsi)
+       movups  %xmm1,64(%rsi)
+       jmp     .Lctr32_done
+
+.align 16
+.Lctr32_one_shortcut:
+       movups  (%r8),%xmm2
+       movups  (%rdi),%xmm8
+       movl    240(%rcx),%eax
+.Lctr32_one:
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_enc1_7:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_enc1_7    
+.byte  102,15,56,221,209
+       xorps   %xmm2,%xmm8
+       movups  %xmm8,(%rsi)
+       jmp     .Lctr32_done
+
+.align 16
+.Lctr32_two:
+       xorps   %xmm4,%xmm4
+       call    _aesni_encrypt3
+       xorps   %xmm2,%xmm8
+       xorps   %xmm3,%xmm9
+       movups  %xmm8,(%rsi)
+       movups  %xmm9,16(%rsi)
+       jmp     .Lctr32_done
+
+.align 16
+.Lctr32_three:
+       call    _aesni_encrypt3
+       xorps   %xmm2,%xmm8
+       xorps   %xmm3,%xmm9
+       movups  %xmm8,(%rsi)
+       xorps   %xmm4,%xmm10
+       movups  %xmm9,16(%rsi)
+       movups  %xmm10,32(%rsi)
+       jmp     .Lctr32_done
+
+.align 16
+.Lctr32_four:
+       call    _aesni_encrypt4
+       xorps   %xmm2,%xmm8
+       xorps   %xmm3,%xmm9
+       movups  %xmm8,(%rsi)
+       xorps   %xmm4,%xmm10
+       movups  %xmm9,16(%rsi)
+       xorps   %xmm5,%xmm11
+       movups  %xmm10,32(%rsi)
+       movups  %xmm11,48(%rsi)
+
+.Lctr32_done:
+       .byte   0xf3,0xc3
+.size  aesni_ctr32_encrypt_blocks,.-aesni_ctr32_encrypt_blocks
+.globl aesni_xts_encrypt
+.type  aesni_xts_encrypt,@function
+.align 16
+aesni_xts_encrypt:
+       leaq    -104(%rsp),%rsp
+       movups  (%r9),%xmm15
+       movl    240(%r8),%eax
+       movl    240(%rcx),%r10d
+       movups  (%r8),%xmm0
+       movups  16(%r8),%xmm1
+       leaq    32(%r8),%r8
+       xorps   %xmm0,%xmm15
+.Loop_enc1_8:
+.byte  102,68,15,56,220,249
+       decl    %eax
+       movups  (%r8),%xmm1
+       leaq    16(%r8),%r8
+       jnz     .Loop_enc1_8    
+.byte  102,68,15,56,221,249
+       movq    %rcx,%r11
+       movl    %r10d,%eax
+       movq    %rdx,%r9
+       andq    $-16,%rdx
+
+       movdqa  .Lxts_magic(%rip),%xmm8
+       pxor    %xmm14,%xmm14
+       pcmpgtd %xmm15,%xmm14
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm10
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm11
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm12
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm13
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       subq    $96,%rdx
+       jc      .Lxts_enc_short
+
+       shrl    $1,%eax
+       subl    $1,%eax
+       movl    %eax,%r10d
+       jmp     .Lxts_enc_grandloop
+
+.align 16
+.Lxts_enc_grandloop:
+       pshufd  $19,%xmm14,%xmm9
+       movdqa  %xmm15,%xmm14
+       paddq   %xmm15,%xmm15
+       movdqu  0(%rdi),%xmm2
+       pand    %xmm8,%xmm9
+       movdqu  16(%rdi),%xmm3
+       pxor    %xmm9,%xmm15
+
+       movdqu  32(%rdi),%xmm4
+       pxor    %xmm10,%xmm2
+       movdqu  48(%rdi),%xmm5
+       pxor    %xmm11,%xmm3
+       movdqu  64(%rdi),%xmm6
+       pxor    %xmm12,%xmm4
+       movdqu  80(%rdi),%xmm7
+       leaq    96(%rdi),%rdi
+       pxor    %xmm13,%xmm5
+       movups  (%r11),%xmm0
+       pxor    %xmm14,%xmm6
+       pxor    %xmm15,%xmm7
+
+
+
+       movups  16(%r11),%xmm1
+       pxor    %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+       movdqa  %xmm10,0(%rsp)
+.byte  102,15,56,220,209
+       leaq    32(%r11),%rcx
+       pxor    %xmm0,%xmm4
+       movdqa  %xmm11,16(%rsp)
+.byte  102,15,56,220,217
+       pxor    %xmm0,%xmm5
+       movdqa  %xmm12,32(%rsp)
+.byte  102,15,56,220,225
+       pxor    %xmm0,%xmm6
+       movdqa  %xmm13,48(%rsp)
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+       movups  (%rcx),%xmm0
+       decl    %eax
+       movdqa  %xmm14,64(%rsp)
+.byte  102,15,56,220,241
+       movdqa  %xmm15,80(%rsp)
+.byte  102,15,56,220,249
+       pxor    %xmm14,%xmm14
+       pcmpgtd %xmm15,%xmm14
+       jmp     .Lxts_enc_loop6_enter
+
+.align 16
+.Lxts_enc_loop6:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %eax
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.Lxts_enc_loop6_enter:
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+.byte  102,15,56,220,240
+.byte  102,15,56,220,248
+       movups  (%rcx),%xmm0
+       jnz     .Lxts_enc_loop6
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,220,209
+       pand    %xmm8,%xmm9
+.byte  102,15,56,220,217
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,220,225
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+       movups  16(%rcx),%xmm1
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm10
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,220,208
+       pand    %xmm8,%xmm9
+.byte  102,15,56,220,216
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,220,224
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,220,232
+.byte  102,15,56,220,240
+.byte  102,15,56,220,248
+       movups  32(%rcx),%xmm0
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm11
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,220,209
+       pand    %xmm8,%xmm9
+.byte  102,15,56,220,217
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,220,225
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm12
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,221,208
+       pand    %xmm8,%xmm9
+.byte  102,15,56,221,216
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,221,224
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,221,232
+.byte  102,15,56,221,240
+.byte  102,15,56,221,248
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm13
+       paddq   %xmm15,%xmm15
+       xorps   0(%rsp),%xmm2
+       pand    %xmm8,%xmm9
+       xorps   16(%rsp),%xmm3
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+
+       xorps   32(%rsp),%xmm4
+       movups  %xmm2,0(%rsi)
+       xorps   48(%rsp),%xmm5
+       movups  %xmm3,16(%rsi)
+       xorps   64(%rsp),%xmm6
+       movups  %xmm4,32(%rsi)
+       xorps   80(%rsp),%xmm7
+       movups  %xmm5,48(%rsi)
+       movl    %r10d,%eax
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       leaq    96(%rsi),%rsi
+       subq    $96,%rdx
+       jnc     .Lxts_enc_grandloop
+
+       leal    3(%rax,%rax,1),%eax
+       movq    %r11,%rcx
+       movl    %eax,%r10d
+
+.Lxts_enc_short:
+       addq    $96,%rdx
+       jz      .Lxts_enc_done
+
+       cmpq    $32,%rdx
+       jb      .Lxts_enc_one
+       je      .Lxts_enc_two
+
+       cmpq    $64,%rdx
+       jb      .Lxts_enc_three
+       je      .Lxts_enc_four
+
+       pshufd  $19,%xmm14,%xmm9
+       movdqa  %xmm15,%xmm14
+       paddq   %xmm15,%xmm15
+       movdqu  (%rdi),%xmm2
+       pand    %xmm8,%xmm9
+       movdqu  16(%rdi),%xmm3
+       pxor    %xmm9,%xmm15
+
+       movdqu  32(%rdi),%xmm4
+       pxor    %xmm10,%xmm2
+       movdqu  48(%rdi),%xmm5
+       pxor    %xmm11,%xmm3
+       movdqu  64(%rdi),%xmm6
+       leaq    80(%rdi),%rdi
+       pxor    %xmm12,%xmm4
+       pxor    %xmm13,%xmm5
+       pxor    %xmm14,%xmm6
+
+       call    _aesni_encrypt6
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm15,%xmm10
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+       movdqu  %xmm2,(%rsi)
+       xorps   %xmm13,%xmm5
+       movdqu  %xmm3,16(%rsi)
+       xorps   %xmm14,%xmm6
+       movdqu  %xmm4,32(%rsi)
+       movdqu  %xmm5,48(%rsi)
+       movdqu  %xmm6,64(%rsi)
+       leaq    80(%rsi),%rsi
+       jmp     .Lxts_enc_done
+
+.align 16
+.Lxts_enc_one:
+       movups  (%rdi),%xmm2
+       leaq    16(%rdi),%rdi
+       xorps   %xmm10,%xmm2
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_enc1_9:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_enc1_9    
+.byte  102,15,56,221,209
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm11,%xmm10
+       movups  %xmm2,(%rsi)
+       leaq    16(%rsi),%rsi
+       jmp     .Lxts_enc_done
+
+.align 16
+.Lxts_enc_two:
+       movups  (%rdi),%xmm2
+       movups  16(%rdi),%xmm3
+       leaq    32(%rdi),%rdi
+       xorps   %xmm10,%xmm2
+       xorps   %xmm11,%xmm3
+
+       call    _aesni_encrypt3
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm12,%xmm10
+       xorps   %xmm11,%xmm3
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       leaq    32(%rsi),%rsi
+       jmp     .Lxts_enc_done
+
+.align 16
+.Lxts_enc_three:
+       movups  (%rdi),%xmm2
+       movups  16(%rdi),%xmm3
+       movups  32(%rdi),%xmm4
+       leaq    48(%rdi),%rdi
+       xorps   %xmm10,%xmm2
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+
+       call    _aesni_encrypt3
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm13,%xmm10
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       leaq    48(%rsi),%rsi
+       jmp     .Lxts_enc_done
+
+.align 16
+.Lxts_enc_four:
+       movups  (%rdi),%xmm2
+       movups  16(%rdi),%xmm3
+       movups  32(%rdi),%xmm4
+       xorps   %xmm10,%xmm2
+       movups  48(%rdi),%xmm5
+       leaq    64(%rdi),%rdi
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+       xorps   %xmm13,%xmm5
+
+       call    _aesni_encrypt4
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm15,%xmm10
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+       movups  %xmm2,(%rsi)
+       xorps   %xmm13,%xmm5
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       leaq    64(%rsi),%rsi
+       jmp     .Lxts_enc_done
+
+.align 16
+.Lxts_enc_done:
+       andq    $15,%r9
+       jz      .Lxts_enc_ret
+       movq    %r9,%rdx
+
+.Lxts_enc_steal:
+       movzbl  (%rdi),%eax
+       movzbl  -16(%rsi),%ecx
+       leaq    1(%rdi),%rdi
+       movb    %al,-16(%rsi)
+       movb    %cl,0(%rsi)
+       leaq    1(%rsi),%rsi
+       subq    $1,%rdx
+       jnz     .Lxts_enc_steal
+
+       subq    %r9,%rsi
+       movq    %r11,%rcx
+       movl    %r10d,%eax
+
+       movups  -16(%rsi),%xmm2
+       xorps   %xmm10,%xmm2
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_enc1_10:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_enc1_10   
+.byte  102,15,56,221,209
+       xorps   %xmm10,%xmm2
+       movups  %xmm2,-16(%rsi)
+
+.Lxts_enc_ret:
+       leaq    104(%rsp),%rsp
+.Lxts_enc_epilogue:
+       .byte   0xf3,0xc3
+.size  aesni_xts_encrypt,.-aesni_xts_encrypt
+.globl aesni_xts_decrypt
+.type  aesni_xts_decrypt,@function
+.align 16
+aesni_xts_decrypt:
+       leaq    -104(%rsp),%rsp
+       movups  (%r9),%xmm15
+       movl    240(%r8),%eax
+       movl    240(%rcx),%r10d
+       movups  (%r8),%xmm0
+       movups  16(%r8),%xmm1
+       leaq    32(%r8),%r8
+       xorps   %xmm0,%xmm15
+.Loop_enc1_11:
+.byte  102,68,15,56,220,249
+       decl    %eax
+       movups  (%r8),%xmm1
+       leaq    16(%r8),%r8
+       jnz     .Loop_enc1_11   
+.byte  102,68,15,56,221,249
+       xorl    %eax,%eax
+       testq   $15,%rdx
+       setnz   %al
+       shlq    $4,%rax
+       subq    %rax,%rdx
+
+       movq    %rcx,%r11
+       movl    %r10d,%eax
+       movq    %rdx,%r9
+       andq    $-16,%rdx
+
+       movdqa  .Lxts_magic(%rip),%xmm8
+       pxor    %xmm14,%xmm14
+       pcmpgtd %xmm15,%xmm14
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm10
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm11
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm12
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm13
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm9
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+       subq    $96,%rdx
+       jc      .Lxts_dec_short
+
+       shrl    $1,%eax
+       subl    $1,%eax
+       movl    %eax,%r10d
+       jmp     .Lxts_dec_grandloop
+
+.align 16
+.Lxts_dec_grandloop:
+       pshufd  $19,%xmm14,%xmm9
+       movdqa  %xmm15,%xmm14
+       paddq   %xmm15,%xmm15
+       movdqu  0(%rdi),%xmm2
+       pand    %xmm8,%xmm9
+       movdqu  16(%rdi),%xmm3
+       pxor    %xmm9,%xmm15
+
+       movdqu  32(%rdi),%xmm4
+       pxor    %xmm10,%xmm2
+       movdqu  48(%rdi),%xmm5
+       pxor    %xmm11,%xmm3
+       movdqu  64(%rdi),%xmm6
+       pxor    %xmm12,%xmm4
+       movdqu  80(%rdi),%xmm7
+       leaq    96(%rdi),%rdi
+       pxor    %xmm13,%xmm5
+       movups  (%r11),%xmm0
+       pxor    %xmm14,%xmm6
+       pxor    %xmm15,%xmm7
+
+
+
+       movups  16(%r11),%xmm1
+       pxor    %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+       movdqa  %xmm10,0(%rsp)
+.byte  102,15,56,222,209
+       leaq    32(%r11),%rcx
+       pxor    %xmm0,%xmm4
+       movdqa  %xmm11,16(%rsp)
+.byte  102,15,56,222,217
+       pxor    %xmm0,%xmm5
+       movdqa  %xmm12,32(%rsp)
+.byte  102,15,56,222,225
+       pxor    %xmm0,%xmm6
+       movdqa  %xmm13,48(%rsp)
+.byte  102,15,56,222,233
+       pxor    %xmm0,%xmm7
+       movups  (%rcx),%xmm0
+       decl    %eax
+       movdqa  %xmm14,64(%rsp)
+.byte  102,15,56,222,241
+       movdqa  %xmm15,80(%rsp)
+.byte  102,15,56,222,249
+       pxor    %xmm14,%xmm14
+       pcmpgtd %xmm15,%xmm14
+       jmp     .Lxts_dec_loop6_enter
+
+.align 16
+.Lxts_dec_loop6:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %eax
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.Lxts_dec_loop6_enter:
+       movups  16(%rcx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leaq    32(%rcx),%rcx
+.byte  102,15,56,222,224
+.byte  102,15,56,222,232
+.byte  102,15,56,222,240
+.byte  102,15,56,222,248
+       movups  (%rcx),%xmm0
+       jnz     .Lxts_dec_loop6
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,222,209
+       pand    %xmm8,%xmm9
+.byte  102,15,56,222,217
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,222,225
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+       movups  16(%rcx),%xmm1
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm10
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,222,208
+       pand    %xmm8,%xmm9
+.byte  102,15,56,222,216
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,222,224
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,222,232
+.byte  102,15,56,222,240
+.byte  102,15,56,222,248
+       movups  32(%rcx),%xmm0
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm11
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,222,209
+       pand    %xmm8,%xmm9
+.byte  102,15,56,222,217
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,222,225
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm12
+       paddq   %xmm15,%xmm15
+.byte  102,15,56,223,208
+       pand    %xmm8,%xmm9
+.byte  102,15,56,223,216
+       pcmpgtd %xmm15,%xmm14
+.byte  102,15,56,223,224
+       pxor    %xmm9,%xmm15
+.byte  102,15,56,223,232
+.byte  102,15,56,223,240
+.byte  102,15,56,223,248
+
+       pshufd  $19,%xmm14,%xmm9
+       pxor    %xmm14,%xmm14
+       movdqa  %xmm15,%xmm13
+       paddq   %xmm15,%xmm15
+       xorps   0(%rsp),%xmm2
+       pand    %xmm8,%xmm9
+       xorps   16(%rsp),%xmm3
+       pcmpgtd %xmm15,%xmm14
+       pxor    %xmm9,%xmm15
+
+       xorps   32(%rsp),%xmm4
+       movups  %xmm2,0(%rsi)
+       xorps   48(%rsp),%xmm5
+       movups  %xmm3,16(%rsi)
+       xorps   64(%rsp),%xmm6
+       movups  %xmm4,32(%rsi)
+       xorps   80(%rsp),%xmm7
+       movups  %xmm5,48(%rsi)
+       movl    %r10d,%eax
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       leaq    96(%rsi),%rsi
+       subq    $96,%rdx
+       jnc     .Lxts_dec_grandloop
+
+       leal    3(%rax,%rax,1),%eax
+       movq    %r11,%rcx
+       movl    %eax,%r10d
+
+.Lxts_dec_short:
+       addq    $96,%rdx
+       jz      .Lxts_dec_done
+
+       cmpq    $32,%rdx
+       jb      .Lxts_dec_one
+       je      .Lxts_dec_two
+
+       cmpq    $64,%rdx
+       jb      .Lxts_dec_three
+       je      .Lxts_dec_four
+
+       pshufd  $19,%xmm14,%xmm9
+       movdqa  %xmm15,%xmm14
+       paddq   %xmm15,%xmm15
+       movdqu  (%rdi),%xmm2
+       pand    %xmm8,%xmm9
+       movdqu  16(%rdi),%xmm3
+       pxor    %xmm9,%xmm15
+
+       movdqu  32(%rdi),%xmm4
+       pxor    %xmm10,%xmm2
+       movdqu  48(%rdi),%xmm5
+       pxor    %xmm11,%xmm3
+       movdqu  64(%rdi),%xmm6
+       leaq    80(%rdi),%rdi
+       pxor    %xmm12,%xmm4
+       pxor    %xmm13,%xmm5
+       pxor    %xmm14,%xmm6
+
+       call    _aesni_decrypt6
+
+       xorps   %xmm10,%xmm2
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+       movdqu  %xmm2,(%rsi)
+       xorps   %xmm13,%xmm5
+       movdqu  %xmm3,16(%rsi)
+       xorps   %xmm14,%xmm6
+       movdqu  %xmm4,32(%rsi)
+       pxor    %xmm14,%xmm14
+       movdqu  %xmm5,48(%rsi)
+       pcmpgtd %xmm15,%xmm14
+       movdqu  %xmm6,64(%rsi)
+       leaq    80(%rsi),%rsi
+       pshufd  $19,%xmm14,%xmm11
+       andq    $15,%r9
+       jz      .Lxts_dec_ret
+
+       movdqa  %xmm15,%xmm10
+       paddq   %xmm15,%xmm15
+       pand    %xmm8,%xmm11
+       pxor    %xmm15,%xmm11
+       jmp     .Lxts_dec_done2
+
+.align 16
+.Lxts_dec_one:
+       movups  (%rdi),%xmm2
+       leaq    16(%rdi),%rdi
+       xorps   %xmm10,%xmm2
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_dec1_12:
+.byte  102,15,56,222,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_dec1_12   
+.byte  102,15,56,223,209
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm11,%xmm10
+       movups  %xmm2,(%rsi)
+       movdqa  %xmm12,%xmm11
+       leaq    16(%rsi),%rsi
+       jmp     .Lxts_dec_done
+
+.align 16
+.Lxts_dec_two:
+       movups  (%rdi),%xmm2
+       movups  16(%rdi),%xmm3
+       leaq    32(%rdi),%rdi
+       xorps   %xmm10,%xmm2
+       xorps   %xmm11,%xmm3
+
+       call    _aesni_decrypt3
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm12,%xmm10
+       xorps   %xmm11,%xmm3
+       movdqa  %xmm13,%xmm11
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       leaq    32(%rsi),%rsi
+       jmp     .Lxts_dec_done
+
+.align 16
+.Lxts_dec_three:
+       movups  (%rdi),%xmm2
+       movups  16(%rdi),%xmm3
+       movups  32(%rdi),%xmm4
+       leaq    48(%rdi),%rdi
+       xorps   %xmm10,%xmm2
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+
+       call    _aesni_decrypt3
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm13,%xmm10
+       xorps   %xmm11,%xmm3
+       movdqa  %xmm15,%xmm11
+       xorps   %xmm12,%xmm4
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       leaq    48(%rsi),%rsi
+       jmp     .Lxts_dec_done
+
+.align 16
+.Lxts_dec_four:
+       pshufd  $19,%xmm14,%xmm9
+       movdqa  %xmm15,%xmm14
+       paddq   %xmm15,%xmm15
+       movups  (%rdi),%xmm2
+       pand    %xmm8,%xmm9
+       movups  16(%rdi),%xmm3
+       pxor    %xmm9,%xmm15
+
+       movups  32(%rdi),%xmm4
+       xorps   %xmm10,%xmm2
+       movups  48(%rdi),%xmm5
+       leaq    64(%rdi),%rdi
+       xorps   %xmm11,%xmm3
+       xorps   %xmm12,%xmm4
+       xorps   %xmm13,%xmm5
+
+       call    _aesni_decrypt4
+
+       xorps   %xmm10,%xmm2
+       movdqa  %xmm14,%xmm10
+       xorps   %xmm11,%xmm3
+       movdqa  %xmm15,%xmm11
+       xorps   %xmm12,%xmm4
+       movups  %xmm2,(%rsi)
+       xorps   %xmm13,%xmm5
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       leaq    64(%rsi),%rsi
+       jmp     .Lxts_dec_done
+
+.align 16
+.Lxts_dec_done:
+       andq    $15,%r9
+       jz      .Lxts_dec_ret
+.Lxts_dec_done2:
+       movq    %r9,%rdx
+       movq    %r11,%rcx
+       movl    %r10d,%eax
+
+       movups  (%rdi),%xmm2
+       xorps   %xmm11,%xmm2
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_dec1_13:
+.byte  102,15,56,222,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_dec1_13   
+.byte  102,15,56,223,209
+       xorps   %xmm11,%xmm2
+       movups  %xmm2,(%rsi)
+
+.Lxts_dec_steal:
+       movzbl  16(%rdi),%eax
+       movzbl  (%rsi),%ecx
+       leaq    1(%rdi),%rdi
+       movb    %al,(%rsi)
+       movb    %cl,16(%rsi)
+       leaq    1(%rsi),%rsi
+       subq    $1,%rdx
+       jnz     .Lxts_dec_steal
+
+       subq    %r9,%rsi
+       movq    %r11,%rcx
+       movl    %r10d,%eax
+
+       movups  (%rsi),%xmm2
+       xorps   %xmm10,%xmm2
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_dec1_14:
+.byte  102,15,56,222,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_dec1_14   
+.byte  102,15,56,223,209
+       xorps   %xmm10,%xmm2
+       movups  %xmm2,(%rsi)
+
+.Lxts_dec_ret:
+       leaq    104(%rsp),%rsp
+.Lxts_dec_epilogue:
+       .byte   0xf3,0xc3
+.size  aesni_xts_decrypt,.-aesni_xts_decrypt
+.globl aesni_cbc_encrypt
+.type  aesni_cbc_encrypt,@function
+.align 16
+aesni_cbc_encrypt:
+       testq   %rdx,%rdx
+       jz      .Lcbc_ret
+
+       movl    240(%rcx),%r10d
+       movq    %rcx,%r11
+       testl   %r9d,%r9d
+       jz      .Lcbc_decrypt
+
+       movups  (%r8),%xmm2
+       movl    %r10d,%eax
+       cmpq    $16,%rdx
+       jb      .Lcbc_enc_tail
+       subq    $16,%rdx
+       jmp     .Lcbc_enc_loop
+.align 16
+.Lcbc_enc_loop:
+       movups  (%rdi),%xmm3
+       leaq    16(%rdi),%rdi
+
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       xorps   %xmm0,%xmm3
+       leaq    32(%rcx),%rcx
+       xorps   %xmm3,%xmm2
+.Loop_enc1_15:
+.byte  102,15,56,220,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_enc1_15   
+.byte  102,15,56,221,209
+       movl    %r10d,%eax
+       movq    %r11,%rcx
+       movups  %xmm2,0(%rsi)
+       leaq    16(%rsi),%rsi
+       subq    $16,%rdx
+       jnc     .Lcbc_enc_loop
+       addq    $16,%rdx
+       jnz     .Lcbc_enc_tail
+       movups  %xmm2,(%r8)
+       jmp     .Lcbc_ret
+
+.Lcbc_enc_tail:
+       movq    %rdx,%rcx
+       xchgq   %rdi,%rsi
+.long  0x9066A4F3      
+       movl    $16,%ecx
+       subq    %rdx,%rcx
+       xorl    %eax,%eax
+.long  0x9066AAF3      
+       leaq    -16(%rdi),%rdi
+       movl    %r10d,%eax
+       movq    %rdi,%rsi
+       movq    %r11,%rcx
+       xorq    %rdx,%rdx
+       jmp     .Lcbc_enc_loop  
+
+.align 16
+.Lcbc_decrypt:
+       movups  (%r8),%xmm9
+       movl    %r10d,%eax
+       cmpq    $112,%rdx
+       jbe     .Lcbc_dec_tail
+       shrl    $1,%r10d
+       subq    $112,%rdx
+       movl    %r10d,%eax
+       movaps  %xmm9,-24(%rsp)
+       jmp     .Lcbc_dec_loop8_enter
+.align 16
+.Lcbc_dec_loop8:
+       movaps  %xmm0,-24(%rsp)
+       movups  %xmm9,(%rsi)
+       leaq    16(%rsi),%rsi
+.Lcbc_dec_loop8_enter:
+       movups  (%rcx),%xmm0
+       movups  (%rdi),%xmm2
+       movups  16(%rdi),%xmm3
+       movups  16(%rcx),%xmm1
+
+       leaq    32(%rcx),%rcx
+       movdqu  32(%rdi),%xmm4
+       xorps   %xmm0,%xmm2
+       movdqu  48(%rdi),%xmm5
+       xorps   %xmm0,%xmm3
+       movdqu  64(%rdi),%xmm6
+.byte  102,15,56,222,209
+       pxor    %xmm0,%xmm4
+       movdqu  80(%rdi),%xmm7
+.byte  102,15,56,222,217
+       pxor    %xmm0,%xmm5
+       movdqu  96(%rdi),%xmm8
+.byte  102,15,56,222,225
+       pxor    %xmm0,%xmm6
+       movdqu  112(%rdi),%xmm9
+.byte  102,15,56,222,233
+       pxor    %xmm0,%xmm7
+       decl    %eax
+.byte  102,15,56,222,241
+       pxor    %xmm0,%xmm8
+.byte  102,15,56,222,249
+       pxor    %xmm0,%xmm9
+       movups  (%rcx),%xmm0
+.byte  102,68,15,56,222,193
+.byte  102,68,15,56,222,201
+       movups  16(%rcx),%xmm1
+
+       call    .Ldec_loop8_enter
+
+       movups  (%rdi),%xmm1
+       movups  16(%rdi),%xmm0
+       xorps   -24(%rsp),%xmm2
+       xorps   %xmm1,%xmm3
+       movups  32(%rdi),%xmm1
+       xorps   %xmm0,%xmm4
+       movups  48(%rdi),%xmm0
+       xorps   %xmm1,%xmm5
+       movups  64(%rdi),%xmm1
+       xorps   %xmm0,%xmm6
+       movups  80(%rdi),%xmm0
+       xorps   %xmm1,%xmm7
+       movups  96(%rdi),%xmm1
+       xorps   %xmm0,%xmm8
+       movups  112(%rdi),%xmm0
+       xorps   %xmm1,%xmm9
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movl    %r10d,%eax
+       movups  %xmm6,64(%rsi)
+       movq    %r11,%rcx
+       movups  %xmm7,80(%rsi)
+       leaq    128(%rdi),%rdi
+       movups  %xmm8,96(%rsi)
+       leaq    112(%rsi),%rsi
+       subq    $128,%rdx
+       ja      .Lcbc_dec_loop8
+
+       movaps  %xmm9,%xmm2
+       movaps  %xmm0,%xmm9
+       addq    $112,%rdx
+       jle     .Lcbc_dec_tail_collected
+       movups  %xmm2,(%rsi)
+       leal    1(%r10,%r10,1),%eax
+       leaq    16(%rsi),%rsi
+.Lcbc_dec_tail:
+       movups  (%rdi),%xmm2
+       movaps  %xmm2,%xmm8
+       cmpq    $16,%rdx
+       jbe     .Lcbc_dec_one
+
+       movups  16(%rdi),%xmm3
+       movaps  %xmm3,%xmm7
+       cmpq    $32,%rdx
+       jbe     .Lcbc_dec_two
+
+       movups  32(%rdi),%xmm4
+       movaps  %xmm4,%xmm6
+       cmpq    $48,%rdx
+       jbe     .Lcbc_dec_three
+
+       movups  48(%rdi),%xmm5
+       cmpq    $64,%rdx
+       jbe     .Lcbc_dec_four
+
+       movups  64(%rdi),%xmm6
+       cmpq    $80,%rdx
+       jbe     .Lcbc_dec_five
+
+       movups  80(%rdi),%xmm7
+       cmpq    $96,%rdx
+       jbe     .Lcbc_dec_six
+
+       movups  96(%rdi),%xmm8
+       movaps  %xmm9,-24(%rsp)
+       call    _aesni_decrypt8
+       movups  (%rdi),%xmm1
+       movups  16(%rdi),%xmm0
+       xorps   -24(%rsp),%xmm2
+       xorps   %xmm1,%xmm3
+       movups  32(%rdi),%xmm1
+       xorps   %xmm0,%xmm4
+       movups  48(%rdi),%xmm0
+       xorps   %xmm1,%xmm5
+       movups  64(%rdi),%xmm1
+       xorps   %xmm0,%xmm6
+       movups  80(%rdi),%xmm0
+       xorps   %xmm1,%xmm7
+       movups  96(%rdi),%xmm9
+       xorps   %xmm0,%xmm8
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       movups  %xmm7,80(%rsi)
+       leaq    96(%rsi),%rsi
+       movaps  %xmm8,%xmm2
+       subq    $112,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.align 16
+.Lcbc_dec_one:
+       movups  (%rcx),%xmm0
+       movups  16(%rcx),%xmm1
+       leaq    32(%rcx),%rcx
+       xorps   %xmm0,%xmm2
+.Loop_dec1_16:
+.byte  102,15,56,222,209
+       decl    %eax
+       movups  (%rcx),%xmm1
+       leaq    16(%rcx),%rcx
+       jnz     .Loop_dec1_16   
+.byte  102,15,56,223,209
+       xorps   %xmm9,%xmm2
+       movaps  %xmm8,%xmm9
+       subq    $16,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.align 16
+.Lcbc_dec_two:
+       xorps   %xmm4,%xmm4
+       call    _aesni_decrypt3
+       xorps   %xmm9,%xmm2
+       xorps   %xmm8,%xmm3
+       movups  %xmm2,(%rsi)
+       movaps  %xmm7,%xmm9
+       movaps  %xmm3,%xmm2
+       leaq    16(%rsi),%rsi
+       subq    $32,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.align 16
+.Lcbc_dec_three:
+       call    _aesni_decrypt3
+       xorps   %xmm9,%xmm2
+       xorps   %xmm8,%xmm3
+       movups  %xmm2,(%rsi)
+       xorps   %xmm7,%xmm4
+       movups  %xmm3,16(%rsi)
+       movaps  %xmm6,%xmm9
+       movaps  %xmm4,%xmm2
+       leaq    32(%rsi),%rsi
+       subq    $48,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.align 16
+.Lcbc_dec_four:
+       call    _aesni_decrypt4
+       xorps   %xmm9,%xmm2
+       movups  48(%rdi),%xmm9
+       xorps   %xmm8,%xmm3
+       movups  %xmm2,(%rsi)
+       xorps   %xmm7,%xmm4
+       movups  %xmm3,16(%rsi)
+       xorps   %xmm6,%xmm5
+       movups  %xmm4,32(%rsi)
+       movaps  %xmm5,%xmm2
+       leaq    48(%rsi),%rsi
+       subq    $64,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.align 16
+.Lcbc_dec_five:
+       xorps   %xmm7,%xmm7
+       call    _aesni_decrypt6
+       movups  16(%rdi),%xmm1
+       movups  32(%rdi),%xmm0
+       xorps   %xmm9,%xmm2
+       xorps   %xmm8,%xmm3
+       xorps   %xmm1,%xmm4
+       movups  48(%rdi),%xmm1
+       xorps   %xmm0,%xmm5
+       movups  64(%rdi),%xmm9
+       xorps   %xmm1,%xmm6
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       leaq    64(%rsi),%rsi
+       movaps  %xmm6,%xmm2
+       subq    $80,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.align 16
+.Lcbc_dec_six:
+       call    _aesni_decrypt6
+       movups  16(%rdi),%xmm1
+       movups  32(%rdi),%xmm0
+       xorps   %xmm9,%xmm2
+       xorps   %xmm8,%xmm3
+       xorps   %xmm1,%xmm4
+       movups  48(%rdi),%xmm1
+       xorps   %xmm0,%xmm5
+       movups  64(%rdi),%xmm0
+       xorps   %xmm1,%xmm6
+       movups  80(%rdi),%xmm9
+       xorps   %xmm0,%xmm7
+       movups  %xmm2,(%rsi)
+       movups  %xmm3,16(%rsi)
+       movups  %xmm4,32(%rsi)
+       movups  %xmm5,48(%rsi)
+       movups  %xmm6,64(%rsi)
+       leaq    80(%rsi),%rsi
+       movaps  %xmm7,%xmm2
+       subq    $96,%rdx
+       jmp     .Lcbc_dec_tail_collected
+.align 16
+.Lcbc_dec_tail_collected:
+       andq    $15,%rdx
+       movups  %xmm9,(%r8)
+       jnz     .Lcbc_dec_tail_partial
+       movups  %xmm2,(%rsi)
+       jmp     .Lcbc_dec_ret
+.align 16
+.Lcbc_dec_tail_partial:
+       movaps  %xmm2,-24(%rsp)
+       movq    $16,%rcx
+       movq    %rsi,%rdi
+       subq    %rdx,%rcx
+       leaq    -24(%rsp),%rsi
+.long  0x9066A4F3      
+
+.Lcbc_dec_ret:
+.Lcbc_ret:
+       .byte   0xf3,0xc3
+.size  aesni_cbc_encrypt,.-aesni_cbc_encrypt
+.globl aesni_set_decrypt_key
+.type  aesni_set_decrypt_key,@function
+.align 16
+aesni_set_decrypt_key:
+.byte  0x48,0x83,0xEC,0x08     
+       call    __aesni_set_encrypt_key
+       shll    $4,%esi
+       testl   %eax,%eax
+       jnz     .Ldec_key_ret
+       leaq    16(%rdx,%rsi,1),%rdi
+
+       movups  (%rdx),%xmm0
+       movups  (%rdi),%xmm1
+       movups  %xmm0,(%rdi)
+       movups  %xmm1,(%rdx)
+       leaq    16(%rdx),%rdx
+       leaq    -16(%rdi),%rdi
+
+.Ldec_key_inverse:
+       movups  (%rdx),%xmm0
+       movups  (%rdi),%xmm1
+.byte  102,15,56,219,192
+.byte  102,15,56,219,201
+       leaq    16(%rdx),%rdx
+       leaq    -16(%rdi),%rdi
+       movups  %xmm0,16(%rdi)
+       movups  %xmm1,-16(%rdx)
+       cmpq    %rdx,%rdi
+       ja      .Ldec_key_inverse
+
+       movups  (%rdx),%xmm0
+.byte  102,15,56,219,192
+       movups  %xmm0,(%rdi)
+.Ldec_key_ret:
+       addq    $8,%rsp
+       .byte   0xf3,0xc3
+.LSEH_end_set_decrypt_key:
+.size  aesni_set_decrypt_key,.-aesni_set_decrypt_key
+.globl aesni_set_encrypt_key
+.type  aesni_set_encrypt_key,@function
+.align 16
+aesni_set_encrypt_key:
+__aesni_set_encrypt_key:
+.byte  0x48,0x83,0xEC,0x08     
+       movq    $-1,%rax
+       testq   %rdi,%rdi
+       jz      .Lenc_key_ret
+       testq   %rdx,%rdx
+       jz      .Lenc_key_ret
+
+       movups  (%rdi),%xmm0
+       xorps   %xmm4,%xmm4
+       leaq    16(%rdx),%rax
+       cmpl    $256,%esi
+       je      .L14rounds
+       cmpl    $192,%esi
+       je      .L12rounds
+       cmpl    $128,%esi
+       jne     .Lbad_keybits
+
+.L10rounds:
+       movl    $9,%esi
+       movups  %xmm0,(%rdx)
+.byte  102,15,58,223,200,1
+       call    .Lkey_expansion_128_cold
+.byte  102,15,58,223,200,2
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,4
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,8
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,16
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,32
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,64
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,128
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,27
+       call    .Lkey_expansion_128
+.byte  102,15,58,223,200,54
+       call    .Lkey_expansion_128
+       movups  %xmm0,(%rax)
+       movl    %esi,80(%rax)
+       xorl    %eax,%eax
+       jmp     .Lenc_key_ret
+
+.align 16
+.L12rounds:
+       movq    16(%rdi),%xmm2
+       movl    $11,%esi
+       movups  %xmm0,(%rdx)
+.byte  102,15,58,223,202,1
+       call    .Lkey_expansion_192a_cold
+.byte  102,15,58,223,202,2
+       call    .Lkey_expansion_192b
+.byte  102,15,58,223,202,4
+       call    .Lkey_expansion_192a
+.byte  102,15,58,223,202,8
+       call    .Lkey_expansion_192b
+.byte  102,15,58,223,202,16
+       call    .Lkey_expansion_192a
+.byte  102,15,58,223,202,32
+       call    .Lkey_expansion_192b
+.byte  102,15,58,223,202,64
+       call    .Lkey_expansion_192a
+.byte  102,15,58,223,202,128
+       call    .Lkey_expansion_192b
+       movups  %xmm0,(%rax)
+       movl    %esi,48(%rax)
+       xorq    %rax,%rax
+       jmp     .Lenc_key_ret
+
+.align 16
+.L14rounds:
+       movups  16(%rdi),%xmm2
+       movl    $13,%esi
+       leaq    16(%rax),%rax
+       movups  %xmm0,(%rdx)
+       movups  %xmm2,16(%rdx)
+.byte  102,15,58,223,202,1
+       call    .Lkey_expansion_256a_cold
+.byte  102,15,58,223,200,1
+       call    .Lkey_expansion_256b
+.byte  102,15,58,223,202,2
+       call    .Lkey_expansion_256a
+.byte  102,15,58,223,200,2
+       call    .Lkey_expansion_256b
+.byte  102,15,58,223,202,4
+       call    .Lkey_expansion_256a
+.byte  102,15,58,223,200,4
+       call    .Lkey_expansion_256b
+.byte  102,15,58,223,202,8
+       call    .Lkey_expansion_256a
+.byte  102,15,58,223,200,8
+       call    .Lkey_expansion_256b
+.byte  102,15,58,223,202,16
+       call    .Lkey_expansion_256a
+.byte  102,15,58,223,200,16
+       call    .Lkey_expansion_256b
+.byte  102,15,58,223,202,32
+       call    .Lkey_expansion_256a
+.byte  102,15,58,223,200,32
+       call    .Lkey_expansion_256b
+.byte  102,15,58,223,202,64
+       call    .Lkey_expansion_256a
+       movups  %xmm0,(%rax)
+       movl    %esi,16(%rax)
+       xorq    %rax,%rax
+       jmp     .Lenc_key_ret
+
+.align 16
+.Lbad_keybits:
+       movq    $-2,%rax
+.Lenc_key_ret:
+       addq    $8,%rsp
+       .byte   0xf3,0xc3
+.LSEH_end_set_encrypt_key:
+
+.align 16
+.Lkey_expansion_128:
+       movups  %xmm0,(%rax)
+       leaq    16(%rax),%rax
+.Lkey_expansion_128_cold:
+       shufps  $16,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $140,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $255,%xmm1,%xmm1
+       xorps   %xmm1,%xmm0
+       .byte   0xf3,0xc3
+
+.align 16
+.Lkey_expansion_192a:
+       movups  %xmm0,(%rax)
+       leaq    16(%rax),%rax
+.Lkey_expansion_192a_cold:
+       movaps  %xmm2,%xmm5
+.Lkey_expansion_192b_warm:
+       shufps  $16,%xmm0,%xmm4
+       movdqa  %xmm2,%xmm3
+       xorps   %xmm4,%xmm0
+       shufps  $140,%xmm0,%xmm4
+       pslldq  $4,%xmm3
+       xorps   %xmm4,%xmm0
+       pshufd  $85,%xmm1,%xmm1
+       pxor    %xmm3,%xmm2
+       pxor    %xmm1,%xmm0
+       pshufd  $255,%xmm0,%xmm3
+       pxor    %xmm3,%xmm2
+       .byte   0xf3,0xc3
+
+.align 16
+.Lkey_expansion_192b:
+       movaps  %xmm0,%xmm3
+       shufps  $68,%xmm0,%xmm5
+       movups  %xmm5,(%rax)
+       shufps  $78,%xmm2,%xmm3
+       movups  %xmm3,16(%rax)
+       leaq    32(%rax),%rax
+       jmp     .Lkey_expansion_192b_warm
+
+.align 16
+.Lkey_expansion_256a:
+       movups  %xmm2,(%rax)
+       leaq    16(%rax),%rax
+.Lkey_expansion_256a_cold:
+       shufps  $16,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $140,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $255,%xmm1,%xmm1
+       xorps   %xmm1,%xmm0
+       .byte   0xf3,0xc3
+
+.align 16
+.Lkey_expansion_256b:
+       movups  %xmm0,(%rax)
+       leaq    16(%rax),%rax
+
+       shufps  $16,%xmm2,%xmm4
+       xorps   %xmm4,%xmm2
+       shufps  $140,%xmm2,%xmm4
+       xorps   %xmm4,%xmm2
+       shufps  $170,%xmm1,%xmm1
+       xorps   %xmm1,%xmm2
+       .byte   0xf3,0xc3
+.size  aesni_set_encrypt_key,.-aesni_set_encrypt_key
+.size  __aesni_set_encrypt_key,.-__aesni_set_encrypt_key
+.align 64
+.Lbswap_mask:
+.byte  15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
+.Lincrement32:
+.long  6,6,6,0
+.Lincrement64:
+.long  1,0,0,0
+.Lxts_magic:
+.long  0x87,0,1,0
+
+.byte  
65,69,83,32,102,111,114,32,73,110,116,101,108,32,65,69,83,45,78,73,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
+.align 64
+
+#if defined(__ELF__)
+.section .note.GNU-stack,"",%progbits
+#endif
+
diff --git a/lib/accelerated/x86/asm/appro-aes-x86.s 
b/lib/accelerated/x86/asm/appro-aes-x86.s
new file mode 100644
index 0000000..b1ce9bc
--- /dev/null
+++ b/lib/accelerated/x86/asm/appro-aes-x86.s
@@ -0,0 +1,2186 @@
+# Copyright (c) 2011, Andy Polyakov by <address@hidden>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 
+#     * Redistributions of source code must retain copyright notices,
+#      this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+#
+#     * Neither the name of the Andy Polyakov nor the names of its
+#      copyright holder and contributors may be used to endorse or
+#      promote products derived from this software without specific
+#      prior written permission.
+#
+# ALTERNATIVELY, provided that this notice is retained in full, this
+# product may be distributed under the terms of the GNU General Public
+# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+# those given above.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.file  "aesni-x86.s"
+.text
+.globl aesni_encrypt
+.type  aesni_encrypt,@function
+.align 16
+aesni_encrypt:
+.L_aesni_encrypt_begin:
+       movl    4(%esp),%eax
+       movl    12(%esp),%edx
+       movups  (%eax),%xmm2
+       movl    240(%edx),%ecx
+       movl    8(%esp),%eax
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L000enc1_loop_1:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L000enc1_loop_1
+.byte  102,15,56,221,209
+       movups  %xmm2,(%eax)
+       ret
+.size  aesni_encrypt,.-.L_aesni_encrypt_begin
+.globl aesni_decrypt
+.type  aesni_decrypt,@function
+.align 16
+aesni_decrypt:
+.L_aesni_decrypt_begin:
+       movl    4(%esp),%eax
+       movl    12(%esp),%edx
+       movups  (%eax),%xmm2
+       movl    240(%edx),%ecx
+       movl    8(%esp),%eax
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L001dec1_loop_2:
+.byte  102,15,56,222,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L001dec1_loop_2
+.byte  102,15,56,223,209
+       movups  %xmm2,(%eax)
+       ret
+.size  aesni_decrypt,.-.L_aesni_decrypt_begin
+.type  _aesni_encrypt3,@function
+.align 16
+_aesni_encrypt3:
+       movups  (%edx),%xmm0
+       shrl    $1,%ecx
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+       pxor    %xmm0,%xmm4
+       movups  (%edx),%xmm0
+.L002enc3_loop:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %ecx
+.byte  102,15,56,220,225
+       movups  16(%edx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leal    32(%edx),%edx
+.byte  102,15,56,220,224
+       movups  (%edx),%xmm0
+       jnz     .L002enc3_loop
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+       ret
+.size  _aesni_encrypt3,.-_aesni_encrypt3
+.type  _aesni_decrypt3,@function
+.align 16
+_aesni_decrypt3:
+       movups  (%edx),%xmm0
+       shrl    $1,%ecx
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+       pxor    %xmm0,%xmm4
+       movups  (%edx),%xmm0
+.L003dec3_loop:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %ecx
+.byte  102,15,56,222,225
+       movups  16(%edx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leal    32(%edx),%edx
+.byte  102,15,56,222,224
+       movups  (%edx),%xmm0
+       jnz     .L003dec3_loop
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+       ret
+.size  _aesni_decrypt3,.-_aesni_decrypt3
+.type  _aesni_encrypt4,@function
+.align 16
+_aesni_encrypt4:
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       shrl    $1,%ecx
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+       pxor    %xmm0,%xmm4
+       pxor    %xmm0,%xmm5
+       movups  (%edx),%xmm0
+.L004enc4_loop:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %ecx
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+       movups  16(%edx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leal    32(%edx),%edx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+       movups  (%edx),%xmm0
+       jnz     .L004enc4_loop
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+.byte  102,15,56,221,232
+       ret
+.size  _aesni_encrypt4,.-_aesni_encrypt4
+.type  _aesni_decrypt4,@function
+.align 16
+_aesni_decrypt4:
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       shrl    $1,%ecx
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+       pxor    %xmm0,%xmm4
+       pxor    %xmm0,%xmm5
+       movups  (%edx),%xmm0
+.L005dec4_loop:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %ecx
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+       movups  16(%edx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leal    32(%edx),%edx
+.byte  102,15,56,222,224
+.byte  102,15,56,222,232
+       movups  (%edx),%xmm0
+       jnz     .L005dec4_loop
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+.byte  102,15,56,223,232
+       ret
+.size  _aesni_decrypt4,.-_aesni_decrypt4
+.type  _aesni_encrypt6,@function
+.align 16
+_aesni_encrypt6:
+       movups  (%edx),%xmm0
+       shrl    $1,%ecx
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+.byte  102,15,56,220,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,220,217
+       pxor    %xmm0,%xmm5
+       decl    %ecx
+.byte  102,15,56,220,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+.byte  102,15,56,220,241
+       movups  (%edx),%xmm0
+.byte  102,15,56,220,249
+       jmp     .L_aesni_encrypt6_enter
+.align 16
+.L006enc6_loop:
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       decl    %ecx
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.align 16
+.L_aesni_encrypt6_enter:
+       movups  16(%edx),%xmm1
+.byte  102,15,56,220,208
+.byte  102,15,56,220,216
+       leal    32(%edx),%edx
+.byte  102,15,56,220,224
+.byte  102,15,56,220,232
+.byte  102,15,56,220,240
+.byte  102,15,56,220,248
+       movups  (%edx),%xmm0
+       jnz     .L006enc6_loop
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,220,225
+.byte  102,15,56,220,233
+.byte  102,15,56,220,241
+.byte  102,15,56,220,249
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+.byte  102,15,56,221,224
+.byte  102,15,56,221,232
+.byte  102,15,56,221,240
+.byte  102,15,56,221,248
+       ret
+.size  _aesni_encrypt6,.-_aesni_encrypt6
+.type  _aesni_decrypt6,@function
+.align 16
+_aesni_decrypt6:
+       movups  (%edx),%xmm0
+       shrl    $1,%ecx
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+.byte  102,15,56,222,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,222,217
+       pxor    %xmm0,%xmm5
+       decl    %ecx
+.byte  102,15,56,222,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,222,233
+       pxor    %xmm0,%xmm7
+.byte  102,15,56,222,241
+       movups  (%edx),%xmm0
+.byte  102,15,56,222,249
+       jmp     .L_aesni_decrypt6_enter
+.align 16
+.L007dec6_loop:
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+       decl    %ecx
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.align 16
+.L_aesni_decrypt6_enter:
+       movups  16(%edx),%xmm1
+.byte  102,15,56,222,208
+.byte  102,15,56,222,216
+       leal    32(%edx),%edx
+.byte  102,15,56,222,224
+.byte  102,15,56,222,232
+.byte  102,15,56,222,240
+.byte  102,15,56,222,248
+       movups  (%edx),%xmm0
+       jnz     .L007dec6_loop
+.byte  102,15,56,222,209
+.byte  102,15,56,222,217
+.byte  102,15,56,222,225
+.byte  102,15,56,222,233
+.byte  102,15,56,222,241
+.byte  102,15,56,222,249
+.byte  102,15,56,223,208
+.byte  102,15,56,223,216
+.byte  102,15,56,223,224
+.byte  102,15,56,223,232
+.byte  102,15,56,223,240
+.byte  102,15,56,223,248
+       ret
+.size  _aesni_decrypt6,.-_aesni_decrypt6
+.globl aesni_ecb_encrypt
+.type  aesni_ecb_encrypt,@function
+.align 16
+aesni_ecb_encrypt:
+.L_aesni_ecb_encrypt_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%esi
+       movl    24(%esp),%edi
+       movl    28(%esp),%eax
+       movl    32(%esp),%edx
+       movl    36(%esp),%ebx
+       andl    $-16,%eax
+       jz      .L008ecb_ret
+       movl    240(%edx),%ecx
+       testl   %ebx,%ebx
+       jz      .L009ecb_decrypt
+       movl    %edx,%ebp
+       movl    %ecx,%ebx
+       cmpl    $96,%eax
+       jb      .L010ecb_enc_tail
+       movdqu  (%esi),%xmm2
+       movdqu  16(%esi),%xmm3
+       movdqu  32(%esi),%xmm4
+       movdqu  48(%esi),%xmm5
+       movdqu  64(%esi),%xmm6
+       movdqu  80(%esi),%xmm7
+       leal    96(%esi),%esi
+       subl    $96,%eax
+       jmp     .L011ecb_enc_loop6_enter
+.align 16
+.L012ecb_enc_loop6:
+       movups  %xmm2,(%edi)
+       movdqu  (%esi),%xmm2
+       movups  %xmm3,16(%edi)
+       movdqu  16(%esi),%xmm3
+       movups  %xmm4,32(%edi)
+       movdqu  32(%esi),%xmm4
+       movups  %xmm5,48(%edi)
+       movdqu  48(%esi),%xmm5
+       movups  %xmm6,64(%edi)
+       movdqu  64(%esi),%xmm6
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       movdqu  80(%esi),%xmm7
+       leal    96(%esi),%esi
+.L011ecb_enc_loop6_enter:
+       call    _aesni_encrypt6
+       movl    %ebp,%edx
+       movl    %ebx,%ecx
+       subl    $96,%eax
+       jnc     .L012ecb_enc_loop6
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       addl    $96,%eax
+       jz      .L008ecb_ret
+.L010ecb_enc_tail:
+       movups  (%esi),%xmm2
+       cmpl    $32,%eax
+       jb      .L013ecb_enc_one
+       movups  16(%esi),%xmm3
+       je      .L014ecb_enc_two
+       movups  32(%esi),%xmm4
+       cmpl    $64,%eax
+       jb      .L015ecb_enc_three
+       movups  48(%esi),%xmm5
+       je      .L016ecb_enc_four
+       movups  64(%esi),%xmm6
+       xorps   %xmm7,%xmm7
+       call    _aesni_encrypt6
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L013ecb_enc_one:
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L017enc1_loop_3:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L017enc1_loop_3
+.byte  102,15,56,221,209
+       movups  %xmm2,(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L014ecb_enc_two:
+       xorps   %xmm4,%xmm4
+       call    _aesni_encrypt3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L015ecb_enc_three:
+       call    _aesni_encrypt3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L016ecb_enc_four:
+       call    _aesni_encrypt4
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L009ecb_decrypt:
+       movl    %edx,%ebp
+       movl    %ecx,%ebx
+       cmpl    $96,%eax
+       jb      .L018ecb_dec_tail
+       movdqu  (%esi),%xmm2
+       movdqu  16(%esi),%xmm3
+       movdqu  32(%esi),%xmm4
+       movdqu  48(%esi),%xmm5
+       movdqu  64(%esi),%xmm6
+       movdqu  80(%esi),%xmm7
+       leal    96(%esi),%esi
+       subl    $96,%eax
+       jmp     .L019ecb_dec_loop6_enter
+.align 16
+.L020ecb_dec_loop6:
+       movups  %xmm2,(%edi)
+       movdqu  (%esi),%xmm2
+       movups  %xmm3,16(%edi)
+       movdqu  16(%esi),%xmm3
+       movups  %xmm4,32(%edi)
+       movdqu  32(%esi),%xmm4
+       movups  %xmm5,48(%edi)
+       movdqu  48(%esi),%xmm5
+       movups  %xmm6,64(%edi)
+       movdqu  64(%esi),%xmm6
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       movdqu  80(%esi),%xmm7
+       leal    96(%esi),%esi
+.L019ecb_dec_loop6_enter:
+       call    _aesni_decrypt6
+       movl    %ebp,%edx
+       movl    %ebx,%ecx
+       subl    $96,%eax
+       jnc     .L020ecb_dec_loop6
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       addl    $96,%eax
+       jz      .L008ecb_ret
+.L018ecb_dec_tail:
+       movups  (%esi),%xmm2
+       cmpl    $32,%eax
+       jb      .L021ecb_dec_one
+       movups  16(%esi),%xmm3
+       je      .L022ecb_dec_two
+       movups  32(%esi),%xmm4
+       cmpl    $64,%eax
+       jb      .L023ecb_dec_three
+       movups  48(%esi),%xmm5
+       je      .L024ecb_dec_four
+       movups  64(%esi),%xmm6
+       xorps   %xmm7,%xmm7
+       call    _aesni_decrypt6
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L021ecb_dec_one:
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L025dec1_loop_4:
+.byte  102,15,56,222,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L025dec1_loop_4
+.byte  102,15,56,223,209
+       movups  %xmm2,(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L022ecb_dec_two:
+       xorps   %xmm4,%xmm4
+       call    _aesni_decrypt3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L023ecb_dec_three:
+       call    _aesni_decrypt3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       jmp     .L008ecb_ret
+.align 16
+.L024ecb_dec_four:
+       call    _aesni_decrypt4
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+.L008ecb_ret:
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.size  aesni_ecb_encrypt,.-.L_aesni_ecb_encrypt_begin
+.globl aesni_ccm64_encrypt_blocks
+.type  aesni_ccm64_encrypt_blocks,@function
+.align 16
+aesni_ccm64_encrypt_blocks:
+.L_aesni_ccm64_encrypt_blocks_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%esi
+       movl    24(%esp),%edi
+       movl    28(%esp),%eax
+       movl    32(%esp),%edx
+       movl    36(%esp),%ebx
+       movl    40(%esp),%ecx
+       movl    %esp,%ebp
+       subl    $60,%esp
+       andl    $-16,%esp
+       movl    %ebp,48(%esp)
+       movdqu  (%ebx),%xmm7
+       movdqu  (%ecx),%xmm3
+       movl    240(%edx),%ecx
+       movl    $202182159,(%esp)
+       movl    $134810123,4(%esp)
+       movl    $67438087,8(%esp)
+       movl    $66051,12(%esp)
+       movl    $1,%ebx
+       xorl    %ebp,%ebp
+       movl    %ebx,16(%esp)
+       movl    %ebp,20(%esp)
+       movl    %ebp,24(%esp)
+       movl    %ebp,28(%esp)
+       shrl    $1,%ecx
+       leal    (%edx),%ebp
+       movdqa  %xmm7,%xmm2
+       movl    %ecx,%ebx
+       movdqa  (%esp),%xmm5
+.L026ccm64_enc_outer:
+       movups  (%ebp),%xmm0
+       movl    %ebx,%ecx
+       movups  (%esi),%xmm6
+       xorps   %xmm0,%xmm2
+       movups  16(%ebp),%xmm1
+       xorps   %xmm6,%xmm0
+       leal    32(%ebp),%edx
+       xorps   %xmm0,%xmm3
+       movups  (%edx),%xmm0
+.L027ccm64_enc2_loop:
+.byte  102,15,56,220,209
+       decl    %ecx
+.byte  102,15,56,220,217
+       movups  16(%edx),%xmm1
+.byte  102,15,56,220,208
+       leal    32(%edx),%edx
+.byte  102,15,56,220,216
+       movups  (%edx),%xmm0
+       jnz     .L027ccm64_enc2_loop
+.byte  102,15,56,0,253
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+       paddq   16(%esp),%xmm7
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+       decl    %eax
+       leal    16(%esi),%esi
+       xorps   %xmm2,%xmm6
+       movdqa  %xmm7,%xmm2
+       movups  %xmm6,(%edi)
+       leal    16(%edi),%edi
+.byte  102,15,56,0,253
+       jnz     .L026ccm64_enc_outer
+       movl    48(%esp),%esp
+       movl    40(%esp),%edi
+       movups  %xmm3,(%edi)
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.size  aesni_ccm64_encrypt_blocks,.-.L_aesni_ccm64_encrypt_blocks_begin
+.globl aesni_ccm64_decrypt_blocks
+.type  aesni_ccm64_decrypt_blocks,@function
+.align 16
+aesni_ccm64_decrypt_blocks:
+.L_aesni_ccm64_decrypt_blocks_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%esi
+       movl    24(%esp),%edi
+       movl    28(%esp),%eax
+       movl    32(%esp),%edx
+       movl    36(%esp),%ebx
+       movl    40(%esp),%ecx
+       movl    %esp,%ebp
+       subl    $60,%esp
+       andl    $-16,%esp
+       movl    %ebp,48(%esp)
+       movdqu  (%ebx),%xmm7
+       movdqu  (%ecx),%xmm3
+       movl    240(%edx),%ecx
+       movl    $202182159,(%esp)
+       movl    $134810123,4(%esp)
+       movl    $67438087,8(%esp)
+       movl    $66051,12(%esp)
+       movl    $1,%ebx
+       xorl    %ebp,%ebp
+       movl    %ebx,16(%esp)
+       movl    %ebp,20(%esp)
+       movl    %ebp,24(%esp)
+       movl    %ebp,28(%esp)
+       movdqa  (%esp),%xmm5
+       movdqa  %xmm7,%xmm2
+       movl    %edx,%ebp
+       movl    %ecx,%ebx
+.byte  102,15,56,0,253
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L028enc1_loop_5:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L028enc1_loop_5
+.byte  102,15,56,221,209
+       movups  (%esi),%xmm6
+       paddq   16(%esp),%xmm7
+.byte  102,15,56,0,253
+       leal    16(%esi),%esi
+       jmp     .L029ccm64_dec_outer
+.align 16
+.L029ccm64_dec_outer:
+       xorps   %xmm2,%xmm6
+       movdqa  %xmm7,%xmm2
+       movl    %ebx,%ecx
+       movups  %xmm6,(%edi)
+       leal    16(%edi),%edi
+       subl    $1,%eax
+       jz      .L030ccm64_dec_break
+       movups  (%ebp),%xmm0
+       shrl    $1,%ecx
+       movups  16(%ebp),%xmm1
+       xorps   %xmm0,%xmm6
+       leal    32(%ebp),%edx
+       xorps   %xmm0,%xmm2
+       xorps   %xmm6,%xmm3
+       movups  (%edx),%xmm0
+.L031ccm64_dec2_loop:
+.byte  102,15,56,220,209
+       decl    %ecx
+.byte  102,15,56,220,217
+       movups  16(%edx),%xmm1
+.byte  102,15,56,220,208
+       leal    32(%edx),%edx
+.byte  102,15,56,220,216
+       movups  (%edx),%xmm0
+       jnz     .L031ccm64_dec2_loop
+       movups  (%esi),%xmm6
+       paddq   16(%esp),%xmm7
+.byte  102,15,56,220,209
+.byte  102,15,56,220,217
+.byte  102,15,56,0,253
+       leal    16(%esi),%esi
+.byte  102,15,56,221,208
+.byte  102,15,56,221,216
+       jmp     .L029ccm64_dec_outer
+.align 16
+.L030ccm64_dec_break:
+       movl    %ebp,%edx
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       xorps   %xmm0,%xmm6
+       leal    32(%edx),%edx
+       xorps   %xmm6,%xmm3
+.L032enc1_loop_6:
+.byte  102,15,56,220,217
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L032enc1_loop_6
+.byte  102,15,56,221,217
+       movl    48(%esp),%esp
+       movl    40(%esp),%edi
+       movups  %xmm3,(%edi)
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.size  aesni_ccm64_decrypt_blocks,.-.L_aesni_ccm64_decrypt_blocks_begin
+.globl aesni_ctr32_encrypt_blocks
+.type  aesni_ctr32_encrypt_blocks,@function
+.align 16
+aesni_ctr32_encrypt_blocks:
+.L_aesni_ctr32_encrypt_blocks_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%esi
+       movl    24(%esp),%edi
+       movl    28(%esp),%eax
+       movl    32(%esp),%edx
+       movl    36(%esp),%ebx
+       movl    %esp,%ebp
+       subl    $88,%esp
+       andl    $-16,%esp
+       movl    %ebp,80(%esp)
+       cmpl    $1,%eax
+       je      .L033ctr32_one_shortcut
+       movdqu  (%ebx),%xmm7
+       movl    $202182159,(%esp)
+       movl    $134810123,4(%esp)
+       movl    $67438087,8(%esp)
+       movl    $66051,12(%esp)
+       movl    $6,%ecx
+       xorl    %ebp,%ebp
+       movl    %ecx,16(%esp)
+       movl    %ecx,20(%esp)
+       movl    %ecx,24(%esp)
+       movl    %ebp,28(%esp)
+.byte  102,15,58,22,251,3
+.byte  102,15,58,34,253,3
+       movl    240(%edx),%ecx
+       bswap   %ebx
+       pxor    %xmm1,%xmm1
+       pxor    %xmm0,%xmm0
+       movdqa  (%esp),%xmm2
+.byte  102,15,58,34,203,0
+       leal    3(%ebx),%ebp
+.byte  102,15,58,34,197,0
+       incl    %ebx
+.byte  102,15,58,34,203,1
+       incl    %ebp
+.byte  102,15,58,34,197,1
+       incl    %ebx
+.byte  102,15,58,34,203,2
+       incl    %ebp
+.byte  102,15,58,34,197,2
+       movdqa  %xmm1,48(%esp)
+.byte  102,15,56,0,202
+       movdqa  %xmm0,64(%esp)
+.byte  102,15,56,0,194
+       pshufd  $192,%xmm1,%xmm2
+       pshufd  $128,%xmm1,%xmm3
+       cmpl    $6,%eax
+       jb      .L034ctr32_tail
+       movdqa  %xmm7,32(%esp)
+       shrl    $1,%ecx
+       movl    %edx,%ebp
+       movl    %ecx,%ebx
+       subl    $6,%eax
+       jmp     .L035ctr32_loop6
+.align 16
+.L035ctr32_loop6:
+       pshufd  $64,%xmm1,%xmm4
+       movdqa  32(%esp),%xmm1
+       pshufd  $192,%xmm0,%xmm5
+       por     %xmm1,%xmm2
+       pshufd  $128,%xmm0,%xmm6
+       por     %xmm1,%xmm3
+       pshufd  $64,%xmm0,%xmm7
+       por     %xmm1,%xmm4
+       por     %xmm1,%xmm5
+       por     %xmm1,%xmm6
+       por     %xmm1,%xmm7
+       movups  (%ebp),%xmm0
+       movups  16(%ebp),%xmm1
+       leal    32(%ebp),%edx
+       decl    %ecx
+       pxor    %xmm0,%xmm2
+       pxor    %xmm0,%xmm3
+.byte  102,15,56,220,209
+       pxor    %xmm0,%xmm4
+.byte  102,15,56,220,217
+       pxor    %xmm0,%xmm5
+.byte  102,15,56,220,225
+       pxor    %xmm0,%xmm6
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+.byte  102,15,56,220,241
+       movups  (%edx),%xmm0
+.byte  102,15,56,220,249
+       call    .L_aesni_encrypt6_enter
+       movups  (%esi),%xmm1
+       movups  16(%esi),%xmm0
+       xorps   %xmm1,%xmm2
+       movups  32(%esi),%xmm1
+       xorps   %xmm0,%xmm3
+       movups  %xmm2,(%edi)
+       movdqa  16(%esp),%xmm0
+       xorps   %xmm1,%xmm4
+       movdqa  48(%esp),%xmm1
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       paddd   %xmm0,%xmm1
+       paddd   64(%esp),%xmm0
+       movdqa  (%esp),%xmm2
+       movups  48(%esi),%xmm3
+       movups  64(%esi),%xmm4
+       xorps   %xmm3,%xmm5
+       movups  80(%esi),%xmm3
+       leal    96(%esi),%esi
+       movdqa  %xmm1,48(%esp)
+.byte  102,15,56,0,202
+       xorps   %xmm4,%xmm6
+       movups  %xmm5,48(%edi)
+       xorps   %xmm3,%xmm7
+       movdqa  %xmm0,64(%esp)
+.byte  102,15,56,0,194
+       movups  %xmm6,64(%edi)
+       pshufd  $192,%xmm1,%xmm2
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       movl    %ebx,%ecx
+       pshufd  $128,%xmm1,%xmm3
+       subl    $6,%eax
+       jnc     .L035ctr32_loop6
+       addl    $6,%eax
+       jz      .L036ctr32_ret
+       movl    %ebp,%edx
+       leal    1(,%ecx,2),%ecx
+       movdqa  32(%esp),%xmm7
+.L034ctr32_tail:
+       por     %xmm7,%xmm2
+       cmpl    $2,%eax
+       jb      .L037ctr32_one
+       pshufd  $64,%xmm1,%xmm4
+       por     %xmm7,%xmm3
+       je      .L038ctr32_two
+       pshufd  $192,%xmm0,%xmm5
+       por     %xmm7,%xmm4
+       cmpl    $4,%eax
+       jb      .L039ctr32_three
+       pshufd  $128,%xmm0,%xmm6
+       por     %xmm7,%xmm5
+       je      .L040ctr32_four
+       por     %xmm7,%xmm6
+       call    _aesni_encrypt6
+       movups  (%esi),%xmm1
+       movups  16(%esi),%xmm0
+       xorps   %xmm1,%xmm2
+       movups  32(%esi),%xmm1
+       xorps   %xmm0,%xmm3
+       movups  48(%esi),%xmm0
+       xorps   %xmm1,%xmm4
+       movups  64(%esi),%xmm1
+       xorps   %xmm0,%xmm5
+       movups  %xmm2,(%edi)
+       xorps   %xmm1,%xmm6
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       jmp     .L036ctr32_ret
+.align 16
+.L033ctr32_one_shortcut:
+       movups  (%ebx),%xmm2
+       movl    240(%edx),%ecx
+.L037ctr32_one:
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L041enc1_loop_7:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L041enc1_loop_7
+.byte  102,15,56,221,209
+       movups  (%esi),%xmm6
+       xorps   %xmm2,%xmm6
+       movups  %xmm6,(%edi)
+       jmp     .L036ctr32_ret
+.align 16
+.L038ctr32_two:
+       call    _aesni_encrypt3
+       movups  (%esi),%xmm5
+       movups  16(%esi),%xmm6
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       jmp     .L036ctr32_ret
+.align 16
+.L039ctr32_three:
+       call    _aesni_encrypt3
+       movups  (%esi),%xmm5
+       movups  16(%esi),%xmm6
+       xorps   %xmm5,%xmm2
+       movups  32(%esi),%xmm7
+       xorps   %xmm6,%xmm3
+       movups  %xmm2,(%edi)
+       xorps   %xmm7,%xmm4
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       jmp     .L036ctr32_ret
+.align 16
+.L040ctr32_four:
+       call    _aesni_encrypt4
+       movups  (%esi),%xmm6
+       movups  16(%esi),%xmm7
+       movups  32(%esi),%xmm1
+       xorps   %xmm6,%xmm2
+       movups  48(%esi),%xmm0
+       xorps   %xmm7,%xmm3
+       movups  %xmm2,(%edi)
+       xorps   %xmm1,%xmm4
+       movups  %xmm3,16(%edi)
+       xorps   %xmm0,%xmm5
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+.L036ctr32_ret:
+       movl    80(%esp),%esp
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.size  aesni_ctr32_encrypt_blocks,.-.L_aesni_ctr32_encrypt_blocks_begin
+.globl aesni_xts_encrypt
+.type  aesni_xts_encrypt,@function
+.align 16
+aesni_xts_encrypt:
+.L_aesni_xts_encrypt_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    36(%esp),%edx
+       movl    40(%esp),%esi
+       movl    240(%edx),%ecx
+       movups  (%esi),%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L042enc1_loop_8:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L042enc1_loop_8
+.byte  102,15,56,221,209
+       movl    20(%esp),%esi
+       movl    24(%esp),%edi
+       movl    28(%esp),%eax
+       movl    32(%esp),%edx
+       movl    %esp,%ebp
+       subl    $120,%esp
+       movl    240(%edx),%ecx
+       andl    $-16,%esp
+       movl    $135,96(%esp)
+       movl    $0,100(%esp)
+       movl    $1,104(%esp)
+       movl    $0,108(%esp)
+       movl    %eax,112(%esp)
+       movl    %ebp,116(%esp)
+       movdqa  %xmm2,%xmm1
+       pxor    %xmm0,%xmm0
+       movdqa  96(%esp),%xmm3
+       pcmpgtd %xmm1,%xmm0
+       andl    $-16,%eax
+       movl    %edx,%ebp
+       movl    %ecx,%ebx
+       subl    $96,%eax
+       jc      .L043xts_enc_short
+       shrl    $1,%ecx
+       movl    %ecx,%ebx
+       jmp     .L044xts_enc_loop6
+.align 16
+.L044xts_enc_loop6:
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,16(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,32(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,48(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm7
+       movdqa  %xmm1,64(%esp)
+       paddq   %xmm1,%xmm1
+       movups  (%ebp),%xmm0
+       pand    %xmm3,%xmm7
+       movups  (%esi),%xmm2
+       pxor    %xmm1,%xmm7
+       movdqu  16(%esi),%xmm3
+       xorps   %xmm0,%xmm2
+       movdqu  32(%esi),%xmm4
+       pxor    %xmm0,%xmm3
+       movdqu  48(%esi),%xmm5
+       pxor    %xmm0,%xmm4
+       movdqu  64(%esi),%xmm6
+       pxor    %xmm0,%xmm5
+       movdqu  80(%esi),%xmm1
+       pxor    %xmm0,%xmm6
+       leal    96(%esi),%esi
+       pxor    (%esp),%xmm2
+       movdqa  %xmm7,80(%esp)
+       pxor    %xmm1,%xmm7
+       movups  16(%ebp),%xmm1
+       leal    32(%ebp),%edx
+       pxor    16(%esp),%xmm3
+.byte  102,15,56,220,209
+       pxor    32(%esp),%xmm4
+.byte  102,15,56,220,217
+       pxor    48(%esp),%xmm5
+       decl    %ecx
+.byte  102,15,56,220,225
+       pxor    64(%esp),%xmm6
+.byte  102,15,56,220,233
+       pxor    %xmm0,%xmm7
+.byte  102,15,56,220,241
+       movups  (%edx),%xmm0
+.byte  102,15,56,220,249
+       call    .L_aesni_encrypt6_enter
+       movdqa  80(%esp),%xmm1
+       pxor    %xmm0,%xmm0
+       xorps   (%esp),%xmm2
+       pcmpgtd %xmm1,%xmm0
+       xorps   16(%esp),%xmm3
+       movups  %xmm2,(%edi)
+       xorps   32(%esp),%xmm4
+       movups  %xmm3,16(%edi)
+       xorps   48(%esp),%xmm5
+       movups  %xmm4,32(%edi)
+       xorps   64(%esp),%xmm6
+       movups  %xmm5,48(%edi)
+       xorps   %xmm1,%xmm7
+       movups  %xmm6,64(%edi)
+       pshufd  $19,%xmm0,%xmm2
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       movdqa  96(%esp),%xmm3
+       pxor    %xmm0,%xmm0
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       movl    %ebx,%ecx
+       pxor    %xmm2,%xmm1
+       subl    $96,%eax
+       jnc     .L044xts_enc_loop6
+       leal    1(,%ecx,2),%ecx
+       movl    %ebp,%edx
+       movl    %ecx,%ebx
+.L043xts_enc_short:
+       addl    $96,%eax
+       jz      .L045xts_enc_done6x
+       movdqa  %xmm1,%xmm5
+       cmpl    $32,%eax
+       jb      .L046xts_enc_one
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       je      .L047xts_enc_two
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,%xmm6
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       cmpl    $64,%eax
+       jb      .L048xts_enc_three
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,%xmm7
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       movdqa  %xmm5,(%esp)
+       movdqa  %xmm6,16(%esp)
+       je      .L049xts_enc_four
+       movdqa  %xmm7,32(%esp)
+       pshufd  $19,%xmm0,%xmm7
+       movdqa  %xmm1,48(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm7
+       pxor    %xmm1,%xmm7
+       movdqu  (%esi),%xmm2
+       movdqu  16(%esi),%xmm3
+       movdqu  32(%esi),%xmm4
+       pxor    (%esp),%xmm2
+       movdqu  48(%esi),%xmm5
+       pxor    16(%esp),%xmm3
+       movdqu  64(%esi),%xmm6
+       pxor    32(%esp),%xmm4
+       leal    80(%esi),%esi
+       pxor    48(%esp),%xmm5
+       movdqa  %xmm7,64(%esp)
+       pxor    %xmm7,%xmm6
+       call    _aesni_encrypt6
+       movaps  64(%esp),%xmm1
+       xorps   (%esp),%xmm2
+       xorps   16(%esp),%xmm3
+       xorps   32(%esp),%xmm4
+       movups  %xmm2,(%edi)
+       xorps   48(%esp),%xmm5
+       movups  %xmm3,16(%edi)
+       xorps   %xmm1,%xmm6
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       leal    80(%edi),%edi
+       jmp     .L050xts_enc_done
+.align 16
+.L046xts_enc_one:
+       movups  (%esi),%xmm2
+       leal    16(%esi),%esi
+       xorps   %xmm5,%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L051enc1_loop_9:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L051enc1_loop_9
+.byte  102,15,56,221,209
+       xorps   %xmm5,%xmm2
+       movups  %xmm2,(%edi)
+       leal    16(%edi),%edi
+       movdqa  %xmm5,%xmm1
+       jmp     .L050xts_enc_done
+.align 16
+.L047xts_enc_two:
+       movaps  %xmm1,%xmm6
+       movups  (%esi),%xmm2
+       movups  16(%esi),%xmm3
+       leal    32(%esi),%esi
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       xorps   %xmm4,%xmm4
+       call    _aesni_encrypt3
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       leal    32(%edi),%edi
+       movdqa  %xmm6,%xmm1
+       jmp     .L050xts_enc_done
+.align 16
+.L048xts_enc_three:
+       movaps  %xmm1,%xmm7
+       movups  (%esi),%xmm2
+       movups  16(%esi),%xmm3
+       movups  32(%esi),%xmm4
+       leal    48(%esi),%esi
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       xorps   %xmm7,%xmm4
+       call    _aesni_encrypt3
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       xorps   %xmm7,%xmm4
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       leal    48(%edi),%edi
+       movdqa  %xmm7,%xmm1
+       jmp     .L050xts_enc_done
+.align 16
+.L049xts_enc_four:
+       movaps  %xmm1,%xmm6
+       movups  (%esi),%xmm2
+       movups  16(%esi),%xmm3
+       movups  32(%esi),%xmm4
+       xorps   (%esp),%xmm2
+       movups  48(%esi),%xmm5
+       leal    64(%esi),%esi
+       xorps   16(%esp),%xmm3
+       xorps   %xmm7,%xmm4
+       xorps   %xmm6,%xmm5
+       call    _aesni_encrypt4
+       xorps   (%esp),%xmm2
+       xorps   16(%esp),%xmm3
+       xorps   %xmm7,%xmm4
+       movups  %xmm2,(%edi)
+       xorps   %xmm6,%xmm5
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       leal    64(%edi),%edi
+       movdqa  %xmm6,%xmm1
+       jmp     .L050xts_enc_done
+.align 16
+.L045xts_enc_done6x:
+       movl    112(%esp),%eax
+       andl    $15,%eax
+       jz      .L052xts_enc_ret
+       movdqa  %xmm1,%xmm5
+       movl    %eax,112(%esp)
+       jmp     .L053xts_enc_steal
+.align 16
+.L050xts_enc_done:
+       movl    112(%esp),%eax
+       pxor    %xmm0,%xmm0
+       andl    $15,%eax
+       jz      .L052xts_enc_ret
+       pcmpgtd %xmm1,%xmm0
+       movl    %eax,112(%esp)
+       pshufd  $19,%xmm0,%xmm5
+       paddq   %xmm1,%xmm1
+       pand    96(%esp),%xmm5
+       pxor    %xmm1,%xmm5
+.L053xts_enc_steal:
+       movzbl  (%esi),%ecx
+       movzbl  -16(%edi),%edx
+       leal    1(%esi),%esi
+       movb    %cl,-16(%edi)
+       movb    %dl,(%edi)
+       leal    1(%edi),%edi
+       subl    $1,%eax
+       jnz     .L053xts_enc_steal
+       subl    112(%esp),%edi
+       movl    %ebp,%edx
+       movl    %ebx,%ecx
+       movups  -16(%edi),%xmm2
+       xorps   %xmm5,%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L054enc1_loop_10:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L054enc1_loop_10
+.byte  102,15,56,221,209
+       xorps   %xmm5,%xmm2
+       movups  %xmm2,-16(%edi)
+.L052xts_enc_ret:
+       movl    116(%esp),%esp
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.size  aesni_xts_encrypt,.-.L_aesni_xts_encrypt_begin
+.globl aesni_xts_decrypt
+.type  aesni_xts_decrypt,@function
+.align 16
+aesni_xts_decrypt:
+.L_aesni_xts_decrypt_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    36(%esp),%edx
+       movl    40(%esp),%esi
+       movl    240(%edx),%ecx
+       movups  (%esi),%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L055enc1_loop_11:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L055enc1_loop_11
+.byte  102,15,56,221,209
+       movl    20(%esp),%esi
+       movl    24(%esp),%edi
+       movl    28(%esp),%eax
+       movl    32(%esp),%edx
+       movl    %esp,%ebp
+       subl    $120,%esp
+       andl    $-16,%esp
+       xorl    %ebx,%ebx
+       testl   $15,%eax
+       setnz   %bl
+       shll    $4,%ebx
+       subl    %ebx,%eax
+       movl    $135,96(%esp)
+       movl    $0,100(%esp)
+       movl    $1,104(%esp)
+       movl    $0,108(%esp)
+       movl    %eax,112(%esp)
+       movl    %ebp,116(%esp)
+       movl    240(%edx),%ecx
+       movl    %edx,%ebp
+       movl    %ecx,%ebx
+       movdqa  %xmm2,%xmm1
+       pxor    %xmm0,%xmm0
+       movdqa  96(%esp),%xmm3
+       pcmpgtd %xmm1,%xmm0
+       andl    $-16,%eax
+       subl    $96,%eax
+       jc      .L056xts_dec_short
+       shrl    $1,%ecx
+       movl    %ecx,%ebx
+       jmp     .L057xts_dec_loop6
+.align 16
+.L057xts_dec_loop6:
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,16(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,32(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,48(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       pshufd  $19,%xmm0,%xmm7
+       movdqa  %xmm1,64(%esp)
+       paddq   %xmm1,%xmm1
+       movups  (%ebp),%xmm0
+       pand    %xmm3,%xmm7
+       movups  (%esi),%xmm2
+       pxor    %xmm1,%xmm7
+       movdqu  16(%esi),%xmm3
+       xorps   %xmm0,%xmm2
+       movdqu  32(%esi),%xmm4
+       pxor    %xmm0,%xmm3
+       movdqu  48(%esi),%xmm5
+       pxor    %xmm0,%xmm4
+       movdqu  64(%esi),%xmm6
+       pxor    %xmm0,%xmm5
+       movdqu  80(%esi),%xmm1
+       pxor    %xmm0,%xmm6
+       leal    96(%esi),%esi
+       pxor    (%esp),%xmm2
+       movdqa  %xmm7,80(%esp)
+       pxor    %xmm1,%xmm7
+       movups  16(%ebp),%xmm1
+       leal    32(%ebp),%edx
+       pxor    16(%esp),%xmm3
+.byte  102,15,56,222,209
+       pxor    32(%esp),%xmm4
+.byte  102,15,56,222,217
+       pxor    48(%esp),%xmm5
+       decl    %ecx
+.byte  102,15,56,222,225
+       pxor    64(%esp),%xmm6
+.byte  102,15,56,222,233
+       pxor    %xmm0,%xmm7
+.byte  102,15,56,222,241
+       movups  (%edx),%xmm0
+.byte  102,15,56,222,249
+       call    .L_aesni_decrypt6_enter
+       movdqa  80(%esp),%xmm1
+       pxor    %xmm0,%xmm0
+       xorps   (%esp),%xmm2
+       pcmpgtd %xmm1,%xmm0
+       xorps   16(%esp),%xmm3
+       movups  %xmm2,(%edi)
+       xorps   32(%esp),%xmm4
+       movups  %xmm3,16(%edi)
+       xorps   48(%esp),%xmm5
+       movups  %xmm4,32(%edi)
+       xorps   64(%esp),%xmm6
+       movups  %xmm5,48(%edi)
+       xorps   %xmm1,%xmm7
+       movups  %xmm6,64(%edi)
+       pshufd  $19,%xmm0,%xmm2
+       movups  %xmm7,80(%edi)
+       leal    96(%edi),%edi
+       movdqa  96(%esp),%xmm3
+       pxor    %xmm0,%xmm0
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       movl    %ebx,%ecx
+       pxor    %xmm2,%xmm1
+       subl    $96,%eax
+       jnc     .L057xts_dec_loop6
+       leal    1(,%ecx,2),%ecx
+       movl    %ebp,%edx
+       movl    %ecx,%ebx
+.L056xts_dec_short:
+       addl    $96,%eax
+       jz      .L058xts_dec_done6x
+       movdqa  %xmm1,%xmm5
+       cmpl    $32,%eax
+       jb      .L059xts_dec_one
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       je      .L060xts_dec_two
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,%xmm6
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       cmpl    $64,%eax
+       jb      .L061xts_dec_three
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  %xmm1,%xmm7
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+       movdqa  %xmm5,(%esp)
+       movdqa  %xmm6,16(%esp)
+       je      .L062xts_dec_four
+       movdqa  %xmm7,32(%esp)
+       pshufd  $19,%xmm0,%xmm7
+       movdqa  %xmm1,48(%esp)
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm7
+       pxor    %xmm1,%xmm7
+       movdqu  (%esi),%xmm2
+       movdqu  16(%esi),%xmm3
+       movdqu  32(%esi),%xmm4
+       pxor    (%esp),%xmm2
+       movdqu  48(%esi),%xmm5
+       pxor    16(%esp),%xmm3
+       movdqu  64(%esi),%xmm6
+       pxor    32(%esp),%xmm4
+       leal    80(%esi),%esi
+       pxor    48(%esp),%xmm5
+       movdqa  %xmm7,64(%esp)
+       pxor    %xmm7,%xmm6
+       call    _aesni_decrypt6
+       movaps  64(%esp),%xmm1
+       xorps   (%esp),%xmm2
+       xorps   16(%esp),%xmm3
+       xorps   32(%esp),%xmm4
+       movups  %xmm2,(%edi)
+       xorps   48(%esp),%xmm5
+       movups  %xmm3,16(%edi)
+       xorps   %xmm1,%xmm6
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       movups  %xmm6,64(%edi)
+       leal    80(%edi),%edi
+       jmp     .L063xts_dec_done
+.align 16
+.L059xts_dec_one:
+       movups  (%esi),%xmm2
+       leal    16(%esi),%esi
+       xorps   %xmm5,%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L064dec1_loop_12:
+.byte  102,15,56,222,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L064dec1_loop_12
+.byte  102,15,56,223,209
+       xorps   %xmm5,%xmm2
+       movups  %xmm2,(%edi)
+       leal    16(%edi),%edi
+       movdqa  %xmm5,%xmm1
+       jmp     .L063xts_dec_done
+.align 16
+.L060xts_dec_two:
+       movaps  %xmm1,%xmm6
+       movups  (%esi),%xmm2
+       movups  16(%esi),%xmm3
+       leal    32(%esi),%esi
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       call    _aesni_decrypt3
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       leal    32(%edi),%edi
+       movdqa  %xmm6,%xmm1
+       jmp     .L063xts_dec_done
+.align 16
+.L061xts_dec_three:
+       movaps  %xmm1,%xmm7
+       movups  (%esi),%xmm2
+       movups  16(%esi),%xmm3
+       movups  32(%esi),%xmm4
+       leal    48(%esi),%esi
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       xorps   %xmm7,%xmm4
+       call    _aesni_decrypt3
+       xorps   %xmm5,%xmm2
+       xorps   %xmm6,%xmm3
+       xorps   %xmm7,%xmm4
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       leal    48(%edi),%edi
+       movdqa  %xmm7,%xmm1
+       jmp     .L063xts_dec_done
+.align 16
+.L062xts_dec_four:
+       movaps  %xmm1,%xmm6
+       movups  (%esi),%xmm2
+       movups  16(%esi),%xmm3
+       movups  32(%esi),%xmm4
+       xorps   (%esp),%xmm2
+       movups  48(%esi),%xmm5
+       leal    64(%esi),%esi
+       xorps   16(%esp),%xmm3
+       xorps   %xmm7,%xmm4
+       xorps   %xmm6,%xmm5
+       call    _aesni_decrypt4
+       xorps   (%esp),%xmm2
+       xorps   16(%esp),%xmm3
+       xorps   %xmm7,%xmm4
+       movups  %xmm2,(%edi)
+       xorps   %xmm6,%xmm5
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       leal    64(%edi),%edi
+       movdqa  %xmm6,%xmm1
+       jmp     .L063xts_dec_done
+.align 16
+.L058xts_dec_done6x:
+       movl    112(%esp),%eax
+       andl    $15,%eax
+       jz      .L065xts_dec_ret
+       movl    %eax,112(%esp)
+       jmp     .L066xts_dec_only_one_more
+.align 16
+.L063xts_dec_done:
+       movl    112(%esp),%eax
+       pxor    %xmm0,%xmm0
+       andl    $15,%eax
+       jz      .L065xts_dec_ret
+       pcmpgtd %xmm1,%xmm0
+       movl    %eax,112(%esp)
+       pshufd  $19,%xmm0,%xmm2
+       pxor    %xmm0,%xmm0
+       movdqa  96(%esp),%xmm3
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm2
+       pcmpgtd %xmm1,%xmm0
+       pxor    %xmm2,%xmm1
+.L066xts_dec_only_one_more:
+       pshufd  $19,%xmm0,%xmm5
+       movdqa  %xmm1,%xmm6
+       paddq   %xmm1,%xmm1
+       pand    %xmm3,%xmm5
+       pxor    %xmm1,%xmm5
+       movl    %ebp,%edx
+       movl    %ebx,%ecx
+       movups  (%esi),%xmm2
+       xorps   %xmm5,%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L067dec1_loop_13:
+.byte  102,15,56,222,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L067dec1_loop_13
+.byte  102,15,56,223,209
+       xorps   %xmm5,%xmm2
+       movups  %xmm2,(%edi)
+.L068xts_dec_steal:
+       movzbl  16(%esi),%ecx
+       movzbl  (%edi),%edx
+       leal    1(%esi),%esi
+       movb    %cl,(%edi)
+       movb    %dl,16(%edi)
+       leal    1(%edi),%edi
+       subl    $1,%eax
+       jnz     .L068xts_dec_steal
+       subl    112(%esp),%edi
+       movl    %ebp,%edx
+       movl    %ebx,%ecx
+       movups  (%edi),%xmm2
+       xorps   %xmm6,%xmm2
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L069dec1_loop_14:
+.byte  102,15,56,222,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L069dec1_loop_14
+.byte  102,15,56,223,209
+       xorps   %xmm6,%xmm2
+       movups  %xmm2,(%edi)
+.L065xts_dec_ret:
+       movl    116(%esp),%esp
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.size  aesni_xts_decrypt,.-.L_aesni_xts_decrypt_begin
+.globl aesni_cbc_encrypt
+.type  aesni_cbc_encrypt,@function
+.align 16
+aesni_cbc_encrypt:
+.L_aesni_cbc_encrypt_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%esi
+       movl    %esp,%ebx
+       movl    24(%esp),%edi
+       subl    $24,%ebx
+       movl    28(%esp),%eax
+       andl    $-16,%ebx
+       movl    32(%esp),%edx
+       movl    36(%esp),%ebp
+       testl   %eax,%eax
+       jz      .L070cbc_abort
+       cmpl    $0,40(%esp)
+       xchgl   %esp,%ebx
+       movups  (%ebp),%xmm7
+       movl    240(%edx),%ecx
+       movl    %edx,%ebp
+       movl    %ebx,16(%esp)
+       movl    %ecx,%ebx
+       je      .L071cbc_decrypt
+       movaps  %xmm7,%xmm2
+       cmpl    $16,%eax
+       jb      .L072cbc_enc_tail
+       subl    $16,%eax
+       jmp     .L073cbc_enc_loop
+.align 16
+.L073cbc_enc_loop:
+       movups  (%esi),%xmm7
+       leal    16(%esi),%esi
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       xorps   %xmm0,%xmm7
+       leal    32(%edx),%edx
+       xorps   %xmm7,%xmm2
+.L074enc1_loop_15:
+.byte  102,15,56,220,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L074enc1_loop_15
+.byte  102,15,56,221,209
+       movl    %ebx,%ecx
+       movl    %ebp,%edx
+       movups  %xmm2,(%edi)
+       leal    16(%edi),%edi
+       subl    $16,%eax
+       jnc     .L073cbc_enc_loop
+       addl    $16,%eax
+       jnz     .L072cbc_enc_tail
+       movaps  %xmm2,%xmm7
+       jmp     .L075cbc_ret
+.L072cbc_enc_tail:
+       movl    %eax,%ecx
+.long  2767451785
+       movl    $16,%ecx
+       subl    %eax,%ecx
+       xorl    %eax,%eax
+.long  2868115081
+       leal    -16(%edi),%edi
+       movl    %ebx,%ecx
+       movl    %edi,%esi
+       movl    %ebp,%edx
+       jmp     .L073cbc_enc_loop
+.align 16
+.L071cbc_decrypt:
+       cmpl    $80,%eax
+       jbe     .L076cbc_dec_tail
+       movaps  %xmm7,(%esp)
+       subl    $80,%eax
+       jmp     .L077cbc_dec_loop6_enter
+.align 16
+.L078cbc_dec_loop6:
+       movaps  %xmm0,(%esp)
+       movups  %xmm7,(%edi)
+       leal    16(%edi),%edi
+.L077cbc_dec_loop6_enter:
+       movdqu  (%esi),%xmm2
+       movdqu  16(%esi),%xmm3
+       movdqu  32(%esi),%xmm4
+       movdqu  48(%esi),%xmm5
+       movdqu  64(%esi),%xmm6
+       movdqu  80(%esi),%xmm7
+       call    _aesni_decrypt6
+       movups  (%esi),%xmm1
+       movups  16(%esi),%xmm0
+       xorps   (%esp),%xmm2
+       xorps   %xmm1,%xmm3
+       movups  32(%esi),%xmm1
+       xorps   %xmm0,%xmm4
+       movups  48(%esi),%xmm0
+       xorps   %xmm1,%xmm5
+       movups  64(%esi),%xmm1
+       xorps   %xmm0,%xmm6
+       movups  80(%esi),%xmm0
+       xorps   %xmm1,%xmm7
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       leal    96(%esi),%esi
+       movups  %xmm4,32(%edi)
+       movl    %ebx,%ecx
+       movups  %xmm5,48(%edi)
+       movl    %ebp,%edx
+       movups  %xmm6,64(%edi)
+       leal    80(%edi),%edi
+       subl    $96,%eax
+       ja      .L078cbc_dec_loop6
+       movaps  %xmm7,%xmm2
+       movaps  %xmm0,%xmm7
+       addl    $80,%eax
+       jle     .L079cbc_dec_tail_collected
+       movups  %xmm2,(%edi)
+       leal    16(%edi),%edi
+.L076cbc_dec_tail:
+       movups  (%esi),%xmm2
+       movaps  %xmm2,%xmm6
+       cmpl    $16,%eax
+       jbe     .L080cbc_dec_one
+       movups  16(%esi),%xmm3
+       movaps  %xmm3,%xmm5
+       cmpl    $32,%eax
+       jbe     .L081cbc_dec_two
+       movups  32(%esi),%xmm4
+       cmpl    $48,%eax
+       jbe     .L082cbc_dec_three
+       movups  48(%esi),%xmm5
+       cmpl    $64,%eax
+       jbe     .L083cbc_dec_four
+       movups  64(%esi),%xmm6
+       movaps  %xmm7,(%esp)
+       movups  (%esi),%xmm2
+       xorps   %xmm7,%xmm7
+       call    _aesni_decrypt6
+       movups  (%esi),%xmm1
+       movups  16(%esi),%xmm0
+       xorps   (%esp),%xmm2
+       xorps   %xmm1,%xmm3
+       movups  32(%esi),%xmm1
+       xorps   %xmm0,%xmm4
+       movups  48(%esi),%xmm0
+       xorps   %xmm1,%xmm5
+       movups  64(%esi),%xmm7
+       xorps   %xmm0,%xmm6
+       movups  %xmm2,(%edi)
+       movups  %xmm3,16(%edi)
+       movups  %xmm4,32(%edi)
+       movups  %xmm5,48(%edi)
+       leal    64(%edi),%edi
+       movaps  %xmm6,%xmm2
+       subl    $80,%eax
+       jmp     .L079cbc_dec_tail_collected
+.align 16
+.L080cbc_dec_one:
+       movups  (%edx),%xmm0
+       movups  16(%edx),%xmm1
+       leal    32(%edx),%edx
+       xorps   %xmm0,%xmm2
+.L084dec1_loop_16:
+.byte  102,15,56,222,209
+       decl    %ecx
+       movups  (%edx),%xmm1
+       leal    16(%edx),%edx
+       jnz     .L084dec1_loop_16
+.byte  102,15,56,223,209
+       xorps   %xmm7,%xmm2
+       movaps  %xmm6,%xmm7
+       subl    $16,%eax
+       jmp     .L079cbc_dec_tail_collected
+.align 16
+.L081cbc_dec_two:
+       xorps   %xmm4,%xmm4
+       call    _aesni_decrypt3
+       xorps   %xmm7,%xmm2
+       xorps   %xmm6,%xmm3
+       movups  %xmm2,(%edi)
+       movaps  %xmm3,%xmm2
+       leal    16(%edi),%edi
+       movaps  %xmm5,%xmm7
+       subl    $32,%eax
+       jmp     .L079cbc_dec_tail_collected
+.align 16
+.L082cbc_dec_three:
+       call    _aesni_decrypt3
+       xorps   %xmm7,%xmm2
+       xorps   %xmm6,%xmm3
+       xorps   %xmm5,%xmm4
+       movups  %xmm2,(%edi)
+       movaps  %xmm4,%xmm2
+       movups  %xmm3,16(%edi)
+       leal    32(%edi),%edi
+       movups  32(%esi),%xmm7
+       subl    $48,%eax
+       jmp     .L079cbc_dec_tail_collected
+.align 16
+.L083cbc_dec_four:
+       call    _aesni_decrypt4
+       movups  16(%esi),%xmm1
+       movups  32(%esi),%xmm0
+       xorps   %xmm7,%xmm2
+       movups  48(%esi),%xmm7
+       xorps   %xmm6,%xmm3
+       movups  %xmm2,(%edi)
+       xorps   %xmm1,%xmm4
+       movups  %xmm3,16(%edi)
+       xorps   %xmm0,%xmm5
+       movups  %xmm4,32(%edi)
+       leal    48(%edi),%edi
+       movaps  %xmm5,%xmm2
+       subl    $64,%eax
+.L079cbc_dec_tail_collected:
+       andl    $15,%eax
+       jnz     .L085cbc_dec_tail_partial
+       movups  %xmm2,(%edi)
+       jmp     .L075cbc_ret
+.align 16
+.L085cbc_dec_tail_partial:
+       movaps  %xmm2,(%esp)
+       movl    $16,%ecx
+       movl    %esp,%esi
+       subl    %eax,%ecx
+.long  2767451785
+.L075cbc_ret:
+       movl    16(%esp),%esp
+       movl    36(%esp),%ebp
+       movups  %xmm7,(%ebp)
+.L070cbc_abort:
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.size  aesni_cbc_encrypt,.-.L_aesni_cbc_encrypt_begin
+.type  _aesni_set_encrypt_key,@function
+.align 16
+_aesni_set_encrypt_key:
+       testl   %eax,%eax
+       jz      .L086bad_pointer
+       testl   %edx,%edx
+       jz      .L086bad_pointer
+       movups  (%eax),%xmm0
+       xorps   %xmm4,%xmm4
+       leal    16(%edx),%edx
+       cmpl    $256,%ecx
+       je      .L08714rounds
+       cmpl    $192,%ecx
+       je      .L08812rounds
+       cmpl    $128,%ecx
+       jne     .L089bad_keybits
+.align 16
+.L09010rounds:
+       movl    $9,%ecx
+       movups  %xmm0,-16(%edx)
+.byte  102,15,58,223,200,1
+       call    .L091key_128_cold
+.byte  102,15,58,223,200,2
+       call    .L092key_128
+.byte  102,15,58,223,200,4
+       call    .L092key_128
+.byte  102,15,58,223,200,8
+       call    .L092key_128
+.byte  102,15,58,223,200,16
+       call    .L092key_128
+.byte  102,15,58,223,200,32
+       call    .L092key_128
+.byte  102,15,58,223,200,64
+       call    .L092key_128
+.byte  102,15,58,223,200,128
+       call    .L092key_128
+.byte  102,15,58,223,200,27
+       call    .L092key_128
+.byte  102,15,58,223,200,54
+       call    .L092key_128
+       movups  %xmm0,(%edx)
+       movl    %ecx,80(%edx)
+       xorl    %eax,%eax
+       ret
+.align 16
+.L092key_128:
+       movups  %xmm0,(%edx)
+       leal    16(%edx),%edx
+.L091key_128_cold:
+       shufps  $16,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $140,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $255,%xmm1,%xmm1
+       xorps   %xmm1,%xmm0
+       ret
+.align 16
+.L08812rounds:
+       movq    16(%eax),%xmm2
+       movl    $11,%ecx
+       movups  %xmm0,-16(%edx)
+.byte  102,15,58,223,202,1
+       call    .L093key_192a_cold
+.byte  102,15,58,223,202,2
+       call    .L094key_192b
+.byte  102,15,58,223,202,4
+       call    .L095key_192a
+.byte  102,15,58,223,202,8
+       call    .L094key_192b
+.byte  102,15,58,223,202,16
+       call    .L095key_192a
+.byte  102,15,58,223,202,32
+       call    .L094key_192b
+.byte  102,15,58,223,202,64
+       call    .L095key_192a
+.byte  102,15,58,223,202,128
+       call    .L094key_192b
+       movups  %xmm0,(%edx)
+       movl    %ecx,48(%edx)
+       xorl    %eax,%eax
+       ret
+.align 16
+.L095key_192a:
+       movups  %xmm0,(%edx)
+       leal    16(%edx),%edx
+.align 16
+.L093key_192a_cold:
+       movaps  %xmm2,%xmm5
+.L096key_192b_warm:
+       shufps  $16,%xmm0,%xmm4
+       movdqa  %xmm2,%xmm3
+       xorps   %xmm4,%xmm0
+       shufps  $140,%xmm0,%xmm4
+       pslldq  $4,%xmm3
+       xorps   %xmm4,%xmm0
+       pshufd  $85,%xmm1,%xmm1
+       pxor    %xmm3,%xmm2
+       pxor    %xmm1,%xmm0
+       pshufd  $255,%xmm0,%xmm3
+       pxor    %xmm3,%xmm2
+       ret
+.align 16
+.L094key_192b:
+       movaps  %xmm0,%xmm3
+       shufps  $68,%xmm0,%xmm5
+       movups  %xmm5,(%edx)
+       shufps  $78,%xmm2,%xmm3
+       movups  %xmm3,16(%edx)
+       leal    32(%edx),%edx
+       jmp     .L096key_192b_warm
+.align 16
+.L08714rounds:
+       movups  16(%eax),%xmm2
+       movl    $13,%ecx
+       leal    16(%edx),%edx
+       movups  %xmm0,-32(%edx)
+       movups  %xmm2,-16(%edx)
+.byte  102,15,58,223,202,1
+       call    .L097key_256a_cold
+.byte  102,15,58,223,200,1
+       call    .L098key_256b
+.byte  102,15,58,223,202,2
+       call    .L099key_256a
+.byte  102,15,58,223,200,2
+       call    .L098key_256b
+.byte  102,15,58,223,202,4
+       call    .L099key_256a
+.byte  102,15,58,223,200,4
+       call    .L098key_256b
+.byte  102,15,58,223,202,8
+       call    .L099key_256a
+.byte  102,15,58,223,200,8
+       call    .L098key_256b
+.byte  102,15,58,223,202,16
+       call    .L099key_256a
+.byte  102,15,58,223,200,16
+       call    .L098key_256b
+.byte  102,15,58,223,202,32
+       call    .L099key_256a
+.byte  102,15,58,223,200,32
+       call    .L098key_256b
+.byte  102,15,58,223,202,64
+       call    .L099key_256a
+       movups  %xmm0,(%edx)
+       movl    %ecx,16(%edx)
+       xorl    %eax,%eax
+       ret
+.align 16
+.L099key_256a:
+       movups  %xmm2,(%edx)
+       leal    16(%edx),%edx
+.L097key_256a_cold:
+       shufps  $16,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $140,%xmm0,%xmm4
+       xorps   %xmm4,%xmm0
+       shufps  $255,%xmm1,%xmm1
+       xorps   %xmm1,%xmm0
+       ret
+.align 16
+.L098key_256b:
+       movups  %xmm0,(%edx)
+       leal    16(%edx),%edx
+       shufps  $16,%xmm2,%xmm4
+       xorps   %xmm4,%xmm2
+       shufps  $140,%xmm2,%xmm4
+       xorps   %xmm4,%xmm2
+       shufps  $170,%xmm1,%xmm1
+       xorps   %xmm1,%xmm2
+       ret
+.align 4
+.L086bad_pointer:
+       movl    $-1,%eax
+       ret
+.align 4
+.L089bad_keybits:
+       movl    $-2,%eax
+       ret
+.size  _aesni_set_encrypt_key,.-_aesni_set_encrypt_key
+.globl aesni_set_encrypt_key
+.type  aesni_set_encrypt_key,@function
+.align 16
+aesni_set_encrypt_key:
+.L_aesni_set_encrypt_key_begin:
+       movl    4(%esp),%eax
+       movl    8(%esp),%ecx
+       movl    12(%esp),%edx
+       call    _aesni_set_encrypt_key
+       ret
+.size  aesni_set_encrypt_key,.-.L_aesni_set_encrypt_key_begin
+.globl aesni_set_decrypt_key
+.type  aesni_set_decrypt_key,@function
+.align 16
+aesni_set_decrypt_key:
+.L_aesni_set_decrypt_key_begin:
+       movl    4(%esp),%eax
+       movl    8(%esp),%ecx
+       movl    12(%esp),%edx
+       call    _aesni_set_encrypt_key
+       movl    12(%esp),%edx
+       shll    $4,%ecx
+       testl   %eax,%eax
+       jnz     .L100dec_key_ret
+       leal    16(%edx,%ecx,1),%eax
+       movups  (%edx),%xmm0
+       movups  (%eax),%xmm1
+       movups  %xmm0,(%eax)
+       movups  %xmm1,(%edx)
+       leal    16(%edx),%edx
+       leal    -16(%eax),%eax
+.L101dec_key_inverse:
+       movups  (%edx),%xmm0
+       movups  (%eax),%xmm1
+.byte  102,15,56,219,192
+.byte  102,15,56,219,201
+       leal    16(%edx),%edx
+       leal    -16(%eax),%eax
+       movups  %xmm0,16(%eax)
+       movups  %xmm1,-16(%edx)
+       cmpl    %edx,%eax
+       ja      .L101dec_key_inverse
+       movups  (%edx),%xmm0
+.byte  102,15,56,219,192
+       movups  %xmm0,(%edx)
+       xorl    %eax,%eax
+.L100dec_key_ret:
+       ret
+.size  aesni_set_decrypt_key,.-.L_aesni_set_decrypt_key_begin
+.byte  65,69,83,32,102,111,114,32,73,110,116,101,108,32,65,69
+.byte  83,45,78,73,44,32,67,82,89,80,84,79,71,65,77,83
+.byte  32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115
+.byte  115,108,46,111,114,103,62,0
+
+#if defined(__ELF__)
+.section .note.GNU-stack,"",%progbits
+#endif
+
diff --git a/lib/accelerated/x86/asm/cpuid-x86-64.s 
b/lib/accelerated/x86/asm/cpuid-x86-64.s
new file mode 100644
index 0000000..09755ea
--- /dev/null
+++ b/lib/accelerated/x86/asm/cpuid-x86-64.s
@@ -0,0 +1,62 @@
+#
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# Author: Nikos Mavrogiannopoulos
+#
+# This file is part of GnuTLS.
+#
+# The GnuTLS is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 3 of
+# the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+       .file "cpuid.asm"
+        
+       .text
+       .align 16
+.globl _gnutls_cpuid
+.type _gnutls_cpuid,%function
+_gnutls_cpuid:
+       pushq   %rbp
+       movq    %rsp, %rbp
+       pushq   %rbx
+       movl    %edi, -12(%rbp)
+       movq    %rsi, -24(%rbp)
+       movq    %rdx, -32(%rbp)
+       movq    %rcx, -40(%rbp)
+       movq    %r8, -48(%rbp)
+       movl    -12(%rbp), %eax
+       movl    %eax, -60(%rbp)
+       movl    -60(%rbp), %eax
+       cpuid
+       movl    %edx, -56(%rbp)
+       movl    %ecx, %esi
+       movl    %eax, -52(%rbp)
+       movq    -24(%rbp), %rax
+       movl    -52(%rbp), %edx
+       movl    %edx, (%rax)
+       movq    -32(%rbp), %rax
+       movl    %ebx, (%rax)
+       movq    -40(%rbp), %rax
+       movl    %esi, (%rax)
+       movq    -48(%rbp), %rax
+       movl    -56(%rbp), %ecx
+       movl    %ecx, (%rax)
+       popq    %rbx
+       leave
+       ret
+.size _gnutls_cpuid, . - _gnutls_cpuid
+
+
+#if defined(__ELF__)
+.section .note.GNU-stack,"",%progbits
+#endif
diff --git a/lib/accelerated/x86/asm/cpuid-x86.s 
b/lib/accelerated/x86/asm/cpuid-x86.s
new file mode 100644
index 0000000..bf3e6ac
--- /dev/null
+++ b/lib/accelerated/x86/asm/cpuid-x86.s
@@ -0,0 +1,77 @@
+#
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# Author: Nikos Mavrogiannopoulos
+#
+# This file is part of GnuTLS.
+#
+# The GnuTLS is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation; either version 3 of
+# the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+       .file "cpuid.asm"
+        
+       .text
+       .align 16
+.globl _gnutls_cpuid
+.type _gnutls_cpuid,%function
+_gnutls_cpuid:
+       pushl   %ebp
+       movl    %esp, %ebp
+       subl    $12, %esp
+       movl    %ebx, (%esp)
+       movl    8(%ebp), %eax
+       movl    %esi, 4(%esp)
+       movl    %edi, 8(%esp)
+       pushl %ebx
+       cpuid
+       movl %ebx, %edi
+       popl %ebx
+       movl    %edx, %esi
+       movl    12(%ebp), %edx
+       movl    %eax, (%edx)
+       movl    16(%ebp), %eax
+       movl    %edi, (%eax)
+       movl    20(%ebp), %eax
+       movl    %ecx, (%eax)
+       movl    24(%ebp), %eax
+       movl    %esi, (%eax)
+       movl    (%esp), %ebx
+       movl    4(%esp), %esi
+       movl    8(%esp), %edi
+       movl    %ebp, %esp
+       popl    %ebp
+       ret
+.size _gnutls_cpuid, . - _gnutls_cpuid
+
+       .globl  _gnutls_have_cpuid
+       .type   _gnutls_have_cpuid, @function
+_gnutls_have_cpuid:
+.LFB0:
+       .cfi_startproc
+       pushfl  
+       pop %eax        
+       orl $0x200000, %eax     
+       push %eax       
+       popfl   
+       pushfl  
+       pop %eax        
+       andl $0x200000, %eax    
+       ret
+       .cfi_endproc
+.LFE0:
+       .size   _gnutls_have_cpuid, .-_gnutls_have_cpuid
+
+#if defined(__ELF__)
+.section .note.GNU-stack,"",%progbits
+#endif
diff --git a/lib/accelerated/x86/asm/padlock-x86-64.s 
b/lib/accelerated/x86/asm/padlock-x86-64.s
new file mode 100644
index 0000000..156fe38
--- /dev/null
+++ b/lib/accelerated/x86/asm/padlock-x86-64.s
@@ -0,0 +1,519 @@
+# Copyright (c) 2011, Andy Polyakov by <address@hidden>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 
+#     * Redistributions of source code must retain copyright notices,
+#      this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+#
+#     * Neither the name of the Andy Polyakov nor the names of its
+#      copyright holder and contributors may be used to endorse or
+#      promote products derived from this software without specific
+#      prior written permission.
+#
+# ALTERNATIVELY, provided that this notice is retained in full, this
+# product may be distributed under the terms of the GNU General Public
+# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+# those given above.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.text  
+.globl padlock_capability
+.type  padlock_capability,@function
+.align 16
+padlock_capability:
+       movq    %rbx,%r8
+       xorl    %eax,%eax
+       cpuid
+       xorl    %eax,%eax
+       cmpl    $1953391939,%ebx
+       jne     .Lnoluck
+       cmpl    $1215460705,%edx
+       jne     .Lnoluck
+       cmpl    $1936487777,%ecx
+       jne     .Lnoluck
+       movl    $3221225472,%eax
+       cpuid
+       movl    %eax,%edx
+       xorl    %eax,%eax
+       cmpl    $3221225473,%edx
+       jb      .Lnoluck
+       movl    $3221225473,%eax
+       cpuid
+       movl    %edx,%eax
+       andl    $4294967279,%eax
+       orl     $16,%eax
+.Lnoluck:
+       movq    %r8,%rbx
+       .byte   0xf3,0xc3
+.size  padlock_capability,.-padlock_capability
+
+.globl padlock_key_bswap
+.type  padlock_key_bswap,@function
+.align 16
+padlock_key_bswap:
+       movl    240(%rdi),%edx
+.Lbswap_loop:
+       movl    (%rdi),%eax
+       bswapl  %eax
+       movl    %eax,(%rdi)
+       leaq    4(%rdi),%rdi
+       subl    $1,%edx
+       jnz     .Lbswap_loop
+       .byte   0xf3,0xc3
+.size  padlock_key_bswap,.-padlock_key_bswap
+
+.globl padlock_verify_context
+.type  padlock_verify_context,@function
+.align 16
+padlock_verify_context:
+       movq    %rdi,%rdx
+       pushf
+       leaq    .Lpadlock_saved_context(%rip),%rax
+       call    _padlock_verify_ctx
+       leaq    8(%rsp),%rsp
+       .byte   0xf3,0xc3
+.size  padlock_verify_context,.-padlock_verify_context
+
+.type  _padlock_verify_ctx,@function
+.align 16
+_padlock_verify_ctx:
+       movq    8(%rsp),%r8
+       btq     $30,%r8
+       jnc     .Lverified
+       cmpq    (%rax),%rdx
+       je      .Lverified
+       pushf
+       popf
+.Lverified:
+       movq    %rdx,(%rax)
+       .byte   0xf3,0xc3
+.size  _padlock_verify_ctx,.-_padlock_verify_ctx
+
+.globl padlock_reload_key
+.type  padlock_reload_key,@function
+.align 16
+padlock_reload_key:
+       pushf
+       popf
+       .byte   0xf3,0xc3
+.size  padlock_reload_key,.-padlock_reload_key
+
+.globl padlock_aes_block
+.type  padlock_aes_block,@function
+.align 16
+padlock_aes_block:
+       movq    %rbx,%r8
+       movq    $1,%rcx
+       leaq    32(%rdx),%rbx
+       leaq    16(%rdx),%rdx
+.byte  0xf3,0x0f,0xa7,0xc8     
+       movq    %r8,%rbx
+       .byte   0xf3,0xc3
+.size  padlock_aes_block,.-padlock_aes_block
+
+.globl padlock_xstore
+.type  padlock_xstore,@function
+.align 16
+padlock_xstore:
+       movl    %esi,%edx
+.byte  0x0f,0xa7,0xc0          
+       .byte   0xf3,0xc3
+.size  padlock_xstore,.-padlock_xstore
+
+.globl padlock_sha1_oneshot
+.type  padlock_sha1_oneshot,@function
+.align 16
+padlock_sha1_oneshot:
+       movq    %rdx,%rcx
+       movq    %rdi,%rdx
+       movups  (%rdi),%xmm0
+       subq    $128+8,%rsp
+       movl    16(%rdi),%eax
+       movaps  %xmm0,(%rsp)
+       movq    %rsp,%rdi
+       movl    %eax,16(%rsp)
+       xorq    %rax,%rax
+.byte  0xf3,0x0f,0xa6,0xc8     
+       movaps  (%rsp),%xmm0
+       movl    16(%rsp),%eax
+       addq    $128+8,%rsp
+       movups  %xmm0,(%rdx)
+       movl    %eax,16(%rdx)
+       .byte   0xf3,0xc3
+.size  padlock_sha1_oneshot,.-padlock_sha1_oneshot
+
+.globl padlock_sha1_blocks
+.type  padlock_sha1_blocks,@function
+.align 16
+padlock_sha1_blocks:
+       movq    %rdx,%rcx
+       movq    %rdi,%rdx
+       movups  (%rdi),%xmm0
+       subq    $128+8,%rsp
+       movl    16(%rdi),%eax
+       movaps  %xmm0,(%rsp)
+       movq    %rsp,%rdi
+       movl    %eax,16(%rsp)
+       movq    $-1,%rax
+.byte  0xf3,0x0f,0xa6,0xc8     
+       movaps  (%rsp),%xmm0
+       movl    16(%rsp),%eax
+       addq    $128+8,%rsp
+       movups  %xmm0,(%rdx)
+       movl    %eax,16(%rdx)
+       .byte   0xf3,0xc3
+.size  padlock_sha1_blocks,.-padlock_sha1_blocks
+
+.globl padlock_sha256_oneshot
+.type  padlock_sha256_oneshot,@function
+.align 16
+padlock_sha256_oneshot:
+       movq    %rdx,%rcx
+       movq    %rdi,%rdx
+       movups  (%rdi),%xmm0
+       subq    $128+8,%rsp
+       movups  16(%rdi),%xmm1
+       movaps  %xmm0,(%rsp)
+       movq    %rsp,%rdi
+       movaps  %xmm1,16(%rsp)
+       xorq    %rax,%rax
+.byte  0xf3,0x0f,0xa6,0xd0     
+       movaps  (%rsp),%xmm0
+       movaps  16(%rsp),%xmm1
+       addq    $128+8,%rsp
+       movups  %xmm0,(%rdx)
+       movups  %xmm1,16(%rdx)
+       .byte   0xf3,0xc3
+.size  padlock_sha256_oneshot,.-padlock_sha256_oneshot
+
+.globl padlock_sha256_blocks
+.type  padlock_sha256_blocks,@function
+.align 16
+padlock_sha256_blocks:
+       movq    %rdx,%rcx
+       movq    %rdi,%rdx
+       movups  (%rdi),%xmm0
+       subq    $128+8,%rsp
+       movups  16(%rdi),%xmm1
+       movaps  %xmm0,(%rsp)
+       movq    %rsp,%rdi
+       movaps  %xmm1,16(%rsp)
+       movq    $-1,%rax
+.byte  0xf3,0x0f,0xa6,0xd0     
+       movaps  (%rsp),%xmm0
+       movaps  16(%rsp),%xmm1
+       addq    $128+8,%rsp
+       movups  %xmm0,(%rdx)
+       movups  %xmm1,16(%rdx)
+       .byte   0xf3,0xc3
+.size  padlock_sha256_blocks,.-padlock_sha256_blocks
+
+.globl padlock_sha512_blocks
+.type  padlock_sha512_blocks,@function
+.align 16
+padlock_sha512_blocks:
+       movq    %rdx,%rcx
+       movq    %rdi,%rdx
+       movups  (%rdi),%xmm0
+       subq    $128+8,%rsp
+       movups  16(%rdi),%xmm1
+       movups  32(%rdi),%xmm2
+       movups  48(%rdi),%xmm3
+       movaps  %xmm0,(%rsp)
+       movq    %rsp,%rdi
+       movaps  %xmm1,16(%rsp)
+       movaps  %xmm2,32(%rsp)
+       movaps  %xmm3,48(%rsp)
+.byte  0xf3,0x0f,0xa6,0xe0     
+       movaps  (%rsp),%xmm0
+       movaps  16(%rsp),%xmm1
+       movaps  32(%rsp),%xmm2
+       movaps  48(%rsp),%xmm3
+       addq    $128+8,%rsp
+       movups  %xmm0,(%rdx)
+       movups  %xmm1,16(%rdx)
+       movups  %xmm2,32(%rdx)
+       movups  %xmm3,48(%rdx)
+       .byte   0xf3,0xc3
+.size  padlock_sha512_blocks,.-padlock_sha512_blocks
+.globl padlock_ecb_encrypt
+.type  padlock_ecb_encrypt,@function
+.align 16
+padlock_ecb_encrypt:
+       pushq   %rbp
+       pushq   %rbx
+
+       xorl    %eax,%eax
+       testq   $15,%rdx
+       jnz     .Lecb_abort
+       testq   $15,%rcx
+       jnz     .Lecb_abort
+       leaq    .Lpadlock_saved_context(%rip),%rax
+       pushf
+       cld
+       call    _padlock_verify_ctx
+       leaq    16(%rdx),%rdx
+       xorl    %eax,%eax
+       xorl    %ebx,%ebx
+       cmpq    $128,%rcx
+       jbe     .Lecb_short
+       testl   $32,(%rdx)
+       jnz     .Lecb_aligned
+       testq   $15,%rdi
+       setz    %al
+       testq   $15,%rsi
+       setz    %bl
+       testl   %ebx,%eax
+       jnz     .Lecb_aligned
+       negq    %rax
+       movq    $512,%rbx
+       notq    %rax
+       leaq    (%rsp),%rbp
+       cmpq    %rbx,%rcx
+       cmovcq  %rcx,%rbx
+       andq    %rbx,%rax
+       movq    %rcx,%rbx
+       negq    %rax
+       andq    $512-1,%rbx
+       leaq    (%rax,%rbp,1),%rsp
+       jmp     .Lecb_loop
+.align 16
+.Lecb_loop:
+       cmpq    %rcx,%rbx
+       cmovaq  %rcx,%rbx
+       movq    %rdi,%r8
+       movq    %rsi,%r9
+       movq    %rcx,%r10
+       movq    %rbx,%rcx
+       movq    %rbx,%r11
+       testq   $15,%rdi
+       cmovnzq %rsp,%rdi
+       testq   $15,%rsi
+       jz      .Lecb_inp_aligned
+       shrq    $3,%rcx
+.byte  0xf3,0x48,0xa5          
+       subq    %rbx,%rdi
+       movq    %rbx,%rcx
+       movq    %rdi,%rsi
+.Lecb_inp_aligned:
+       leaq    -16(%rdx),%rax
+       leaq    16(%rdx),%rbx
+       shrq    $4,%rcx
+.byte  0xf3,0x0f,0xa7,200      
+       movq    %r8,%rdi
+       movq    %r11,%rbx
+       testq   $15,%rdi
+       jz      .Lecb_out_aligned
+       movq    %rbx,%rcx
+       shrq    $3,%rcx
+       leaq    (%rsp),%rsi
+.byte  0xf3,0x48,0xa5          
+       subq    %rbx,%rdi
+.Lecb_out_aligned:
+       movq    %r9,%rsi
+       movq    %r10,%rcx
+       addq    %rbx,%rdi
+       addq    %rbx,%rsi
+       subq    %rbx,%rcx
+       movq    $512,%rbx
+       jnz     .Lecb_loop
+
+       cmpq    %rsp,%rbp
+       je      .Lecb_done
+
+       pxor    %xmm0,%xmm0
+       leaq    (%rsp),%rax
+.Lecb_bzero:
+       movaps  %xmm0,(%rax)
+       leaq    16(%rax),%rax
+       cmpq    %rax,%rbp
+       ja      .Lecb_bzero
+
+.Lecb_done:
+       leaq    (%rbp),%rsp
+       jmp     .Lecb_exit
+.align 16
+.Lecb_short:
+       movq    %rsp,%rbp
+       subq    %rcx,%rsp
+       xorq    %rbx,%rbx
+.Lecb_short_copy:
+       movups  (%rsi,%rbx,1),%xmm0
+       leaq    16(%rbx),%rbx
+       cmpq    %rbx,%rcx
+       movaps  %xmm0,-16(%rsp,%rbx,1)
+       ja      .Lecb_short_copy
+       movq    %rsp,%rsi
+       movq    %rcx,%rbx
+       jmp     .Lecb_loop
+.align 16
+.Lecb_aligned:
+       leaq    -16(%rdx),%rax
+       leaq    16(%rdx),%rbx
+       shrq    $4,%rcx
+.byte  0xf3,0x0f,0xa7,200      
+.Lecb_exit:
+       movl    $1,%eax
+       leaq    8(%rsp),%rsp
+.Lecb_abort:
+       popq    %rbx
+       popq    %rbp
+       .byte   0xf3,0xc3
+.size  padlock_ecb_encrypt,.-padlock_ecb_encrypt
+.globl padlock_cbc_encrypt
+.type  padlock_cbc_encrypt,@function
+.align 16
+padlock_cbc_encrypt:
+       pushq   %rbp
+       pushq   %rbx
+
+       xorl    %eax,%eax
+       testq   $15,%rdx
+       jnz     .Lcbc_abort
+       testq   $15,%rcx
+       jnz     .Lcbc_abort
+       leaq    .Lpadlock_saved_context(%rip),%rax
+       pushf
+       cld
+       call    _padlock_verify_ctx
+       leaq    16(%rdx),%rdx
+       xorl    %eax,%eax
+       xorl    %ebx,%ebx
+       cmpq    $64,%rcx
+       jbe     .Lcbc_short
+       testl   $32,(%rdx)
+       jnz     .Lcbc_aligned
+       testq   $15,%rdi
+       setz    %al
+       testq   $15,%rsi
+       setz    %bl
+       testl   %ebx,%eax
+       jnz     .Lcbc_aligned
+       negq    %rax
+       movq    $512,%rbx
+       notq    %rax
+       leaq    (%rsp),%rbp
+       cmpq    %rbx,%rcx
+       cmovcq  %rcx,%rbx
+       andq    %rbx,%rax
+       movq    %rcx,%rbx
+       negq    %rax
+       andq    $512-1,%rbx
+       leaq    (%rax,%rbp,1),%rsp
+       jmp     .Lcbc_loop
+.align 16
+.Lcbc_loop:
+       cmpq    %rcx,%rbx
+       cmovaq  %rcx,%rbx
+       movq    %rdi,%r8
+       movq    %rsi,%r9
+       movq    %rcx,%r10
+       movq    %rbx,%rcx
+       movq    %rbx,%r11
+       testq   $15,%rdi
+       cmovnzq %rsp,%rdi
+       testq   $15,%rsi
+       jz      .Lcbc_inp_aligned
+       shrq    $3,%rcx
+.byte  0xf3,0x48,0xa5          
+       subq    %rbx,%rdi
+       movq    %rbx,%rcx
+       movq    %rdi,%rsi
+.Lcbc_inp_aligned:
+       leaq    -16(%rdx),%rax
+       leaq    16(%rdx),%rbx
+       shrq    $4,%rcx
+.byte  0xf3,0x0f,0xa7,208      
+       movdqa  (%rax),%xmm0
+       movdqa  %xmm0,-16(%rdx)
+       movq    %r8,%rdi
+       movq    %r11,%rbx
+       testq   $15,%rdi
+       jz      .Lcbc_out_aligned
+       movq    %rbx,%rcx
+       shrq    $3,%rcx
+       leaq    (%rsp),%rsi
+.byte  0xf3,0x48,0xa5          
+       subq    %rbx,%rdi
+.Lcbc_out_aligned:
+       movq    %r9,%rsi
+       movq    %r10,%rcx
+       addq    %rbx,%rdi
+       addq    %rbx,%rsi
+       subq    %rbx,%rcx
+       movq    $512,%rbx
+       jnz     .Lcbc_loop
+
+       cmpq    %rsp,%rbp
+       je      .Lcbc_done
+
+       pxor    %xmm0,%xmm0
+       leaq    (%rsp),%rax
+.Lcbc_bzero:
+       movaps  %xmm0,(%rax)
+       leaq    16(%rax),%rax
+       cmpq    %rax,%rbp
+       ja      .Lcbc_bzero
+
+.Lcbc_done:
+       leaq    (%rbp),%rsp
+       jmp     .Lcbc_exit
+.align 16
+.Lcbc_short:
+       movq    %rsp,%rbp
+       subq    %rcx,%rsp
+       xorq    %rbx,%rbx
+.Lcbc_short_copy:
+       movups  (%rsi,%rbx,1),%xmm0
+       leaq    16(%rbx),%rbx
+       cmpq    %rbx,%rcx
+       movaps  %xmm0,-16(%rsp,%rbx,1)
+       ja      .Lcbc_short_copy
+       movq    %rsp,%rsi
+       movq    %rcx,%rbx
+       jmp     .Lcbc_loop
+.align 16
+.Lcbc_aligned:
+       leaq    -16(%rdx),%rax
+       leaq    16(%rdx),%rbx
+       shrq    $4,%rcx
+.byte  0xf3,0x0f,0xa7,208      
+       movdqa  (%rax),%xmm0
+       movdqa  %xmm0,-16(%rdx)
+.Lcbc_exit:
+       movl    $1,%eax
+       leaq    8(%rsp),%rsp
+.Lcbc_abort:
+       popq    %rbx
+       popq    %rbp
+       .byte   0xf3,0xc3
+.size  padlock_cbc_encrypt,.-padlock_cbc_encrypt
+.byte  
86,73,65,32,80,97,100,108,111,99,107,32,120,56,54,95,54,52,32,109,111,100,117,108,101,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
+.align 16
+.data  
+.align 8
+.Lpadlock_saved_context:
+.quad  0
+
+#if defined(__ELF__)
+.section .note.GNU-stack,"",%progbits
+#endif
diff --git a/lib/accelerated/x86/asm/padlock-x86.s 
b/lib/accelerated/x86/asm/padlock-x86.s
new file mode 100644
index 0000000..b2fca21
--- /dev/null
+++ b/lib/accelerated/x86/asm/padlock-x86.s
@@ -0,0 +1,625 @@
+# Copyright (c) 2011, Andy Polyakov by <address@hidden>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 
+#     * Redistributions of source code must retain copyright notices,
+#      this list of conditions and the following disclaimer.
+#
+#     * Redistributions in binary form must reproduce the above
+#      copyright notice, this list of conditions and the following
+#      disclaimer in the documentation and/or other materials
+#      provided with the distribution.
+#
+#     * Neither the name of the Andy Polyakov nor the names of its
+#      copyright holder and contributors may be used to endorse or
+#      promote products derived from this software without specific
+#      prior written permission.
+#
+# ALTERNATIVELY, provided that this notice is retained in full, this
+# product may be distributed under the terms of the GNU General Public
+# License (GPL), in which case the provisions of the GPL apply INSTEAD OF
+# those given above.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.file  "padlock-x86.s"
+.text
+.globl padlock_capability
+.type  padlock_capability,@function
+.align 16
+padlock_capability:
+.L_padlock_capability_begin:
+       pushl   %ebx
+       pushfl
+       popl    %eax
+       movl    %eax,%ecx
+       xorl    $2097152,%eax
+       pushl   %eax
+       popfl
+       pushfl
+       popl    %eax
+       xorl    %eax,%ecx
+       xorl    %eax,%eax
+       btl     $21,%ecx
+       jnc     .L000noluck
+       .byte   0x0f,0xa2
+       xorl    %eax,%eax
+       cmpl    $0x746e6543,%ebx
+       jne     .L000noluck
+       cmpl    $0x48727561,%edx
+       jne     .L000noluck
+       cmpl    $0x736c7561,%ecx
+       jne     .L000noluck
+       movl    $3221225472,%eax
+       .byte   0x0f,0xa2
+       movl    %eax,%edx
+       xorl    %eax,%eax
+       cmpl    $3221225473,%edx
+       jb      .L000noluck
+       movl    $1,%eax
+       .byte   0x0f,0xa2
+       orl     $15,%eax
+       xorl    %ebx,%ebx
+       andl    $4095,%eax
+       cmpl    $1791,%eax
+       sete    %bl
+       movl    $3221225473,%eax
+       pushl   %ebx
+       .byte   0x0f,0xa2
+       popl    %ebx
+       movl    %edx,%eax
+       shll    $4,%ebx
+       andl    $4294967279,%eax
+       orl     %ebx,%eax
+.L000noluck:
+       popl    %ebx
+       ret
+.size  padlock_capability,.-.L_padlock_capability_begin
+.globl padlock_key_bswap
+.type  padlock_key_bswap,@function
+.align 16
+padlock_key_bswap:
+.L_padlock_key_bswap_begin:
+       movl    4(%esp),%edx
+       movl    240(%edx),%ecx
+.L001bswap_loop:
+       movl    (%edx),%eax
+       bswap   %eax
+       movl    %eax,(%edx)
+       leal    4(%edx),%edx
+       subl    $1,%ecx
+       jnz     .L001bswap_loop
+       ret
+.size  padlock_key_bswap,.-.L_padlock_key_bswap_begin
+.globl padlock_verify_context
+.type  padlock_verify_context,@function
+.align 16
+padlock_verify_context:
+.L_padlock_verify_context_begin:
+       movl    4(%esp),%edx
+       leal    .Lpadlock_saved_context-.L002verify_pic_point,%eax
+       pushfl
+       call    _padlock_verify_ctx
+.L002verify_pic_point:
+       leal    4(%esp),%esp
+       ret
+.size  padlock_verify_context,.-.L_padlock_verify_context_begin
+.type  _padlock_verify_ctx,@function
+.align 16
+_padlock_verify_ctx:
+       addl    (%esp),%eax
+       btl     $30,4(%esp)
+       jnc     .L003verified
+       cmpl    (%eax),%edx
+       je      .L003verified
+       pushfl
+       popfl
+.L003verified:
+       movl    %edx,(%eax)
+       ret
+.size  _padlock_verify_ctx,.-_padlock_verify_ctx
+.globl padlock_reload_key
+.type  padlock_reload_key,@function
+.align 16
+padlock_reload_key:
+.L_padlock_reload_key_begin:
+       pushfl
+       popfl
+       ret
+.size  padlock_reload_key,.-.L_padlock_reload_key_begin
+.globl padlock_aes_block
+.type  padlock_aes_block,@function
+.align 16
+padlock_aes_block:
+.L_padlock_aes_block_begin:
+       pushl   %edi
+       pushl   %esi
+       pushl   %ebx
+       movl    16(%esp),%edi
+       movl    20(%esp),%esi
+       movl    24(%esp),%edx
+       movl    $1,%ecx
+       leal    32(%edx),%ebx
+       leal    16(%edx),%edx
+.byte  243,15,167,200
+       popl    %ebx
+       popl    %esi
+       popl    %edi
+       ret
+.size  padlock_aes_block,.-.L_padlock_aes_block_begin
+.globl padlock_ecb_encrypt
+.type  padlock_ecb_encrypt,@function
+.align 16
+padlock_ecb_encrypt:
+.L_padlock_ecb_encrypt_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%edi
+       movl    24(%esp),%esi
+       movl    28(%esp),%edx
+       movl    32(%esp),%ecx
+       testl   $15,%edx
+       jnz     .L004ecb_abort
+       testl   $15,%ecx
+       jnz     .L004ecb_abort
+       leal    .Lpadlock_saved_context-.L005ecb_pic_point,%eax
+       pushfl
+       cld
+       call    _padlock_verify_ctx
+.L005ecb_pic_point:
+       leal    16(%edx),%edx
+       xorl    %eax,%eax
+       xorl    %ebx,%ebx
+       cmpl    $128,%ecx
+       jbe     .L006ecb_short
+       testl   $32,(%edx)
+       jnz     .L007ecb_aligned
+       testl   $15,%edi
+       setz    %al
+       testl   $15,%esi
+       setz    %bl
+       testl   %ebx,%eax
+       jnz     .L007ecb_aligned
+       negl    %eax
+       movl    $512,%ebx
+       notl    %eax
+       leal    -24(%esp),%ebp
+       cmpl    %ebx,%ecx
+       cmovcl  %ecx,%ebx
+       andl    %ebx,%eax
+       movl    %ecx,%ebx
+       negl    %eax
+       andl    $511,%ebx
+       leal    (%eax,%ebp,1),%esp
+       andl    $-16,%esp
+       jmp     .L008ecb_loop
+.align 16
+.L008ecb_loop:
+       movl    %edi,(%ebp)
+       movl    %esi,4(%ebp)
+       movl    %ecx,8(%ebp)
+       movl    %ebx,%ecx
+       movl    %ebx,12(%ebp)
+       testl   $15,%edi
+       cmovnzl %esp,%edi
+       testl   $15,%esi
+       jz      .L009ecb_inp_aligned
+       shrl    $2,%ecx
+.byte  243,165
+       subl    %ebx,%edi
+       movl    %ebx,%ecx
+       movl    %edi,%esi
+.L009ecb_inp_aligned:
+       leal    -16(%edx),%eax
+       leal    16(%edx),%ebx
+       shrl    $4,%ecx
+.byte  243,15,167,200
+       movl    (%ebp),%edi
+       movl    12(%ebp),%ebx
+       testl   $15,%edi
+       jz      .L010ecb_out_aligned
+       movl    %ebx,%ecx
+       shrl    $2,%ecx
+       leal    (%esp),%esi
+.byte  243,165
+       subl    %ebx,%edi
+.L010ecb_out_aligned:
+       movl    4(%ebp),%esi
+       movl    8(%ebp),%ecx
+       addl    %ebx,%edi
+       addl    %ebx,%esi
+       subl    %ebx,%ecx
+       movl    $512,%ebx
+       jnz     .L008ecb_loop
+       cmpl    %ebp,%esp
+       je      .L011ecb_done
+       pxor    %xmm0,%xmm0
+       leal    (%esp),%eax
+.L012ecb_bzero:
+       movaps  %xmm0,(%eax)
+       leal    16(%eax),%eax
+       cmpl    %eax,%ebp
+       ja      .L012ecb_bzero
+.L011ecb_done:
+       leal    24(%ebp),%esp
+       jmp     .L013ecb_exit
+.align 16
+.L006ecb_short:
+       xorl    %eax,%eax
+       leal    -24(%esp),%ebp
+       subl    %ecx,%eax
+       leal    (%eax,%ebp,1),%esp
+       andl    $-16,%esp
+       xorl    %ebx,%ebx
+.L014ecb_short_copy:
+       movups  (%esi,%ebx,1),%xmm0
+       leal    16(%ebx),%ebx
+       cmpl    %ebx,%ecx
+       movaps  %xmm0,-16(%esp,%ebx,1)
+       ja      .L014ecb_short_copy
+       movl    %esp,%esi
+       movl    %ecx,%ebx
+       jmp     .L008ecb_loop
+.align 16
+.L007ecb_aligned:
+       leal    -16(%edx),%eax
+       leal    16(%edx),%ebx
+       shrl    $4,%ecx
+.byte  243,15,167,200
+.L013ecb_exit:
+       movl    $1,%eax
+       leal    4(%esp),%esp
+.L004ecb_abort:
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.size  padlock_ecb_encrypt,.-.L_padlock_ecb_encrypt_begin
+.globl padlock_cbc_encrypt
+.type  padlock_cbc_encrypt,@function
+.align 16
+padlock_cbc_encrypt:
+.L_padlock_cbc_encrypt_begin:
+       pushl   %ebp
+       pushl   %ebx
+       pushl   %esi
+       pushl   %edi
+       movl    20(%esp),%edi
+       movl    24(%esp),%esi
+       movl    28(%esp),%edx
+       movl    32(%esp),%ecx
+       testl   $15,%edx
+       jnz     .L015cbc_abort
+       testl   $15,%ecx
+       jnz     .L015cbc_abort
+       leal    .Lpadlock_saved_context-.L016cbc_pic_point,%eax
+       pushfl
+       cld
+       call    _padlock_verify_ctx
+.L016cbc_pic_point:
+       leal    16(%edx),%edx
+       xorl    %eax,%eax
+       xorl    %ebx,%ebx
+       cmpl    $64,%ecx
+       jbe     .L017cbc_short
+       testl   $32,(%edx)
+       jnz     .L018cbc_aligned
+       testl   $15,%edi
+       setz    %al
+       testl   $15,%esi
+       setz    %bl
+       testl   %ebx,%eax
+       jnz     .L018cbc_aligned
+       negl    %eax
+       movl    $512,%ebx
+       notl    %eax
+       leal    -24(%esp),%ebp
+       cmpl    %ebx,%ecx
+       cmovcl  %ecx,%ebx
+       andl    %ebx,%eax
+       movl    %ecx,%ebx
+       negl    %eax
+       andl    $511,%ebx
+       leal    (%eax,%ebp,1),%esp
+       andl    $-16,%esp
+       jmp     .L019cbc_loop
+.align 16
+.L019cbc_loop:
+       movl    %edi,(%ebp)
+       movl    %esi,4(%ebp)
+       movl    %ecx,8(%ebp)
+       movl    %ebx,%ecx
+       movl    %ebx,12(%ebp)
+       testl   $15,%edi
+       cmovnzl %esp,%edi
+       testl   $15,%esi
+       jz      .L020cbc_inp_aligned
+       shrl    $2,%ecx
+.byte  243,165
+       subl    %ebx,%edi
+       movl    %ebx,%ecx
+       movl    %edi,%esi
+.L020cbc_inp_aligned:
+       leal    -16(%edx),%eax
+       leal    16(%edx),%ebx
+       shrl    $4,%ecx
+.byte  243,15,167,208
+       movaps  (%eax),%xmm0
+       movaps  %xmm0,-16(%edx)
+       movl    (%ebp),%edi
+       movl    12(%ebp),%ebx
+       testl   $15,%edi
+       jz      .L021cbc_out_aligned
+       movl    %ebx,%ecx
+       shrl    $2,%ecx
+       leal    (%esp),%esi
+.byte  243,165
+       subl    %ebx,%edi
+.L021cbc_out_aligned:
+       movl    4(%ebp),%esi
+       movl    8(%ebp),%ecx
+       addl    %ebx,%edi
+       addl    %ebx,%esi
+       subl    %ebx,%ecx
+       movl    $512,%ebx
+       jnz     .L019cbc_loop
+       cmpl    %ebp,%esp
+       je      .L022cbc_done
+       pxor    %xmm0,%xmm0
+       leal    (%esp),%eax
+.L023cbc_bzero:
+       movaps  %xmm0,(%eax)
+       leal    16(%eax),%eax
+       cmpl    %eax,%ebp
+       ja      .L023cbc_bzero
+.L022cbc_done:
+       leal    24(%ebp),%esp
+       jmp     .L024cbc_exit
+.align 16
+.L017cbc_short:
+       xorl    %eax,%eax
+       leal    -24(%esp),%ebp
+       subl    %ecx,%eax
+       leal    (%eax,%ebp,1),%esp
+       andl    $-16,%esp
+       xorl    %ebx,%ebx
+.L025cbc_short_copy:
+       movups  (%esi,%ebx,1),%xmm0
+       leal    16(%ebx),%ebx
+       cmpl    %ebx,%ecx
+       movaps  %xmm0,-16(%esp,%ebx,1)
+       ja      .L025cbc_short_copy
+       movl    %esp,%esi
+       movl    %ecx,%ebx
+       jmp     .L019cbc_loop
+.align 16
+.L018cbc_aligned:
+       leal    -16(%edx),%eax
+       leal    16(%edx),%ebx
+       shrl    $4,%ecx
+.byte  243,15,167,208
+       movaps  (%eax),%xmm0
+       movaps  %xmm0,-16(%edx)
+.L024cbc_exit:
+       movl    $1,%eax
+       leal    4(%esp),%esp
+.L015cbc_abort:
+       popl    %edi
+       popl    %esi
+       popl    %ebx
+       popl    %ebp
+       ret
+.size  padlock_cbc_encrypt,.-.L_padlock_cbc_encrypt_begin
+.globl padlock_xstore
+.type  padlock_xstore,@function
+.align 16
+padlock_xstore:
+.L_padlock_xstore_begin:
+       pushl   %edi
+       movl    8(%esp),%edi
+       movl    12(%esp),%edx
+.byte  15,167,192
+       popl    %edi
+       ret
+.size  padlock_xstore,.-.L_padlock_xstore_begin
+.type  _win32_segv_handler,@function
+.align 16
+_win32_segv_handler:
+       movl    $1,%eax
+       movl    4(%esp),%edx
+       movl    12(%esp),%ecx
+       cmpl    $3221225477,(%edx)
+       jne     .L026ret
+       addl    $4,184(%ecx)
+       movl    $0,%eax
+.L026ret:
+       ret
+.size  _win32_segv_handler,.-_win32_segv_handler
+.globl padlock_sha1_oneshot
+.type  padlock_sha1_oneshot,@function
+.align 16
+padlock_sha1_oneshot:
+.L_padlock_sha1_oneshot_begin:
+       pushl   %edi
+       pushl   %esi
+       xorl    %eax,%eax
+       movl    12(%esp),%edi
+       movl    16(%esp),%esi
+       movl    20(%esp),%ecx
+       movl    %esp,%edx
+       addl    $-128,%esp
+       movups  (%edi),%xmm0
+       andl    $-16,%esp
+       movl    16(%edi),%eax
+       movaps  %xmm0,(%esp)
+       movl    %esp,%edi
+       movl    %eax,16(%esp)
+       xorl    %eax,%eax
+.byte  243,15,166,200
+       movaps  (%esp),%xmm0
+       movl    16(%esp),%eax
+       movl    %edx,%esp
+       movl    12(%esp),%edi
+       movups  %xmm0,(%edi)
+       movl    %eax,16(%edi)
+       popl    %esi
+       popl    %edi
+       ret
+.size  padlock_sha1_oneshot,.-.L_padlock_sha1_oneshot_begin
+.globl padlock_sha1_blocks
+.type  padlock_sha1_blocks,@function
+.align 16
+padlock_sha1_blocks:
+.L_padlock_sha1_blocks_begin:
+       pushl   %edi
+       pushl   %esi
+       movl    12(%esp),%edi
+       movl    16(%esp),%esi
+       movl    %esp,%edx
+       movl    20(%esp),%ecx
+       addl    $-128,%esp
+       movups  (%edi),%xmm0
+       andl    $-16,%esp
+       movl    16(%edi),%eax
+       movaps  %xmm0,(%esp)
+       movl    %esp,%edi
+       movl    %eax,16(%esp)
+       movl    $-1,%eax
+.byte  243,15,166,200
+       movaps  (%esp),%xmm0
+       movl    16(%esp),%eax
+       movl    %edx,%esp
+       movl    12(%esp),%edi
+       movups  %xmm0,(%edi)
+       movl    %eax,16(%edi)
+       popl    %esi
+       popl    %edi
+       ret
+.size  padlock_sha1_blocks,.-.L_padlock_sha1_blocks_begin
+.globl padlock_sha256_oneshot
+.type  padlock_sha256_oneshot,@function
+.align 16
+padlock_sha256_oneshot:
+.L_padlock_sha256_oneshot_begin:
+       pushl   %edi
+       pushl   %esi
+       xorl    %eax,%eax
+       movl    12(%esp),%edi
+       movl    16(%esp),%esi
+       movl    20(%esp),%ecx
+       movl    %esp,%edx
+       addl    $-128,%esp
+       movups  (%edi),%xmm0
+       andl    $-16,%esp
+       movups  16(%edi),%xmm1
+       movaps  %xmm0,(%esp)
+       movl    %esp,%edi
+       movaps  %xmm1,16(%esp)
+       xorl    %eax,%eax
+.byte  243,15,166,208
+       movaps  (%esp),%xmm0
+       movaps  16(%esp),%xmm1
+       movl    %edx,%esp
+       movl    12(%esp),%edi
+       movups  %xmm0,(%edi)
+       movups  %xmm1,16(%edi)
+       popl    %esi
+       popl    %edi
+       ret
+.size  padlock_sha256_oneshot,.-.L_padlock_sha256_oneshot_begin
+.globl padlock_sha256_blocks
+.type  padlock_sha256_blocks,@function
+.align 16
+padlock_sha256_blocks:
+.L_padlock_sha256_blocks_begin:
+       pushl   %edi
+       pushl   %esi
+       movl    12(%esp),%edi
+       movl    16(%esp),%esi
+       movl    20(%esp),%ecx
+       movl    %esp,%edx
+       addl    $-128,%esp
+       movups  (%edi),%xmm0
+       andl    $-16,%esp
+       movups  16(%edi),%xmm1
+       movaps  %xmm0,(%esp)
+       movl    %esp,%edi
+       movaps  %xmm1,16(%esp)
+       movl    $-1,%eax
+.byte  243,15,166,208
+       movaps  (%esp),%xmm0
+       movaps  16(%esp),%xmm1
+       movl    %edx,%esp
+       movl    12(%esp),%edi
+       movups  %xmm0,(%edi)
+       movups  %xmm1,16(%edi)
+       popl    %esi
+       popl    %edi
+       ret
+.size  padlock_sha256_blocks,.-.L_padlock_sha256_blocks_begin
+.globl padlock_sha512_blocks
+.type  padlock_sha512_blocks,@function
+.align 16
+padlock_sha512_blocks:
+.L_padlock_sha512_blocks_begin:
+       pushl   %edi
+       pushl   %esi
+       movl    12(%esp),%edi
+       movl    16(%esp),%esi
+       movl    20(%esp),%ecx
+       movl    %esp,%edx
+       addl    $-128,%esp
+       movups  (%edi),%xmm0
+       andl    $-16,%esp
+       movups  16(%edi),%xmm1
+       movups  32(%edi),%xmm2
+       movups  48(%edi),%xmm3
+       movaps  %xmm0,(%esp)
+       movl    %esp,%edi
+       movaps  %xmm1,16(%esp)
+       movaps  %xmm2,32(%esp)
+       movaps  %xmm3,48(%esp)
+.byte  243,15,166,224
+       movaps  (%esp),%xmm0
+       movaps  16(%esp),%xmm1
+       movaps  32(%esp),%xmm2
+       movaps  48(%esp),%xmm3
+       movl    %edx,%esp
+       movl    12(%esp),%edi
+       movups  %xmm0,(%edi)
+       movups  %xmm1,16(%edi)
+       movups  %xmm2,32(%edi)
+       movups  %xmm3,48(%edi)
+       popl    %esi
+       popl    %edi
+       ret
+.size  padlock_sha512_blocks,.-.L_padlock_sha512_blocks_begin
+.byte  86,73,65,32,80,97,100,108,111,99,107,32,120,56,54,32
+.byte  109,111,100,117,108,101,44,32,67,82,89,80,84,79,71,65
+.byte  77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101
+.byte  110,115,115,108,46,111,114,103,62,0
+.align 16
+.data
+.align 4
+.Lpadlock_saved_context:
+.long  0
+
+#if defined(__ELF__)
+.section .note.GNU-stack,"",%progbits
+#endif
diff --git a/lib/accelerated/x86/hmac-padlock.c 
b/lib/accelerated/x86/hmac-padlock.c
new file mode 100644
index 0000000..7b7a294
--- /dev/null
+++ b/lib/accelerated/x86/hmac-padlock.c
@@ -0,0 +1,372 @@
+/*
+ * Copyright (C) 2008, 2010, 2011 Free Software Foundation, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GNUTLS.
+ *
+ * The GNUTLS library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+/* This file provides is the backend hash/mac API for libgcrypt.
+ */
+
+#include <gnutls_int.h>
+#include <gnutls_hash_int.h>
+#include <gnutls_errors.h>
+#include <nettle/sha.h>
+#include <nettle/hmac.h>
+#include <nettle/macros.h>
+#include <aes-padlock.h>
+#include <sha-padlock.h>
+
+#ifdef HAVE_LIBNETTLE
+
+#define IPAD 0x36
+#define OPAD 0x5c
+#define MAX_SHA_DIGEST_SIZE (512/8)
+
+typedef void (*update_func) (void *, unsigned, const uint8_t *);
+typedef void (*digest_func) (void *, unsigned, uint8_t *);
+typedef void (*set_key_func) (void *, unsigned, const uint8_t *);
+
+struct padlock_hmac_ctx
+{
+    union
+    {
+        struct hmac_sha224_ctx sha224;
+        struct hmac_sha256_ctx sha256;
+        struct hmac_sha384_ctx sha384;
+        struct hmac_sha512_ctx sha512;
+        struct hmac_sha1_ctx sha1;
+    } ctx;
+
+    /* this is the context just after
+     * the set_key. Used in reset().
+     */
+    union
+    {
+        struct hmac_sha224_ctx sha224;
+        struct hmac_sha256_ctx sha256;
+        struct hmac_sha384_ctx sha384;
+        struct hmac_sha512_ctx sha512;
+        struct hmac_sha1_ctx sha1;
+    } init_ctx;
+    void *ctx_ptr;
+    gnutls_mac_algorithm_t algo;
+    size_t length;
+    update_func update;
+    digest_func digest;
+    set_key_func setkey;
+};
+
+static void
+padlock_hmac_sha1_set_key (struct hmac_sha1_ctx *ctx,
+                           unsigned key_length, const uint8_t * key)
+{
+    HMAC_SET_KEY (ctx, &padlock_sha1, key_length, key);
+}
+
+static void
+padlock_hmac_sha1_update (struct hmac_sha1_ctx *ctx,
+                          unsigned length, const uint8_t * data)
+{
+    padlock_sha1_update (&ctx->state, length, data);
+}
+
+static void
+padlock_hmac_sha1_digest (struct hmac_sha1_ctx *ctx,
+                          unsigned length, uint8_t * digest)
+{
+    HMAC_DIGEST (ctx, &padlock_sha1, length, digest);
+}
+
+static void
+padlock_hmac_sha256_set_key (struct hmac_sha256_ctx *ctx,
+                             unsigned key_length, const uint8_t * key)
+{
+    HMAC_SET_KEY (ctx, &padlock_sha256, key_length, key);
+}
+
+static void
+padlock_hmac_sha256_update (struct hmac_sha256_ctx *ctx,
+                            unsigned length, const uint8_t * data)
+{
+    padlock_sha256_update (&ctx->state, length, data);
+}
+
+static void
+padlock_hmac_sha256_digest (struct hmac_sha256_ctx *ctx,
+                            unsigned length, uint8_t * digest)
+{
+    HMAC_DIGEST (ctx, &padlock_sha256, length, digest);
+}
+
+static void
+padlock_hmac_sha224_set_key (struct hmac_sha224_ctx *ctx,
+                             unsigned key_length, const uint8_t * key)
+{
+    HMAC_SET_KEY (ctx, &padlock_sha224, key_length, key);
+}
+
+static void
+padlock_hmac_sha224_digest (struct hmac_sha224_ctx *ctx,
+                            unsigned length, uint8_t * digest)
+{
+    HMAC_DIGEST (ctx, &padlock_sha224, length, digest);
+}
+
+static void
+padlock_hmac_sha384_set_key (struct hmac_sha384_ctx *ctx,
+                             unsigned key_length, const uint8_t * key)
+{
+    HMAC_SET_KEY (ctx, &padlock_sha384, key_length, key);
+}
+
+static void
+padlock_hmac_sha384_digest (struct hmac_sha384_ctx *ctx,
+                            unsigned length, uint8_t * digest)
+{
+    HMAC_DIGEST (ctx, &padlock_sha384, length, digest);
+}
+
+static void
+padlock_hmac_sha512_set_key (struct hmac_sha512_ctx *ctx,
+                             unsigned key_length, const uint8_t * key)
+{
+    HMAC_SET_KEY (ctx, &padlock_sha512, key_length, key);
+}
+
+static void
+padlock_hmac_sha512_update (struct hmac_sha512_ctx *ctx,
+                            unsigned length, const uint8_t * data)
+{
+    padlock_sha512_update (&ctx->state, length, data);
+}
+
+static void
+padlock_hmac_sha512_digest (struct hmac_sha512_ctx *ctx,
+                            unsigned length, uint8_t * digest)
+{
+    HMAC_DIGEST (ctx, &padlock_sha512, length, digest);
+}
+
+static int
+_hmac_ctx_init (gnutls_mac_algorithm_t algo, struct padlock_hmac_ctx *ctx)
+{
+    switch (algo)
+      {
+      case GNUTLS_MAC_SHA1:
+          ctx->update = (update_func) padlock_hmac_sha1_update;
+          ctx->digest = (digest_func) padlock_hmac_sha1_digest;
+          ctx->setkey = (set_key_func) padlock_hmac_sha1_set_key;
+          ctx->ctx_ptr = &ctx->ctx.sha1;
+          ctx->length = SHA1_DIGEST_SIZE;
+          break;
+      case GNUTLS_MAC_SHA224:
+          ctx->update = (update_func) padlock_hmac_sha256_update;
+          ctx->digest = (digest_func) padlock_hmac_sha224_digest;
+          ctx->setkey = (set_key_func) padlock_hmac_sha224_set_key;
+          ctx->ctx_ptr = &ctx->ctx.sha224;
+          ctx->length = SHA224_DIGEST_SIZE;
+          break;
+      case GNUTLS_MAC_SHA256:
+          ctx->update = (update_func) padlock_hmac_sha256_update;
+          ctx->digest = (digest_func) padlock_hmac_sha256_digest;
+          ctx->setkey = (set_key_func) padlock_hmac_sha256_set_key;
+          ctx->ctx_ptr = &ctx->ctx.sha256;
+          ctx->length = SHA256_DIGEST_SIZE;
+          break;
+      case GNUTLS_MAC_SHA384:
+          ctx->update = (update_func) padlock_hmac_sha512_update;
+          ctx->digest = (digest_func) padlock_hmac_sha384_digest;
+          ctx->setkey = (set_key_func) padlock_hmac_sha384_set_key;
+          ctx->ctx_ptr = &ctx->ctx.sha384;
+          ctx->length = SHA384_DIGEST_SIZE;
+          break;
+      case GNUTLS_MAC_SHA512:
+          ctx->update = (update_func) padlock_hmac_sha512_update;
+          ctx->digest = (digest_func) padlock_hmac_sha512_digest;
+          ctx->setkey = (set_key_func) padlock_hmac_sha512_set_key;
+          ctx->ctx_ptr = &ctx->ctx.sha512;
+          ctx->length = SHA512_DIGEST_SIZE;
+          break;
+      default:
+          gnutls_assert ();
+          return GNUTLS_E_INVALID_REQUEST;
+      }
+
+    return 0;
+}
+
+
+static int
+wrap_padlock_hmac_init (gnutls_mac_algorithm_t algo, void **_ctx)
+{
+    struct padlock_hmac_ctx *ctx;
+    int ret;
+
+    ctx = gnutls_calloc (1, sizeof (struct padlock_hmac_ctx));
+    if (ctx == NULL)
+      {
+          gnutls_assert ();
+          return GNUTLS_E_MEMORY_ERROR;
+      }
+
+    ctx->algo = algo;
+
+    ret = _hmac_ctx_init (algo, ctx);
+    if (ret < 0)
+        return gnutls_assert_val (ret);
+
+    *_ctx = ctx;
+
+    return 0;
+}
+
+static int
+wrap_padlock_hmac_setkey (void *_ctx, const void *key, size_t keylen)
+{
+    struct padlock_hmac_ctx *ctx = _ctx;
+
+    ctx->setkey (ctx->ctx_ptr, keylen, key);
+
+    memcpy (&ctx->init_ctx, &ctx->ctx, sizeof (ctx->ctx));
+
+    return GNUTLS_E_SUCCESS;
+}
+
+static void
+wrap_padlock_hmac_reset (void *_ctx)
+{
+    struct padlock_hmac_ctx *ctx = _ctx;
+
+    memcpy (&ctx->ctx, &ctx->init_ctx, sizeof (ctx->ctx));
+}
+
+static int
+wrap_padlock_hmac_update (void *_ctx, const void *text, size_t textsize)
+{
+    struct padlock_hmac_ctx *ctx = _ctx;
+
+    ctx->update (ctx->ctx_ptr, textsize, text);
+
+    return GNUTLS_E_SUCCESS;
+}
+
+static int
+wrap_padlock_hmac_output (void *src_ctx, void *digest, size_t digestsize)
+{
+    struct padlock_hmac_ctx *ctx;
+    ctx = src_ctx;
+
+    if (digestsize < ctx->length)
+      {
+          gnutls_assert ();
+          return GNUTLS_E_SHORT_MEMORY_BUFFER;
+      }
+
+    ctx->digest (ctx->ctx_ptr, digestsize, digest);
+
+    return 0;
+}
+
+static void
+wrap_padlock_hmac_deinit (void *hd)
+{
+    gnutls_free (hd);
+}
+
+static int
+wrap_padlock_hmac_fast (gnutls_mac_algorithm_t algo,
+                        const void *key, size_t key_size, const void *text,
+                        size_t text_size, void *digest)
+{
+    if (algo == GNUTLS_MAC_SHA1 || algo == GNUTLS_MAC_SHA256)
+      {
+          unsigned char *pad;
+          unsigned char pad2[SHA1_DATA_SIZE + MAX_SHA_DIGEST_SIZE];
+          unsigned char hkey[MAX_SHA_DIGEST_SIZE];
+          unsigned int digest_size = _gnutls_hmac_get_algo_len (algo);
+
+          if (key_size > SHA1_DATA_SIZE)
+            {
+                wrap_padlock_hash_fast (algo, key, key_size, hkey);
+                key = hkey;
+                key_size = digest_size;
+            }
+
+          pad = gnutls_malloc (text_size + SHA1_DATA_SIZE);
+          if (pad == NULL)
+              return gnutls_assert_val (GNUTLS_E_MEMORY_ERROR);
+
+          memset (pad, IPAD, SHA1_DATA_SIZE);
+          memxor (pad, key, key_size);
+
+          memcpy (&pad[SHA1_DATA_SIZE], text, text_size);
+
+          wrap_padlock_hash_fast (algo, pad, text_size + SHA1_DATA_SIZE,
+                                  &pad2[SHA1_DATA_SIZE]);
+
+          gnutls_free (pad);
+
+          memset (pad2, OPAD, SHA1_DATA_SIZE);
+          memxor (pad2, key, key_size);
+
+          wrap_padlock_hash_fast (algo, pad2, digest_size + SHA1_DATA_SIZE,
+                                  digest);
+
+      }
+    else
+      {
+          struct padlock_hmac_ctx ctx;
+          int ret;
+
+          ret = _hmac_ctx_init (algo, &ctx);
+          if (ret < 0)
+              return gnutls_assert_val (ret);
+          ctx.algo = algo;
+
+          wrap_padlock_hmac_setkey (&ctx, key, key_size);
+
+          wrap_padlock_hmac_update (&ctx, text, text_size);
+
+          wrap_padlock_hmac_output (&ctx, digest, ctx.length);
+      }
+
+    return 0;
+}
+
+const gnutls_crypto_mac_st hmac_sha_padlock_struct = {
+    .init = NULL,
+    .setkey = NULL,
+    .hash = NULL,
+    .reset = NULL,
+    .output = NULL,
+    .deinit = NULL,
+    .fast = wrap_padlock_hmac_fast
+};
+
+const gnutls_crypto_mac_st hmac_sha_padlock_nano_struct = {
+    .init = wrap_padlock_hmac_init,
+    .setkey = wrap_padlock_hmac_setkey,
+    .hash = wrap_padlock_hmac_update,
+    .reset = wrap_padlock_hmac_reset,
+    .output = wrap_padlock_hmac_output,
+    .deinit = wrap_padlock_hmac_deinit,
+    .fast = wrap_padlock_hmac_fast,
+};
+
+#endif /* HAVE_LIBNETTLE */
diff --git a/lib/accelerated/intel/license.txt b/lib/accelerated/x86/license.txt
similarity index 100%
rename from lib/accelerated/intel/license.txt
rename to lib/accelerated/x86/license.txt
diff --git a/lib/accelerated/x86/sha-padlock.c 
b/lib/accelerated/x86/sha-padlock.c
new file mode 100644
index 0000000..becaaf9
--- /dev/null
+++ b/lib/accelerated/x86/sha-padlock.c
@@ -0,0 +1,415 @@
+/*
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ * Portions Copyright (C) 2001 Niels Moeller
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GNUTLS.
+ *
+ * The GNUTLS library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include <gnutls_int.h>
+#include <gnutls_hash_int.h>
+#include <gnutls_errors.h>
+#include <nettle/sha.h>
+#include <nettle/hmac.h>
+#include <nettle/macros.h>
+#include <aes-padlock.h>
+#include <assert.h>
+#include <sha-padlock.h>
+
+#ifdef HAVE_LIBNETTLE
+
+typedef void (*update_func) (void *, unsigned, const uint8_t *);
+typedef void (*digest_func) (void *, unsigned, uint8_t *);
+typedef void (*set_key_func) (void *, unsigned, const uint8_t *);
+
+struct padlock_hash_ctx
+{
+  union
+  {
+    struct sha1_ctx sha1;
+    struct sha224_ctx sha224;
+    struct sha256_ctx sha256;
+    struct sha384_ctx sha384;
+    struct sha512_ctx sha512;
+  } ctx;
+  void *ctx_ptr;
+  gnutls_digest_algorithm_t algo;
+  size_t length;
+  update_func update;
+  digest_func digest;
+};
+
+static int
+wrap_padlock_hash_update (void *_ctx, const void *text, size_t textsize)
+{
+  struct padlock_hash_ctx *ctx = _ctx;
+
+  ctx->update (ctx->ctx_ptr, textsize, text);
+
+  return GNUTLS_E_SUCCESS;
+}
+
+static void
+wrap_padlock_hash_deinit (void *hd)
+{
+  gnutls_free (hd);
+}
+
+#define SHA1_COMPRESS(ctx, data) (padlock_sha1_blocks((void*)(ctx)->state, 
data, 1))
+#define SHA256_COMPRESS(ctx, data) (padlock_sha256_blocks((void*)(ctx)->state, 
data, 1))
+#define SHA512_COMPRESS(ctx, data) (padlock_sha512_blocks((void*)(ctx)->state, 
data, 1))
+
+void
+padlock_sha1_update(struct sha1_ctx *ctx,
+           unsigned length, const uint8_t *data)
+{
+  MD_UPDATE (ctx, length, data, SHA1_COMPRESS, MD_INCR(ctx));
+}
+
+void
+padlock_sha256_update(struct sha256_ctx *ctx,
+             unsigned length, const uint8_t *data)
+{
+  MD_UPDATE (ctx, length, data, SHA256_COMPRESS, MD_INCR(ctx));
+}
+
+void
+padlock_sha512_update(struct sha512_ctx *ctx,
+             unsigned length, const uint8_t *data)
+{
+  MD_UPDATE (ctx, length, data, SHA512_COMPRESS, MD_INCR(ctx));
+}
+
+static void
+_nettle_write_be32(unsigned length, uint8_t *dst,
+                  uint32_t *src)
+{
+  unsigned i;
+  unsigned words;
+  unsigned leftover;
+  
+  words = length / 4;
+  leftover = length % 4;
+
+  for (i = 0; i < words; i++, dst += 4)
+    WRITE_UINT32(dst, src[i]);
+
+  if (leftover)
+    {
+      uint32_t word;
+      unsigned j = leftover;
+      
+      word = src[i];
+      
+      switch (leftover)
+       {
+       default:
+         abort();
+       case 3:
+         dst[--j] = (word >> 8) & 0xff;
+         /* Fall through */
+       case 2:
+         dst[--j] = (word >> 16) & 0xff;
+         /* Fall through */
+       case 1:
+         dst[--j] = (word >> 24) & 0xff;
+       }
+    }
+}
+
+static void
+padlock_sha1_digest(struct sha1_ctx *ctx,
+                   unsigned length, uint8_t *digest)
+{
+  uint32_t high, low;
+
+  assert(length <= SHA1_DIGEST_SIZE);
+
+  MD_PAD(ctx, 8, SHA1_COMPRESS);
+
+  /* There are 512 = 2^9 bits in one block */  
+  high = (ctx->count_high << 9) | (ctx->count_low >> 23);
+  low = (ctx->count_low << 9) | (ctx->index << 3);
+
+  /* append the 64 bit count */
+  WRITE_UINT32(ctx->block + (SHA1_DATA_SIZE - 8), high);
+  WRITE_UINT32(ctx->block + (SHA1_DATA_SIZE - 4), low);
+  SHA1_COMPRESS(ctx, ctx->block);
+
+  _nettle_write_be32(length, digest, ctx->state);
+}
+
+static void
+padlock_sha256_digest(struct sha256_ctx *ctx,
+                   unsigned length,
+                   uint8_t *digest)
+{
+  uint32_t high, low;
+
+  assert(length <= SHA256_DIGEST_SIZE);
+
+  MD_PAD(ctx, 8, SHA256_COMPRESS);
+
+  /* There are 512 = 2^9 bits in one block */  
+  high = (ctx->count_high << 9) | (ctx->count_low >> 23);
+  low = (ctx->count_low << 9) | (ctx->index << 3);
+
+  /* This is slightly inefficient, as the numbers are converted to
+     big-endian format, and will be converted back by the compression
+     function. It's probably not worth the effort to fix this. */
+  WRITE_UINT32(ctx->block + (SHA256_DATA_SIZE - 8), high);
+  WRITE_UINT32(ctx->block + (SHA256_DATA_SIZE - 4), low);
+  SHA256_COMPRESS(ctx, ctx->block);
+
+  _nettle_write_be32(length, digest, ctx->state);
+}
+
+static void
+padlock_sha512_digest(struct sha512_ctx *ctx,
+                   unsigned length,
+                   uint8_t *digest)
+{
+  uint64_t high, low;
+
+  unsigned i;
+  unsigned words;
+  unsigned leftover;
+
+  assert(length <= SHA512_DIGEST_SIZE);
+
+  MD_PAD(ctx, 16, SHA512_COMPRESS);
+
+  /* There are 1024 = 2^10 bits in one block */  
+  high = (ctx->count_high << 10) | (ctx->count_low >> 54);
+  low = (ctx->count_low << 10) | (ctx->index << 3);
+
+  /* This is slightly inefficient, as the numbers are converted to
+     big-endian format, and will be converted back by the compression
+     function. It's probably not worth the effort to fix this. */
+  WRITE_UINT64(ctx->block + (SHA512_DATA_SIZE - 16), high);
+  WRITE_UINT64(ctx->block + (SHA512_DATA_SIZE - 8), low);
+  SHA512_COMPRESS(ctx, ctx->block);
+
+  words = length / 8;
+  leftover = length % 8;
+
+  for (i = 0; i < words; i++, digest += 8)
+    WRITE_UINT64(digest, ctx->state[i]);
+
+  if (leftover)
+    {
+      /* Truncate to the right size */
+      uint64_t word = ctx->state[i] >> (8*(8 - leftover));
+
+      do {
+       digest[--leftover] = word & 0xff;
+       word >>= 8;
+      } while (leftover);
+    }
+}
+
+
+static int _ctx_init(gnutls_digest_algorithm_t algo, struct padlock_hash_ctx 
*ctx)
+{
+  switch (algo)
+    {
+    case GNUTLS_DIG_SHA1:
+      sha1_init (&ctx->ctx.sha1);
+      ctx->update = (update_func) padlock_sha1_update;
+      ctx->digest = (digest_func) padlock_sha1_digest;
+      ctx->ctx_ptr = &ctx->ctx.sha1;
+      ctx->length = SHA1_DIGEST_SIZE;
+      break;
+    case GNUTLS_DIG_SHA224:
+      sha224_init (&ctx->ctx.sha224);
+      ctx->update = (update_func) padlock_sha256_update;
+      ctx->digest = (digest_func) padlock_sha256_digest;
+      ctx->ctx_ptr = &ctx->ctx.sha224;
+      ctx->length = SHA224_DIGEST_SIZE;
+      break;
+    case GNUTLS_DIG_SHA256:
+      sha256_init (&ctx->ctx.sha256);
+      ctx->update = (update_func) padlock_sha256_update;
+      ctx->digest = (digest_func) padlock_sha256_digest;
+      ctx->ctx_ptr = &ctx->ctx.sha256;
+      ctx->length = SHA256_DIGEST_SIZE;
+      break;
+    case GNUTLS_DIG_SHA384:
+      sha384_init (&ctx->ctx.sha384);
+      ctx->update = (update_func) padlock_sha512_update;
+      ctx->digest = (digest_func) padlock_sha512_digest;
+      ctx->ctx_ptr = &ctx->ctx.sha384;
+      ctx->length = SHA384_DIGEST_SIZE;
+      break;
+    case GNUTLS_DIG_SHA512:
+      sha512_init (&ctx->ctx.sha512);
+      ctx->update = (update_func) padlock_sha512_update;
+      ctx->digest = (digest_func) padlock_sha512_digest;
+      ctx->ctx_ptr = &ctx->ctx.sha512;
+      ctx->length = SHA512_DIGEST_SIZE;
+      break;
+    default:
+      gnutls_assert ();
+      return GNUTLS_E_INVALID_REQUEST;
+    }
+    
+    return 0;
+}
+
+
+static int
+wrap_padlock_hash_init (gnutls_digest_algorithm_t algo, void **_ctx)
+{
+  struct padlock_hash_ctx *ctx;
+  int ret;
+
+  ctx = gnutls_malloc (sizeof (struct padlock_hash_ctx));
+  if (ctx == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
+    }
+
+  ctx->algo = algo;
+
+  if ((ret=_ctx_init( algo, ctx)) < 0)
+    {
+      gnutls_assert ();
+      return ret;
+    }
+
+  *_ctx = ctx;
+
+  return 0;
+}
+
+static int
+wrap_padlock_hash_copy (void **bhd, void *ahd)
+{
+  struct padlock_hash_ctx *ctx = ahd;
+  struct padlock_hash_ctx *dst_ctx;
+  int ret;
+
+  ret = wrap_padlock_hash_init (ctx->algo, bhd);
+  if (ret < 0)
+    {
+      gnutls_assert ();
+      return ret;
+    }
+
+  dst_ctx = *bhd;
+
+  memcpy (&dst_ctx->ctx, &ctx->ctx, sizeof (ctx->ctx));
+
+  return 0;
+}
+
+
+static int
+wrap_padlock_hash_output (void *src_ctx, void *digest, size_t digestsize)
+{
+  struct padlock_hash_ctx *ctx;
+  ctx = src_ctx;
+
+  if (digestsize < ctx->length)
+    return gnutls_assert_val(GNUTLS_E_SHORT_MEMORY_BUFFER);
+
+  ctx->digest (ctx->ctx_ptr, digestsize, digest);
+
+  return 0;
+}
+
+static void
+wrap_padlock_hash_reset (void *src_ctx)
+{
+  struct padlock_hash_ctx *ctx;
+  ctx = src_ctx;
+
+  _ctx_init(ctx->algo, ctx->ctx_ptr);
+}
+
+int wrap_padlock_hash_fast(gnutls_digest_algorithm_t algo, 
+  const void* text, size_t text_size, 
+  void* digest)
+{
+  if (algo == GNUTLS_DIG_SHA1)
+    {
+      uint32_t iv[5] = 
+        {
+          0x67452301UL,
+          0xEFCDAB89UL,
+          0x98BADCFEUL,
+          0x10325476UL,
+          0xC3D2E1F0UL,
+        };
+      padlock_sha1_oneshot (iv, text, text_size);
+      _nettle_write_be32(20, digest, iv);
+    }
+  else if (algo == GNUTLS_DIG_SHA256)
+    {
+      uint32_t iv[8] =
+        {
+          0x6a09e667UL, 0xbb67ae85UL, 0x3c6ef372UL, 0xa54ff53aUL, 
+          0x510e527fUL, 0x9b05688cUL, 0x1f83d9abUL, 0x5be0cd19UL, 
+        };
+      padlock_sha256_oneshot (iv, text, text_size);
+      _nettle_write_be32(32, digest, iv);
+    }
+  else 
+    {
+      struct padlock_hash_ctx ctx;
+      int ret;
+    
+      ret = _ctx_init(algo, &ctx);
+      if (ret < 0)
+        return gnutls_assert_val(ret);
+      ctx.algo = algo;
+
+      wrap_padlock_hash_update(&ctx, text, text_size);
+
+      wrap_padlock_hash_output(&ctx, digest, ctx.length);
+    }
+  
+  return 0;
+}
+
+const struct nettle_hash padlock_sha1 = _NETTLE_HASH(sha1, SHA1);
+const struct nettle_hash padlock_sha224 = _NETTLE_HASH(sha224, SHA224);
+const struct nettle_hash padlock_sha256 = _NETTLE_HASH(sha256, SHA256);
+const struct nettle_hash padlock_sha384 = _NETTLE_HASH(sha384, SHA384);
+const struct nettle_hash padlock_sha512 = _NETTLE_HASH(sha512, SHA512);
+
+const gnutls_crypto_digest_st sha_padlock_struct = {
+  .init = NULL,
+  .hash = NULL,
+  .output = NULL,
+  .deinit = NULL,
+  .fast = wrap_padlock_hash_fast
+};
+
+const gnutls_crypto_digest_st sha_padlock_nano_struct = {
+  .init = wrap_padlock_hash_init,
+  .hash = wrap_padlock_hash_update,
+  .reset = wrap_padlock_hash_reset,
+  .copy = wrap_padlock_hash_copy,
+  .output = wrap_padlock_hash_output,
+  .deinit = wrap_padlock_hash_deinit,
+  .fast = wrap_padlock_hash_fast,
+};
+
+#endif /* HAVE_LIBNETTLE */
diff --git a/lib/accelerated/x86/sha-padlock.h 
b/lib/accelerated/x86/sha-padlock.h
new file mode 100644
index 0000000..5d1959a
--- /dev/null
+++ b/lib/accelerated/x86/sha-padlock.h
@@ -0,0 +1,30 @@
+#ifndef SHA_PADLOCK_H
+# define SHA_PADLOCK_H
+
+#include <nettle/sha.h>
+
+void padlock_sha1_oneshot(void *ctx, const void *inp, size_t len);
+void padlock_sha256_oneshot(void *ctx, const void *inp, size_t len);
+
+void padlock_sha1_blocks(unsigned int *ctx,const void *inp,size_t blocks);
+void padlock_sha256_blocks(unsigned int *ctx,const void *inp,size_t blocks);
+void padlock_sha512_blocks(unsigned int *ctx,const void *inp,size_t blocks);
+
+int wrap_padlock_hash_fast(gnutls_digest_algorithm_t algo, 
+  const void* text, size_t text_size, 
+  void* digest);
+
+void padlock_sha1_update(struct sha1_ctx *ctx,
+           unsigned length, const uint8_t *data);
+void padlock_sha256_update(struct sha256_ctx *ctx,
+             unsigned length, const uint8_t *data);
+void padlock_sha512_update(struct sha512_ctx *ctx,
+             unsigned length, const uint8_t *data);
+
+extern const struct nettle_hash padlock_sha1;
+extern const struct nettle_hash padlock_sha224;
+extern const struct nettle_hash padlock_sha256;
+extern const struct nettle_hash padlock_sha384;
+extern const struct nettle_hash padlock_sha512;
+
+#endif
diff --git a/lib/accelerated/x86/x86.h b/lib/accelerated/x86/x86.h
new file mode 100644
index 0000000..6730fa8
--- /dev/null
+++ b/lib/accelerated/x86/x86.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * Author: Nikos Mavrogiannopoulos
+ *
+ * This file is part of GnuTLS.
+ *
+ * The GnuTLS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+
+#if defined(ASM_X86)
+
+void _gnutls_cpuid(unsigned int func, unsigned int *ax, unsigned int *bx, 
unsigned int *cx, unsigned int* dx);
+
+# ifdef ASM_X86_32
+unsigned int _gnutls_have_cpuid(void);
+# else
+#  define _gnutls_have_cpuid() 1
+# endif /* ASM_X86_32 */
+
+#endif
+
diff --git a/lib/algorithms/Makefile.am b/lib/algorithms/Makefile.am
index 3bf8ae7..e4d62ee 100644
--- a/lib/algorithms/Makefile.am
+++ b/lib/algorithms/Makefile.am
@@ -21,8 +21,10 @@
 AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
 AM_CPPFLAGS = \
        -I$(srcdir)/../../gl            \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/../includes         \
        -I$(builddir)/../includes       \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/..                  \
        -I$(srcdir)/../opencdk
 
diff --git a/lib/algorithms/ciphersuites.c b/lib/algorithms/ciphersuites.c
index 94ceb70..7b59037 100644
--- a/lib/algorithms/ciphersuites.c
+++ b/lib/algorithms/ciphersuites.c
@@ -566,7 +566,7 @@ static const gnutls_cipher_suite_entry cs_algorithms[] = {
                              GNUTLS_VERSION_MAX, 1),
   GNUTLS_CIPHER_SUITE_ENTRY (GNUTLS_ECDHE_RSA_AES_128_CBC_SHA256,
                              GNUTLS_CIPHER_AES_128_CBC, GNUTLS_KX_ECDHE_RSA,
-                             GNUTLS_MAC_SHA1, GNUTLS_TLS1_2,
+                             GNUTLS_MAC_SHA256, GNUTLS_TLS1_2,
                              GNUTLS_VERSION_MAX, 1),
   GNUTLS_CIPHER_SUITE_ENTRY (GNUTLS_ECDHE_ECDSA_AES_128_GCM_SHA256,
                              GNUTLS_CIPHER_AES_128_GCM, GNUTLS_KX_ECDHE_ECDSA,
diff --git a/lib/auth/Makefile.am b/lib/auth/Makefile.am
index e31e95b..1bf965b 100644
--- a/lib/auth/Makefile.am
+++ b/lib/auth/Makefile.am
@@ -21,8 +21,10 @@
 AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
 AM_CPPFLAGS = \
        -I$(srcdir)/../../gl            \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/../includes         \
        -I$(builddir)/../includes       \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/..                  \
        -I$(srcdir)/../opencdk
 
diff --git a/lib/auth/cert.c b/lib/auth/cert.c
index 2deb5e2..fddc102 100644
--- a/lib/auth/cert.c
+++ b/lib/auth/cert.c
@@ -620,6 +620,10 @@ call_get_cert_callback (gnutls_session_t session,
             }
         }
       break;
+    default:
+      gnutls_assert();
+      ret = GNUTLS_E_INVALID_REQUEST;
+      goto cleanup;
     }
 
   _gnutls_selected_certs_set (session, local_certs,
diff --git a/lib/auth/ecdh_common.c b/lib/auth/ecdh_common.c
index 2b3672b..2ea3d95 100644
--- a/lib/auth/ecdh_common.c
+++ b/lib/auth/ecdh_common.c
@@ -51,13 +51,14 @@ int ret;
   pub.params[2] = session->key->ecdh_params.params[2];
   pub.params[3] = session->key->ecdh_params.params[3];
   pub.params[4] = session->key->ecdh_params.params[4];
-  pub.params[5] = session->key->ecdh_x;
-  pub.params[6] = session->key->ecdh_y;
-  pub.params[7] = _gnutls_mpi_new(1);
-  if (pub.params[7] == NULL)
+  pub.params[5] = session->key->ecdh_params.params[5];
+  pub.params[6] = session->key->ecdh_x;
+  pub.params[7] = session->key->ecdh_y;
+  pub.params[8] = _gnutls_mpi_new(1);
+  if (pub.params[8] == NULL)
     return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
   
-  _gnutls_mpi_set_ui(pub.params[7], 1);
+  _gnutls_mpi_set_ui(pub.params[8], 1);
   
   if (psk_key == NULL)
     ret = _gnutls_pk_derive(GNUTLS_PK_ECC, &session->key->key, 
&session->key->ecdh_params, &pub);
@@ -86,7 +87,7 @@ int ret;
   ret = 0;
 
 cleanup:
-  _gnutls_mpi_release(&pub.params[7]);
+  _gnutls_mpi_release(&pub.params[8]);
   
   /* no longer needed */
   _gnutls_mpi_release (&session->key->ecdh_x);
@@ -148,8 +149,8 @@ _gnutls_gen_ecdh_common_client_kx_int (gnutls_session_t 
session,
   if (ret < 0)
     return gnutls_assert_val(ret);
 
-  ret = _gnutls_ecc_ansi_x963_export(curve, 
session->key->ecdh_params.params[5] /* x */,
-    session->key->ecdh_params.params[6] /* y */, &out);
+  ret = _gnutls_ecc_ansi_x963_export(curve, 
session->key->ecdh_params.params[6] /* x */,
+    session->key->ecdh_params.params[7] /* y */, &out);
   if (ret < 0)
     return gnutls_assert_val(ret);
 
@@ -234,8 +235,8 @@ int _gnutls_ecdh_common_print_server_kx (gnutls_session_t 
session, gnutls_buffer
   if (ret < 0)
     return gnutls_assert_val(ret);
 
-  ret = _gnutls_ecc_ansi_x963_export(curve, 
session->key->ecdh_params.params[5] /* x */,
-    session->key->ecdh_params.params[6] /* y */, &out);
+  ret = _gnutls_ecc_ansi_x963_export(curve, 
session->key->ecdh_params.params[6] /* x */,
+    session->key->ecdh_params.params[7] /* y */, &out);
   if (ret < 0)
     return gnutls_assert_val(ret);
 
diff --git a/lib/auth/srp.c b/lib/auth/srp.c
index 068682c..6c9d233 100644
--- a/lib/auth/srp.c
+++ b/lib/auth/srp.c
@@ -1,6 +1,5 @@
 /*
- * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2008, 2009, 2010 Free
- * Software Foundation, Inc.
+ * Copyright (C) 2001-2011 Free Software Foundation, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
  *
@@ -460,6 +459,7 @@ static const unsigned char srp_params_1024[] = {
 };
 
 static const unsigned char srp_generator = 0x02;
+static const unsigned char srp3072_generator = 0x05;
 
 const gnutls_datum_t gnutls_srp_1024_group_prime = {
   (void *) srp_params_1024, sizeof (srp_params_1024)
@@ -542,6 +542,113 @@ const gnutls_datum_t gnutls_srp_2048_group_generator = {
   (void *) &srp_generator, sizeof (srp_generator)
 };
 
+static const unsigned char srp_params_3072[] = {
+  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9,
+  0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6,
+  0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E,
+  0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6,
+  0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E,
+  0x34, 0x04, 0xDD, 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A,
+  0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14,
+  0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
+  0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4,
+  0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF,
+  0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 0xEE, 0x38, 0x6B,
+  0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11,
+  0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC,
+  0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63,
+  0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3,
+  0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
+  0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C,
+  0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5,
+  0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35,
+  0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08,
+  0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E,
+  0x36, 0xCE, 0x3B, 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E,
+  0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2,
+  0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9,
+  0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39,
+  0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2,
+  0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 0x15, 0x72, 0x8E,
+  0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D,
+  0x04, 0x50, 0x7A, 0x33, 0xA8, 0x55, 0x21, 0xAB, 0xDF,
+  0x1C, 0xBA, 0x64, 0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB,
+  0xEF, 0x0A, 0x8A, 0xEA, 0x71, 0x57, 0x5D, 0x06, 0x0C,
+  0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7,
+  0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E,
+  0x8C, 0x94, 0xE0, 0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 
+  0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, 0xF1, 0x2F, 0xFA, 
+  0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73,
+  0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17,
+  0x7B, 0x20, 0x0C, 0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 
+  0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 0xBA, 0xD9, 0x46, 
+  0xE2, 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31,
+  0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B,
+  0x82, 0xD1, 0x20, 0xA9, 0x3A, 0xD2, 0xCA, 0xFF, 0xFF, 
+  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
+};
+
+const gnutls_datum_t gnutls_srp_3072_group_generator = {
+  (void *) &srp3072_generator, sizeof (srp3072_generator)
+};
+
+const gnutls_datum_t gnutls_srp_3072_group_prime = {
+  (void *) srp_params_3072, sizeof (srp_params_3072)
+};
+
+static const unsigned char srp_params_4096[] = {
+0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 
+0x21, 0x68, 0xC2, 0x34, 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 
+0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, 0x02, 0x0B, 0xBE, 0xA6, 
+0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, 
+0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 
+0xF2, 0x5F, 0x14, 0x37, 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 
+0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, 0xF4, 0x4C, 0x42, 0xE9,
+0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, 
+0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 
+0x7C, 0x4B, 0x1F, 0xE6, 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 
+0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, 0x98, 0xDA, 0x48, 0x36, 
+0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, 
+0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 
+0x20, 0x85, 0x52, 0xBB, 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
+0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, 0xF1, 0x74, 0x6C, 0x08, 
+0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B,
+0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 
+0xEC, 0x07, 0xA2, 0x8F, 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 
+0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, 0x39, 0x95, 0x49, 0x7C, 
+0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, 
+0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAA, 0xC4, 0x2D, 0xAD, 0x33, 0x17, 0x0D,
+0x04, 0x50, 0x7A, 0x33, 0xA8, 0x55, 0x21, 0xAB, 0xDF, 0x1C, 0xBA, 0x64, 
+0xEC, 0xFB, 0x85, 0x04, 0x58, 0xDB, 0xEF, 0x0A, 0x8A, 0xEA, 0x71, 0x57, 
+0x5D, 0x06, 0x0C, 0x7D, 0xB3, 0x97, 0x0F, 0x85, 0xA6, 0xE1, 0xE4, 0xC7, 
+0xAB, 0xF5, 0xAE, 0x8C, 0xDB, 0x09, 0x33, 0xD7, 0x1E, 0x8C, 0x94, 0xE0, 
+0x4A, 0x25, 0x61, 0x9D, 0xCE, 0xE3, 0xD2, 0x26, 0x1A, 0xD2, 0xEE, 0x6B, 
+0xF1, 0x2F, 0xFA, 0x06, 0xD9, 0x8A, 0x08, 0x64, 0xD8, 0x76, 0x02, 0x73, 
+0x3E, 0xC8, 0x6A, 0x64, 0x52, 0x1F, 0x2B, 0x18, 0x17, 0x7B, 0x20, 0x0C,
+0xBB, 0xE1, 0x17, 0x57, 0x7A, 0x61, 0x5D, 0x6C, 0x77, 0x09, 0x88, 0xC0, 
+0xBA, 0xD9, 0x46, 0xE2, 0x08, 0xE2, 0x4F, 0xA0, 0x74, 0xE5, 0xAB, 0x31, 
+0x43, 0xDB, 0x5B, 0xFC, 0xE0, 0xFD, 0x10, 0x8E, 0x4B, 0x82, 0xD1, 0x20, 
+0xA9, 0x21, 0x08, 0x01, 0x1A, 0x72, 0x3C, 0x12, 0xA7, 0x87, 0xE6, 0xD7, 
+0x88, 0x71, 0x9A, 0x10, 0xBD, 0xBA, 0x5B, 0x26, 0x99, 0xC3, 0x27, 0x18, 
+0x6A, 0xF4, 0xE2, 0x3C, 0x1A, 0x94, 0x68, 0x34, 0xB6, 0x15, 0x0B, 0xDA, 
+0x25, 0x83, 0xE9, 0xCA, 0x2A, 0xD4, 0x4C, 0xE8, 0xDB, 0xBB, 0xC2, 0xDB,
+0x04, 0xDE, 0x8E, 0xF9, 0x2E, 0x8E, 0xFC, 0x14, 0x1F, 0xBE, 0xCA, 0xA6, 
+0x28, 0x7C, 0x59, 0x47, 0x4E, 0x6B, 0xC0, 0x5D, 0x99, 0xB2, 0x96, 0x4F, 
+0xA0, 0x90, 0xC3, 0xA2, 0x23, 0x3B, 0xA1, 0x86, 0x51, 0x5B, 0xE7, 0xED, 
+0x1F, 0x61, 0x29, 0x70, 0xCE, 0xE2, 0xD7, 0xAF, 0xB8, 0x1B, 0xDD, 0x76, 
+0x21, 0x70, 0x48, 0x1C, 0xD0, 0x06, 0x91, 0x27, 0xD5, 0xB0, 0x5A, 0xA9, 
+0x93, 0xB4, 0xEA, 0x98, 0x8D, 0x8F, 0xDD, 0xC1, 0x86, 0xFF, 0xB7, 0xDC, 
+0x90, 0xA6, 0xC0, 0x8F, 0x4D, 0xF4, 0x35, 0xC9, 0x34, 0x06, 0x31, 0x99,
+0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
+};
+
+const gnutls_datum_t gnutls_srp_4096_group_generator = {
+  (void *) &srp3072_generator, sizeof (srp3072_generator)
+};
+
+const gnutls_datum_t gnutls_srp_4096_group_prime = {
+  (void *) srp_params_4096, sizeof (srp_params_4096)
+};
 
 /* Check if G and N are parameters from the SRP draft.
  */
@@ -549,6 +656,18 @@ static int
 check_g_n (const opaque * g, size_t n_g, const opaque * n, size_t n_n)
 {
 
+  if ((n_n == sizeof (srp_params_3072) &&
+      memcmp (srp_params_3072, n, n_n) == 0) ||
+      (n_n == sizeof (srp_params_4096) &&
+      memcmp (srp_params_4096, n, n_n) == 0))
+    {
+      if (n_g != 1 || g[0] != srp3072_generator)
+        {
+          return gnutls_assert_val(GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER);
+        }
+      return 0;
+    }
+
   if (n_g != 1 || g[0] != srp_generator)
     {
       gnutls_assert ();
diff --git a/lib/auth/srp_passwd.c b/lib/auth/srp_passwd.c
index a06ae9d..7ced101 100644
--- a/lib/auth/srp_passwd.c
+++ b/lib/auth/srp_passwd.c
@@ -446,7 +446,7 @@ _randomize_pwd_entry (SRP_PWD_ENTRY * entry)
 }
 
 /* Free all the entry parameters, except if g and n are
- * the static ones defined in extra.h
+ * the static ones defined in gnutls.h
  */
 void
 _gnutls_srp_entry_free (SRP_PWD_ENTRY * entry)
@@ -454,12 +454,15 @@ _gnutls_srp_entry_free (SRP_PWD_ENTRY * entry)
   _gnutls_free_datum (&entry->v);
   _gnutls_free_datum (&entry->salt);
 
-  if (entry->g.data != gnutls_srp_1024_group_generator.data)
+  if ((entry->g.data != gnutls_srp_1024_group_generator.data)
+     && (entry->g.data != gnutls_srp_3072_group_generator.data))
     _gnutls_free_datum (&entry->g);
 
   if (entry->n.data != gnutls_srp_1024_group_prime.data &&
       entry->n.data != gnutls_srp_1536_group_prime.data &&
-      entry->n.data != gnutls_srp_2048_group_prime.data)
+      entry->n.data != gnutls_srp_2048_group_prime.data &&
+      entry->n.data != gnutls_srp_3072_group_prime.data &&
+      entry->n.data != gnutls_srp_4096_group_prime.data)
     _gnutls_free_datum (&entry->n);
 
   gnutls_free (entry->username);
diff --git a/lib/crypto-backend.h b/lib/crypto-backend.h
index 5be0dd9..0a20025 100644
--- a/lib/crypto-backend.h
+++ b/lib/crypto-backend.h
@@ -51,16 +51,18 @@
     int (*hash) (void *ctx, const void *text, size_t textsize);
     int (*output) (void *src_ctx, void *digest, size_t digestsize);
     void (*deinit) (void *ctx);
+    int (*fast)(gnutls_mac_algorithm_t, const void *key, size_t keysize, const 
void *text, size_t textsize, void *digest);
   } gnutls_crypto_mac_st;
 
   typedef struct
   {
-    int (*init) (gnutls_mac_algorithm_t, void **ctx);
+    int (*init) (gnutls_digest_algorithm_t, void **ctx);
     void (*reset) (void *ctx);
-    int (*hash) (void *ctx, const void *text, size_t textsize);
+    int (*hash) (void *ctx, const void *src, size_t srcsize);
     int (*copy) (void **dst_ctx, void *src_ctx);
     int (*output) (void *src_ctx, void *digest, size_t digestsize);
     void (*deinit) (void *ctx);
+    int (*fast)(gnutls_digest_algorithm_t, const void *src, size_t srcsize, 
void *digest);
   } gnutls_crypto_digest_st;
 
   typedef struct gnutls_crypto_rnd
@@ -181,6 +183,35 @@
   void gnutls_pk_params_release (gnutls_pk_params_st * p);
   void gnutls_pk_params_init (gnutls_pk_params_st * p);
 
+
+#define MAX_PUBLIC_PARAMS_SIZE 4        /* ok for RSA and DSA */
+
+/* parameters should not be larger than this limit */
+#define DSA_PUBLIC_PARAMS 4
+#define RSA_PUBLIC_PARAMS 2
+#define ECC_PUBLIC_PARAMS 8
+
+
+#define MAX_PRIV_PARAMS_SIZE GNUTLS_MAX_PK_PARAMS       /* ok for RSA and DSA 
*/
+
+/* parameters should not be larger than this limit */
+#define DSA_PRIVATE_PARAMS 5
+#define RSA_PRIVATE_PARAMS 8
+#define ECC_PRIVATE_PARAMS 9
+
+#if MAX_PRIV_PARAMS_SIZE - RSA_PRIVATE_PARAMS < 0
+#error INCREASE MAX_PRIV_PARAMS
+#endif
+
+#if MAX_PRIV_PARAMS_SIZE - ECC_PRIVATE_PARAMS < 0
+#error INCREASE MAX_PRIV_PARAMS
+#endif
+
+#if MAX_PRIV_PARAMS_SIZE - DSA_PRIVATE_PARAMS < 0
+#error INCREASE MAX_PRIV_PARAMS
+#endif
+
+
 /* params are:
  * RSA:
  *  [0] is modulus
@@ -206,11 +237,12 @@
  *  [0] is prime
  *  [1] is order
  *  [2] is A
- *  [3] is Gx
- *  [4] is Gy
- *  [5] is x
- *  [6] is y
- *  [7] is k (private key)
+ *  [3] is B
+ *  [4] is Gx
+ *  [5] is Gy
+ *  [6] is x
+ *  [7] is y
+ *  [8] is k (private key)
  */
 
 /**
diff --git a/lib/debug.c b/lib/debug.c
index 27dda9a..19246e4 100644
--- a/lib/debug.c
+++ b/lib/debug.c
@@ -28,6 +28,7 @@
 #include "debug.h"
 #include <gnutls_mpi.h>
 
+#ifdef DEBUG
 void
 _gnutls_dump_mpi (const char *prefix, bigint_t a)
 {
@@ -41,7 +42,7 @@ _gnutls_dump_mpi (const char *prefix, bigint_t a)
                      _gnutls_bin2hex (buf, n, buf_hex, sizeof (buf_hex),
                                       NULL));
 }
-
+#endif
 
 const char *
 _gnutls_packet2str (content_type_t packet)
diff --git a/lib/ext/Makefile.am b/lib/ext/Makefile.am
index b00a47f..a2adcca 100644
--- a/lib/ext/Makefile.am
+++ b/lib/ext/Makefile.am
@@ -21,8 +21,10 @@
 AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
 AM_CPPFLAGS = \
        -I$(srcdir)/../../gl            \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/../includes         \
        -I$(builddir)/../includes       \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/..                  \
        -I$(srcdir)/../opencdk
 
diff --git a/lib/gcrypt/Makefile.am b/lib/gcrypt/Makefile.am
deleted file mode 100644
index e2d7fc4..0000000
--- a/lib/gcrypt/Makefile.am
+++ /dev/null
@@ -1,34 +0,0 @@
-## Process this file with automake to produce Makefile.in
-# Copyright (C) 2004-2011 Free Software Foundation, Inc.
-#
-# Author: Nikos Mavroyanopoulos
-#
-# This file is part of GNUTLS.
-#
-# The GNUTLS library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public License
-# as published by the Free Software Foundation; either version 3 of
-# the License, or (at your option) any later version.
-#
-# The GNUTLS library is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied warranty
-# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>
-
-AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
-AM_CPPFLAGS = \
-       -I$(srcdir)/../../gl            \
-       -I$(srcdir)/../includes         \
-       -I$(builddir)/../includes       \
-       -I$(srcdir)/..
-
-if ENABLE_MINITASN1
-AM_CPPFLAGS += -I$(srcdir)/../minitasn1
-endif
-
-noinst_LTLIBRARIES = libcrypto.la
-
-libcrypto_la_SOURCES = pk.c mpi.c mac.c cipher.c rnd.c init.c
diff --git a/lib/gcrypt/cipher.c b/lib/gcrypt/cipher.c
deleted file mode 100644
index e5427c6..0000000
--- a/lib/gcrypt/cipher.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright (C) 2008, 2010, 2011 Free Software Foundation, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS.
- *
- * The GnuTLS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-/* Here lie everything that has to do with large numbers, libgcrypt and
- * other stuff that didn't fit anywhere else.
- */
-
-#include <gnutls_int.h>
-#include <gnutls_errors.h>
-#include <gnutls_cipher_int.h>
-#include <gcrypt.h>
-
-/* Functions that refer to the libgcrypt library.
- */
-
-#error GCM is missing
-
-static int
-wrap_gcry_cipher_init (gnutls_cipher_algorithm_t algo, void **ctx)
-{
-  int err;
-
-  switch (algo)
-    {
-    case GNUTLS_CIPHER_AES_128_CBC:
-      err =
-        gcry_cipher_open ((gcry_cipher_hd_t *) ctx, GCRY_CIPHER_AES128,
-                          GCRY_CIPHER_MODE_CBC, 0);
-      break;
-
-    case GNUTLS_CIPHER_AES_192_CBC:
-      err =
-        gcry_cipher_open ((gcry_cipher_hd_t *) ctx, GCRY_CIPHER_AES192,
-                          GCRY_CIPHER_MODE_CBC, 0);
-      break;
-
-    case GNUTLS_CIPHER_AES_256_CBC:
-      err =
-        gcry_cipher_open ((gcry_cipher_hd_t *) ctx, GCRY_CIPHER_AES256,
-                          GCRY_CIPHER_MODE_CBC, 0);
-      break;
-
-    case GNUTLS_CIPHER_3DES_CBC:
-      err =
-        gcry_cipher_open ((gcry_cipher_hd_t *) ctx, GCRY_CIPHER_3DES,
-                          GCRY_CIPHER_MODE_CBC, 0);
-      break;
-
-    case GNUTLS_CIPHER_DES_CBC:
-      err =
-        gcry_cipher_open ((gcry_cipher_hd_t *) ctx, GCRY_CIPHER_DES,
-                          GCRY_CIPHER_MODE_CBC, 0);
-      break;
-
-    case GNUTLS_CIPHER_ARCFOUR_128:
-    case GNUTLS_CIPHER_ARCFOUR_40:
-      err =
-        gcry_cipher_open ((gcry_cipher_hd_t *) ctx, GCRY_CIPHER_ARCFOUR,
-                          GCRY_CIPHER_MODE_STREAM, 0);
-      break;
-
-    case GNUTLS_CIPHER_RC2_40_CBC:
-      err =
-        gcry_cipher_open ((gcry_cipher_hd_t *) ctx, GCRY_CIPHER_RFC2268_40,
-                          GCRY_CIPHER_MODE_CBC, 0);
-      break;
-
-    case GNUTLS_CIPHER_CAMELLIA_128_CBC:
-      err =
-        gcry_cipher_open ((gcry_cipher_hd_t *) ctx, GCRY_CIPHER_CAMELLIA128,
-                          GCRY_CIPHER_MODE_CBC, 0);
-      break;
-
-    case GNUTLS_CIPHER_CAMELLIA_256_CBC:
-      err =
-        gcry_cipher_open ((gcry_cipher_hd_t *) ctx, GCRY_CIPHER_CAMELLIA256,
-                          GCRY_CIPHER_MODE_CBC, 0);
-      break;
-    default:
-      gnutls_assert ();
-      return GNUTLS_E_INVALID_REQUEST;
-    }
-
-  if (err == 0)
-    return 0;
-
-  gnutls_assert ();
-  return GNUTLS_E_ENCRYPTION_FAILED;
-}
-
-static int
-wrap_gcry_cipher_setkey (void *ctx, const void *key, size_t keysize)
-{
-  gcry_cipher_setkey (ctx, key, keysize);
-  return 0;
-}
-
-static int
-wrap_gcry_cipher_setiv (void *ctx, const void *iv, size_t ivsize)
-{
-  gcry_cipher_setiv (ctx, iv, ivsize);
-  return 0;
-}
-
-static int
-wrap_gcry_cipher_decrypt (void *ctx, const void *encr, size_t encrsize,
-                          void *plain, size_t plainsize)
-{
-  int err;
-
-  err = gcry_cipher_decrypt (ctx, plain, plainsize, encr, encrsize);
-  if (err == 0)
-    return 0;
-
-  gnutls_assert ();
-  return GNUTLS_E_ENCRYPTION_FAILED;
-}
-
-static int
-wrap_gcry_cipher_encrypt (void *ctx, const void *plain, size_t plainsize,
-                          void *encr, size_t encrsize)
-{
-  int err;
-
-  err = gcry_cipher_encrypt (ctx, encr, encrsize, plain, plainsize);
-  if (err == 0)
-    return 0;
-
-  gnutls_assert ();
-  return GNUTLS_E_ENCRYPTION_FAILED;
-}
-
-static void
-wrap_gcry_cipher_close (void *h)
-{
-  gcry_cipher_close (h);
-}
-
-
-gnutls_crypto_cipher_st _gnutls_cipher_ops = {
-  .init = wrap_gcry_cipher_init,
-  .setkey = wrap_gcry_cipher_setkey,
-  .setiv = wrap_gcry_cipher_setiv,
-  .encrypt = wrap_gcry_cipher_encrypt,
-  .decrypt = wrap_gcry_cipher_decrypt,
-  .deinit = wrap_gcry_cipher_close,
-};
diff --git a/lib/gcrypt/init.c b/lib/gcrypt/init.c
deleted file mode 100644
index 3d69f44..0000000
--- a/lib/gcrypt/init.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright (C) 2010-2011 Free Software Foundation, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS.
- *
- * The GnuTLS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-#include <gnutls_int.h>
-#include <gnutls_errors.h>
-#include <gcrypt.h>
-#include <locks.h>
-
-#define GNUTLS_MIN_LIBGCRYPT_VERSION "1.2.4"
-
-/* Functions that refer to the initialization of the libgcrypt library.
- */
-
-static struct gcry_thread_cbs gct = {
-  .option = (GCRY_THREAD_OPTION_PTHREAD | (GCRY_THREAD_OPTION_VERSION << 8)),
-  .init = NULL,
-  .select = NULL,
-  .waitpid = NULL,
-  .accept = NULL,
-  .connect = NULL,
-  .sendmsg = NULL,
-  .recvmsg = NULL,
-};
-
-int
-gnutls_crypto_init (void)
-{
-  /* Initialize libgcrypt if it hasn't already been initialized. */
-  if (gcry_control (GCRYCTL_ANY_INITIALIZATION_P) == 0)
-    {
-      const char *p;
-
-      if (gnutls_mutex_init != NULL)
-        {
-          gct.mutex_init = gnutls_mutex_init;
-          gct.mutex_destroy = gnutls_mutex_deinit;
-          gct.mutex_lock = gnutls_mutex_lock;
-          gct.mutex_unlock = gnutls_mutex_unlock;
-
-          gcry_control (GCRYCTL_SET_THREAD_CBS, &gct);
-        }
-
-      p = gcry_check_version (GNUTLS_MIN_LIBGCRYPT_VERSION);
-
-      if (p == NULL)
-        {
-          gnutls_assert ();
-          _gnutls_debug_log ("Checking for libgcrypt failed: %s < %s\n",
-                             gcry_check_version (NULL),
-                             GNUTLS_MIN_LIBGCRYPT_VERSION);
-          return GNUTLS_E_INCOMPATIBLE_GCRYPT_LIBRARY;
-        }
-
-      /* for gcrypt in order to be able to allocate memory */
-      gcry_control (GCRYCTL_DISABLE_SECMEM, NULL, 0);
-
-      gcry_control (GCRYCTL_INITIALIZATION_FINISHED, NULL, 0);
-
-      gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
-    }
-
-  return 0;
-}
diff --git a/lib/gcrypt/mac.c b/lib/gcrypt/mac.c
deleted file mode 100644
index a72e65b..0000000
--- a/lib/gcrypt/mac.c
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright (C) 2008-2011 Free Software Foundation, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS.
- *
- * The GnuTLS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-/* This file provides is the backend hash/mac API for libgcrypt.
- */
-
-#include <gnutls_int.h>
-#include <gnutls_hash_int.h>
-#include <gnutls_errors.h>
-#include <gcrypt.h>
-
-static int
-wrap_gcry_mac_init (gnutls_mac_algorithm_t algo, void **ctx)
-{
-  int err;
-  unsigned int flags = GCRY_MD_FLAG_HMAC;
-
-  switch (algo)
-    {
-    case GNUTLS_MAC_MD5:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_MD5, flags);
-      break;
-    case GNUTLS_MAC_SHA1:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_SHA1, flags);
-      break;
-    case GNUTLS_MAC_RMD160:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_RMD160, flags);
-      break;
-    case GNUTLS_MAC_MD2:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_MD2, flags);
-      break;
-    case GNUTLS_MAC_SHA256:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_SHA256, flags);
-      break;
-    case GNUTLS_MAC_SHA384:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_SHA384, flags);
-      break;
-    case GNUTLS_MAC_SHA512:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_SHA512, flags);
-      break;
-    default:
-      gnutls_assert ();
-      return GNUTLS_E_INVALID_REQUEST;
-    }
-
-  if (err == 0)
-    return 0;
-
-  gnutls_assert ();
-  return GNUTLS_E_ENCRYPTION_FAILED;
-}
-
-static int
-wrap_gcry_md_setkey (void *ctx, const void *key, size_t keylen)
-{
-  return gcry_md_setkey ((gcry_md_hd_t) ctx, key, keylen);
-}
-
-static int
-wrap_gcry_md_write (void *ctx, const void *text, size_t textsize)
-{
-  gcry_md_write (ctx, text, textsize);
-  return GNUTLS_E_SUCCESS;
-}
-
-static int
-wrap_gcry_md_copy (void **bhd, void *ahd)
-{
-  return gcry_md_copy ((gcry_md_hd_t *) bhd, (gcry_md_hd_t) ahd);
-}
-
-static void
-wrap_gcry_md_close (void *hd)
-{
-  gcry_md_close (hd);
-}
-
-static void
-wrap_gcry_md_reset (void *hd)
-{
-  gcry_md_reset (hd);
-}
-
-static int
-wrap_gcry_hash_init (gnutls_mac_algorithm_t algo, void **ctx)
-{
-  int err;
-  unsigned int flags = 0;
-
-  switch (algo)
-    {
-    case GNUTLS_DIG_MD5:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_MD5, flags);
-      break;
-    case GNUTLS_DIG_SHA1:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_SHA1, flags);
-      break;
-    case GNUTLS_DIG_RMD160:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_RMD160, flags);
-      break;
-    case GNUTLS_DIG_MD2:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_MD2, flags);
-      break;
-    case GNUTLS_DIG_SHA256:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_SHA256, flags);
-      break;
-    case GNUTLS_DIG_SHA224:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_SHA224, flags);
-      break;
-    case GNUTLS_DIG_SHA384:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_SHA384, flags);
-      break;
-    case GNUTLS_DIG_SHA512:
-      err = gcry_md_open ((gcry_md_hd_t *) ctx, GCRY_MD_SHA512, flags);
-      break;
-    default:
-      gnutls_assert ();
-      return GNUTLS_E_INVALID_REQUEST;
-    }
-
-  if (err == 0)
-    return 0;
-
-  gnutls_assert ();
-  return GNUTLS_E_ENCRYPTION_FAILED;
-}
-
-static int
-wrap_gcry_mac_output (void *src_ctx, void *digest, size_t digestsize)
-{
-  opaque *_digest = gcry_md_read (src_ctx, 0);
-
-  if (_digest != NULL)
-    {
-      unsigned int len = gcry_md_get_algo_dlen (gcry_md_get_algo (src_ctx));
-
-      if (len <= digestsize && digest != NULL)
-        memcpy (digest, _digest, len);
-
-      return 0;
-    }
-
-  gnutls_assert ();
-  return GNUTLS_E_HASH_FAILED;
-}
-
-
-gnutls_crypto_mac_st _gnutls_mac_ops = {
-  .init = wrap_gcry_mac_init,
-  .setkey = wrap_gcry_md_setkey,
-  .hash = wrap_gcry_md_write,
-  .reset = wrap_gcry_md_reset,
-  .output = wrap_gcry_mac_output,
-  .deinit = wrap_gcry_md_close,
-};
-
-gnutls_crypto_digest_st _gnutls_digest_ops = {
-  .init = wrap_gcry_hash_init,
-  .hash = wrap_gcry_md_write,
-  .copy = wrap_gcry_md_copy,
-  .reset = wrap_gcry_md_reset,
-  .output = wrap_gcry_mac_output,
-  .deinit = wrap_gcry_md_close,
-};
diff --git a/lib/gcrypt/mpi.c b/lib/gcrypt/mpi.c
deleted file mode 100644
index 5239d7c..0000000
--- a/lib/gcrypt/mpi.c
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
- * Copyright (C) 2001-2011 Free Software Foundation, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS.
- *
- * The GnuTLS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-/* Here lie everything that has to do with large numbers, libgcrypt and
- * other stuff that didn't fit anywhere else.
- */
-
-#include <gnutls_int.h>
-#include <gnutls_errors.h>
-#include <gnutls_num.h>
-#include <gnutls_mpi.h>
-#include <gcrypt.h>
-
-/* Functions that refer to the libgcrypt library.
- */
-
-static inline int
-_format_conv (gnutls_bigint_format_t format)
-{
-  if (format == GNUTLS_MPI_FORMAT_USG)
-    return GCRYMPI_FMT_USG;
-  else if (format == GNUTLS_MPI_FORMAT_STD)
-    return GCRYMPI_FMT_STD;
-  else
-    return GCRYMPI_FMT_PGP;
-}
-
-/* returns (0) on success
- */
-static bigint_t
-wrap_gcry_mpi_scan (const void *buffer, size_t nbytes,
-                    gnutls_bigint_format_t format)
-{
-  gcry_mpi_t ret_mpi = NULL;
-  int ret;
-
-  ret = gcry_mpi_scan (&ret_mpi, _format_conv (format), buffer, nbytes, NULL);
-  if (ret != 0)
-    return NULL;
-
-  return ret_mpi;
-}
-
-static int
-wrap_gcry_mpi_print (const bigint_t a, void *buffer, size_t * nbytes,
-                     gnutls_bigint_format_t format)
-{
-  int ret;
-  size_t init_bytes = *nbytes;
-
-  format = _format_conv (format);
-
-  if (nbytes == NULL || a == NULL)
-    return GNUTLS_E_INVALID_REQUEST;
-
-  ret = gcry_mpi_print (format, buffer, *nbytes, nbytes, a);
-  if (!ret)
-    {
-      if (buffer == NULL || init_bytes < *nbytes)
-        {
-
-          /* in STD format we may want to include
-           * an extra byte for (0). Sometimes the gcry_
-           * function doesn't add it.
-           */
-          if (format == GNUTLS_MPI_FORMAT_STD)
-            (*nbytes)++;
-          return GNUTLS_E_SHORT_MEMORY_BUFFER;
-        }
-      return 0;
-    }
-
-  return GNUTLS_E_MPI_PRINT_FAILED;
-}
-
-static bigint_t
-wrap_gcry_mpi_new (int nbits)
-{
-  return gcry_mpi_new (nbits);
-}
-
-static int
-wrap_gcry_mpi_cmp (const bigint_t u, const bigint_t v)
-{
-  return gcry_mpi_cmp (u, v);
-}
-
-static int
-wrap_gcry_mpi_cmp_ui (const bigint_t u, unsigned long v)
-{
-  return gcry_mpi_cmp_ui (u, v);
-}
-
-static bigint_t
-wrap_gcry_mpi_set (bigint_t w, const bigint_t u)
-{
-  return gcry_mpi_set (w, u);
-}
-
-static bigint_t
-wrap_gcry_mpi_set_ui (bigint_t w, unsigned long u)
-{
-  return gcry_mpi_set_ui (w, u);
-}
-
-static unsigned int
-wrap_gcry_mpi_get_nbits (bigint_t a)
-{
-  return gcry_mpi_get_nbits (a);
-}
-
-static void
-wrap_gcry_mpi_release (bigint_t a)
-{
-  gcry_mpi_release (a);
-}
-
-#undef _gnutls_mpi_alloc_like
-#define _gnutls_mpi_alloc_like(x) gcry_mpi_new(gcry_mpi_get_nbits(x))
-
-static bigint_t
-wrap_gcry_mpi_mod (const bigint_t a, const bigint_t b)
-{
-  bigint_t r = _gnutls_mpi_alloc_like (b);
-
-  if (r == NULL)
-    return NULL;
-
-  gcry_mpi_mod (r, a, b);
-
-  return r;
-}
-
-static bigint_t
-wrap_gcry_mpi_powm (bigint_t w, const bigint_t b, const bigint_t e,
-                    const bigint_t m)
-{
-  if (w == NULL)
-    w = _gnutls_mpi_alloc_like (m);
-
-  if (w == NULL)
-    return NULL;
-
-  gcry_mpi_powm (w, b, e, m);
-
-  return w;
-}
-
-static bigint_t
-wrap_gcry_mpi_addm (bigint_t w, const bigint_t a, const bigint_t b,
-                    const bigint_t m)
-{
-  if (w == NULL)
-    w = _gnutls_mpi_alloc_like (m);
-
-  if (w == NULL)
-    return NULL;
-
-  gcry_mpi_addm (w, a, b, m);
-
-  return w;
-}
-
-static bigint_t
-wrap_gcry_mpi_subm (bigint_t w, const bigint_t a, const bigint_t b,
-                    const bigint_t m)
-{
-  if (w == NULL)
-    w = _gnutls_mpi_alloc_like (m);
-
-  if (w == NULL)
-    return NULL;
-
-  gcry_mpi_subm (w, a, b, m);
-
-  return w;
-}
-
-static bigint_t
-wrap_gcry_mpi_mulm (bigint_t w, const bigint_t a, const bigint_t b,
-                    const bigint_t m)
-{
-  if (w == NULL)
-    w = _gnutls_mpi_alloc_like (m);
-
-  if (w == NULL)
-    return NULL;
-
-  gcry_mpi_mulm (w, a, b, m);
-
-  return w;
-}
-
-static bigint_t
-wrap_gcry_mpi_add (bigint_t w, const bigint_t a, const bigint_t b)
-{
-  if (w == NULL)
-    w = _gnutls_mpi_alloc_like (b);
-
-  if (w == NULL)
-    return NULL;
-
-  gcry_mpi_add (w, a, b);
-
-  return w;
-}
-
-static bigint_t
-wrap_gcry_mpi_sub (bigint_t w, const bigint_t a, const bigint_t b)
-{
-  if (w == NULL)
-    w = _gnutls_mpi_alloc_like (b);
-
-  if (w == NULL)
-    return NULL;
-
-  gcry_mpi_sub (w, a, b);
-
-  return w;
-}
-
-static bigint_t
-wrap_gcry_mpi_mul (bigint_t w, const bigint_t a, const bigint_t b)
-{
-  if (w == NULL)
-    w = _gnutls_mpi_alloc_like (b);
-
-  if (w == NULL)
-    return NULL;
-
-  gcry_mpi_mul (w, a, b);
-
-  return w;
-}
-
-/* q = a / b */
-static bigint_t
-wrap_gcry_mpi_div (bigint_t q, const bigint_t a, const bigint_t b)
-{
-  if (q == NULL)
-    q = _gnutls_mpi_alloc_like (a);
-
-  if (q == NULL)
-    return NULL;
-
-  gcry_mpi_div (q, NULL, a, b, 0);
-
-  return q;
-}
-
-static bigint_t
-wrap_gcry_mpi_add_ui (bigint_t w, const bigint_t a, unsigned long b)
-{
-  if (w == NULL)
-    w = _gnutls_mpi_alloc_like (a);
-
-  if (w == NULL)
-    return NULL;
-
-  gcry_mpi_add_ui (w, a, b);
-
-  return w;
-}
-
-static bigint_t
-wrap_gcry_mpi_sub_ui (bigint_t w, const bigint_t a, unsigned long b)
-{
-  if (w == NULL)
-    w = _gnutls_mpi_alloc_like (a);
-
-  if (w == NULL)
-    return NULL;
-
-  gcry_mpi_sub_ui (w, a, b);
-
-  return w;
-}
-
-static bigint_t
-wrap_gcry_mpi_mul_ui (bigint_t w, const bigint_t a, unsigned long b)
-{
-  if (w == NULL)
-    w = _gnutls_mpi_alloc_like (a);
-
-  if (w == NULL)
-    return NULL;
-
-  gcry_mpi_mul_ui (w, a, b);
-
-  return w;
-}
-
-static int
-wrap_gcry_prime_check (bigint_t pp)
-{
-  return gcry_prime_check (pp, 0);
-}
-
-static int
-wrap_gcry_generate_group (gnutls_group_st * group, unsigned int bits)
-{
-  gcry_mpi_t g = NULL, prime = NULL;
-  gcry_error_t err;
-  int times = 0, qbits;
-  gcry_mpi_t *factors = NULL;
-
-  /* Calculate the size of a prime factor of (prime-1)/2.
-   * This is an emulation of the values in "Selecting Cryptographic Key Sizes" 
paper.
-   */
-  if (bits < 256)
-    qbits = bits / 2;
-  else
-    {
-      qbits = (bits / 40) + 105;
-    }
-
-  if (qbits & 1)                /* better have an even number */
-    qbits++;
-
-  /* find a prime number of size bits.
-   */
-  do
-    {
-      if (times)
-        {
-          gcry_mpi_release (prime);
-          gcry_prime_release_factors (factors);
-        }
-
-      err = gcry_prime_generate (&prime, bits, qbits, &factors,
-                                 NULL, NULL, GCRY_STRONG_RANDOM,
-                                 GCRY_PRIME_FLAG_SPECIAL_FACTOR);
-      if (err != 0)
-        {
-          gnutls_assert ();
-          return GNUTLS_E_INTERNAL_ERROR;
-        }
-
-      err = gcry_prime_check (prime, 0);
-
-      times++;
-    }
-  while (err != 0 && times < 10);
-
-  if (err != 0)
-    {
-      gnutls_assert ();
-      gcry_mpi_release (prime);
-      gcry_prime_release_factors (factors);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  /* generate the group generator.
-   */
-  err = gcry_prime_group_generator (&g, prime, factors, NULL);
-  gcry_prime_release_factors (factors);
-  if (err != 0)
-    {
-      gnutls_assert ();
-      gcry_mpi_release (prime);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  group->g = g;
-  group->p = prime;
-
-  return 0;
-}
-
-int crypto_bigint_prio = INT_MAX;
-
-gnutls_crypto_bigint_st _gnutls_mpi_ops = {
-  .bigint_new = wrap_gcry_mpi_new,
-  .bigint_cmp = wrap_gcry_mpi_cmp,
-  .bigint_cmp_ui = wrap_gcry_mpi_cmp_ui,
-  .bigint_mod = wrap_gcry_mpi_mod,
-  .bigint_set = wrap_gcry_mpi_set,
-  .bigint_set_ui = wrap_gcry_mpi_set_ui,
-  .bigint_get_nbits = wrap_gcry_mpi_get_nbits,
-  .bigint_powm = wrap_gcry_mpi_powm,
-  .bigint_addm = wrap_gcry_mpi_addm,
-  .bigint_subm = wrap_gcry_mpi_subm,
-  .bigint_add = wrap_gcry_mpi_add,
-  .bigint_sub = wrap_gcry_mpi_sub,
-  .bigint_add_ui = wrap_gcry_mpi_add_ui,
-  .bigint_sub_ui = wrap_gcry_mpi_sub_ui,
-  .bigint_mul = wrap_gcry_mpi_mul,
-  .bigint_mulm = wrap_gcry_mpi_mulm,
-  .bigint_mul_ui = wrap_gcry_mpi_mul_ui,
-  .bigint_div = wrap_gcry_mpi_div,
-  .bigint_prime_check = wrap_gcry_prime_check,
-  .bigint_release = wrap_gcry_mpi_release,
-  .bigint_print = wrap_gcry_mpi_print,
-  .bigint_scan = wrap_gcry_mpi_scan,
-  .bigint_generate_group = wrap_gcry_generate_group
-};
diff --git a/lib/gcrypt/pk.c b/lib/gcrypt/pk.c
deleted file mode 100644
index 11ff8b6..0000000
--- a/lib/gcrypt/pk.c
+++ /dev/null
@@ -1,859 +0,0 @@
-/*
- * Copyright (C) 2001-2011 Free Software Foundation, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS.
- *
- * The GnuTLS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-/* This file contains the functions needed for RSA/DSA public key
- * encryption and signatures. 
- */
-
-#error NO ECC SUPPORT
-
-#include <gnutls_int.h>
-#include <gnutls_mpi.h>
-#include <gnutls_pk.h>
-#include <gnutls_errors.h>
-#include <gnutls_datum.h>
-#include <gnutls_global.h>
-#include <gnutls_num.h>
-#include <x509/x509_int.h>
-#include <x509/common.h>
-#include <random.h>
-#include <gnutls_pk.h>
-#include <gcrypt.h>
-
-/* this is based on code from old versions of libgcrypt (centuries ago)
- */
-
-int (*generate) (gnutls_pk_algorithm_t, unsigned int level /*bits */ ,
-                 gnutls_pk_params_st *);
-
-static int
-_wrap_gcry_pk_encrypt (gnutls_pk_algorithm_t algo,
-                       gnutls_datum_t * ciphertext,
-                       const gnutls_datum_t * plaintext,
-                       const gnutls_pk_params_st * pk_params)
-{
-  gcry_sexp_t s_ciph = NULL, s_data = NULL, s_pkey = NULL;
-  int rc = -1;
-  int ret;
-  bigint_t data, res;
-  gcry_sexp_t list;
-
-  if (_gnutls_mpi_scan_nz (&data, plaintext->data, plaintext->size) != 0)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MPI_SCAN_FAILED;
-    }
-
-  /* make a sexp from pkey */
-  switch (algo)
-    {
-    case GNUTLS_PK_RSA:
-      if (pk_params->params_nr >= 2)
-        rc = gcry_sexp_build (&s_pkey, NULL,
-                              "(public-key(rsa(n%m)(e%m)))",
-                              pk_params->params[0], pk_params->params[1]);
-      break;
-
-    default:
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  if (rc != 0)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  /* put the data into a simple list */
-  if (gcry_sexp_build (&s_data, NULL, "%m", data))
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_MEMORY_ERROR;
-      goto cleanup;
-    }
-
-  /* pass it to libgcrypt */
-  rc = gcry_pk_encrypt (&s_ciph, s_data, s_pkey);
-  if (rc != 0)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_PK_ENCRYPTION_FAILED;
-      goto cleanup;
-    }
-
-  list = gcry_sexp_find_token (s_ciph, "a", 0);
-  if (list == NULL)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  res = gcry_sexp_nth_mpi (list, 1, 0);
-  gcry_sexp_release (list);
-  if (res == NULL)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  ret = _gnutls_mpi_dprint_size (res, ciphertext, plaintext->size);
-  _gnutls_mpi_release (&res);
-  if (ret < 0)
-    {
-      gnutls_assert ();
-      goto cleanup;
-    }
-
-  ret = 0;
-
-cleanup:
-  _gnutls_mpi_release (&data);
-  if (s_ciph)
-    gcry_sexp_release (s_ciph);
-  if (s_data)
-    gcry_sexp_release (s_data);
-  if (s_pkey)
-    gcry_sexp_release (s_pkey);
-
-  return ret;
-}
-
-static int
-_wrap_gcry_pk_decrypt (gnutls_pk_algorithm_t algo,
-                       gnutls_datum_t * plaintext,
-                       const gnutls_datum_t * ciphertext,
-                       const gnutls_pk_params_st * pk_params)
-{
-  gcry_sexp_t s_plain = NULL, s_data = NULL, s_pkey = NULL;
-  int rc = -1;
-  int ret;
-  bigint_t data, res;
-
-  if (_gnutls_mpi_scan_nz (&data, ciphertext->data, ciphertext->size) != 0)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MPI_SCAN_FAILED;
-    }
-
-  /* make a sexp from pkey */
-  switch (algo)
-    {
-    case GNUTLS_PK_RSA:
-      if (pk_params->params_nr >= 6)
-        rc = gcry_sexp_build (&s_pkey, NULL,
-                              
"(private-key(rsa((n%m)(e%m)(d%m)(p%m)(q%m)(u%m))))",
-                              pk_params->params[0], pk_params->params[1],
-                              pk_params->params[2], pk_params->params[3],
-                              pk_params->params[4], pk_params->params[5]);
-      break;
-
-    default:
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  if (rc != 0)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  /* put the data into a simple list */
-  if (gcry_sexp_build (&s_data, NULL, "(enc-val(rsa(a%m)))", data))
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  /* pass it to libgcrypt */
-  rc = gcry_pk_decrypt (&s_plain, s_data, s_pkey);
-  if (rc != 0)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_PK_DECRYPTION_FAILED;
-      goto cleanup;
-    }
-
-  res = gcry_sexp_nth_mpi (s_plain, 0, 0);
-  if (res == NULL)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  ret = _gnutls_mpi_dprint_size (res, plaintext, ciphertext->size);
-  _gnutls_mpi_release (&res);
-  if (ret < 0)
-    {
-      gnutls_assert ();
-      goto cleanup;
-    }
-
-  ret = 0;
-
-cleanup:
-  _gnutls_mpi_release (&data);
-  if (s_plain)
-    gcry_sexp_release (s_plain);
-  if (s_data)
-    gcry_sexp_release (s_data);
-  if (s_pkey)
-    gcry_sexp_release (s_pkey);
-
-  return ret;
-
-}
-
-
-/* in case of DSA puts into data, r,s
- */
-static int
-_wrap_gcry_pk_sign (gnutls_pk_algorithm_t algo, gnutls_datum_t * signature,
-                    const gnutls_datum_t * vdata,
-                    const gnutls_pk_params_st * pk_params)
-{
-  gcry_sexp_t s_hash = NULL, s_key = NULL, s_sig = NULL;
-  gcry_sexp_t list = NULL;
-  int rc = -1, ret;
-  bigint_t hash;
-  bigint_t res[2] = { NULL, NULL };
-
-  if (_gnutls_mpi_scan_nz (&hash, vdata->data, vdata->size) != 0)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MPI_SCAN_FAILED;
-    }
-
-  /* make a sexp from pkey */
-  switch (algo)
-    {
-    case GNUTLS_PK_DSA:
-      if (pk_params->params_nr >= 5)
-        rc = gcry_sexp_build (&s_key, NULL,
-                              "(private-key(dsa(p%m)(q%m)(g%m)(y%m)(x%m)))",
-                              pk_params->params[0], pk_params->params[1],
-                              pk_params->params[2], pk_params->params[3],
-                              pk_params->params[4]);
-      else
-        {
-          gnutls_assert ();
-        }
-
-      break;
-    case GNUTLS_PK_RSA:
-      if (pk_params->params_nr >= 6)
-        rc = gcry_sexp_build (&s_key, NULL,
-                              
"(private-key(rsa((n%m)(e%m)(d%m)(p%m)(q%m)(u%m))))",
-                              pk_params->params[0], pk_params->params[1],
-                              pk_params->params[2], pk_params->params[3],
-                              pk_params->params[4], pk_params->params[5]);
-      else
-        {
-          gnutls_assert ();
-        }
-      break;
-
-    default:
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  if (rc != 0)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  /* put the data into a simple list */
-  if (gcry_sexp_build (&s_hash, NULL, "%m", hash))
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-
-  /* pass it to libgcrypt */
-  rc = gcry_pk_sign (&s_sig, s_hash, s_key);
-  if (rc != 0)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_PK_SIGN_FAILED;
-      goto cleanup;
-    }
-
-  ret = GNUTLS_E_INTERNAL_ERROR;
-
-  switch (algo)
-    {
-    case GNUTLS_PK_DSA:
-      {
-        list = gcry_sexp_find_token (s_sig, "r", 0);
-        if (list == NULL)
-          {
-            gnutls_assert ();
-            ret = GNUTLS_E_INTERNAL_ERROR;
-            goto cleanup;
-          }
-
-        res[0] = gcry_sexp_nth_mpi (list, 1, 0);
-        gcry_sexp_release (list);
-
-        list = gcry_sexp_find_token (s_sig, "s", 0);
-        if (list == NULL)
-          {
-            gnutls_assert ();
-            ret = GNUTLS_E_INTERNAL_ERROR;
-            goto cleanup;
-          }
-
-        res[1] = gcry_sexp_nth_mpi (list, 1, 0);
-        gcry_sexp_release (list);
-
-        ret = _gnutls_encode_ber_rs (signature, res[0], res[1]);
-        if (ret < 0)
-          {
-            gnutls_assert ();
-            goto cleanup;
-          }
-      }
-      break;
-
-    case GNUTLS_PK_RSA:
-      {
-        list = gcry_sexp_find_token (s_sig, "s", 0);
-        if (list == NULL)
-          {
-            gnutls_assert ();
-            ret = GNUTLS_E_INTERNAL_ERROR;
-            goto cleanup;
-          }
-
-        res[0] = gcry_sexp_nth_mpi (list, 1, 0);
-        gcry_sexp_release (list);
-
-        ret = _gnutls_mpi_dprint (res[0], signature);
-        if (ret < 0)
-          {
-            gnutls_assert ();
-            goto cleanup;
-          }
-      }
-      break;
-
-    default:
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  ret = 0;
-
-cleanup:
-  _gnutls_mpi_release (&hash);
-  if (res[0])
-    _gnutls_mpi_release (&res[0]);
-  if (res[1])
-    _gnutls_mpi_release (&res[1]);
-  if (s_sig)
-    gcry_sexp_release (s_sig);
-  if (s_hash)
-    gcry_sexp_release (s_hash);
-  if (s_key)
-    gcry_sexp_release (s_key);
-
-  return ret;
-}
-
-static int
-_wrap_gcry_pk_verify (gnutls_pk_algorithm_t algo,
-                      const gnutls_datum_t * vdata,
-                      const gnutls_datum_t * signature,
-                      const gnutls_pk_params_st * pk_params)
-{
-  gcry_sexp_t s_sig = NULL, s_hash = NULL, s_pkey = NULL;
-  int rc = -1, ret;
-  bigint_t hash;
-  bigint_t tmp[2] = { NULL, NULL };
-
-  if (_gnutls_mpi_scan_nz (&hash, vdata->data, vdata->size) != 0)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MPI_SCAN_FAILED;
-    }
-
-  /* make a sexp from pkey */
-  switch (algo)
-    {
-    case GNUTLS_PK_DSA:
-      if (pk_params->params_nr >= 4)
-        rc = gcry_sexp_build (&s_pkey, NULL,
-                              "(public-key(dsa(p%m)(q%m)(g%m)(y%m)))",
-                              pk_params->params[0], pk_params->params[1],
-                              pk_params->params[2], pk_params->params[3]);
-      break;
-    case GNUTLS_PK_RSA:
-      if (pk_params->params_nr >= 2)
-        rc = gcry_sexp_build (&s_pkey, NULL,
-                              "(public-key(rsa(n%m)(e%m)))",
-                              pk_params->params[0], pk_params->params[1]);
-      break;
-
-    default:
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  if (rc != 0)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  /* put the data into a simple list */
-  if (gcry_sexp_build (&s_hash, NULL, "%m", hash))
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  switch (algo)
-    {
-    case GNUTLS_PK_DSA:
-      ret = _gnutls_decode_ber_rs (signature, &tmp[0], &tmp[1]);
-      if (ret < 0)
-        {
-          gnutls_assert ();
-          goto cleanup;
-        }
-      rc = gcry_sexp_build (&s_sig, NULL,
-                            "(sig-val(dsa(r%m)(s%m)))", tmp[0], tmp[1]);
-      _gnutls_mpi_release (&tmp[0]);
-      _gnutls_mpi_release (&tmp[1]);
-      break;
-
-    case GNUTLS_PK_RSA:
-      ret = _gnutls_mpi_scan_nz (&tmp[0], signature->data, signature->size);
-      if (ret < 0)
-        {
-          gnutls_assert ();
-          goto cleanup;
-        }
-      rc = gcry_sexp_build (&s_sig, NULL, "(sig-val(rsa(s%m)))", tmp[0]);
-      _gnutls_mpi_release (&tmp[0]);
-      break;
-
-    default:
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  if (rc != 0)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_INTERNAL_ERROR;
-      goto cleanup;
-    }
-
-  rc = gcry_pk_verify (s_sig, s_hash, s_pkey);
-
-  if (rc != 0)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_PK_SIG_VERIFY_FAILED;
-      goto cleanup;
-    }
-
-  ret = 0;
-
-cleanup:
-  _gnutls_mpi_release (&hash);
-  if (s_sig)
-    gcry_sexp_release (s_sig);
-  if (s_hash)
-    gcry_sexp_release (s_hash);
-  if (s_pkey)
-    gcry_sexp_release (s_pkey);
-
-  return ret;
-}
-
-static int
-_dsa_generate_params (bigint_t * resarr, int *resarr_len, int bits)
-{
-
-  int ret;
-  gcry_sexp_t parms, key, list;
-
-  /* FIXME: Remove me once we depend on 1.3.1 */
-  if (bits > 1024 && gcry_check_version ("1.3.1") == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INVALID_REQUEST;
-    }
-
-  if (bits < 512)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INVALID_REQUEST;
-    }
-
-  ret = gcry_sexp_build (&parms, NULL, "(genkey(dsa(nbits %d)))", bits);
-  if (ret != 0)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  /* generate the DSA key 
-   */
-  ret = gcry_pk_genkey (&key, parms);
-  gcry_sexp_release (parms);
-
-  if (ret != 0)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  list = gcry_sexp_find_token (key, "p", 0);
-  if (list == NULL)
-    {
-      gnutls_assert ();
-      gcry_sexp_release (key);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  resarr[0] = gcry_sexp_nth_mpi (list, 1, 0);
-  gcry_sexp_release (list);
-
-  list = gcry_sexp_find_token (key, "q", 0);
-  if (list == NULL)
-    {
-      gnutls_assert ();
-      gcry_sexp_release (key);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  resarr[1] = gcry_sexp_nth_mpi (list, 1, 0);
-  gcry_sexp_release (list);
-
-  list = gcry_sexp_find_token (key, "g", 0);
-  if (list == NULL)
-    {
-      gnutls_assert ();
-      gcry_sexp_release (key);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  resarr[2] = gcry_sexp_nth_mpi (list, 1, 0);
-  gcry_sexp_release (list);
-
-  list = gcry_sexp_find_token (key, "y", 0);
-  if (list == NULL)
-    {
-      gnutls_assert ();
-      gcry_sexp_release (key);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  resarr[3] = gcry_sexp_nth_mpi (list, 1, 0);
-  gcry_sexp_release (list);
-
-
-  list = gcry_sexp_find_token (key, "x", 0);
-  if (list == NULL)
-    {
-      gnutls_assert ();
-      gcry_sexp_release (key);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  resarr[4] = gcry_sexp_nth_mpi (list, 1, 0);
-
-  gcry_sexp_release (list);
-  gcry_sexp_release (key);
-
-  _gnutls_mpi_log ("p: ", resarr[0]);
-  _gnutls_mpi_log ("q: ", resarr[1]);
-  _gnutls_mpi_log ("g: ", resarr[2]);
-  _gnutls_mpi_log ("y: ", resarr[3]);
-  _gnutls_mpi_log ("x: ", resarr[4]);
-
-  *resarr_len = 5;
-
-  return 0;
-
-}
-
-static int
-_rsa_generate_params (bigint_t * resarr, int *resarr_len, int bits)
-{
-
-  int ret, i;
-  gcry_sexp_t parms, key, list;
-  bigint_t tmp;
-
-  if (*resarr_len < RSA_PRIVATE_PARAMS)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  ret = gcry_sexp_build (&parms, NULL, "(genkey(rsa(nbits %d)))", bits);
-  if (ret != 0)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  /* generate the RSA key */
-  ret = gcry_pk_genkey (&key, parms);
-  gcry_sexp_release (parms);
-
-  if (ret != 0)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  list = gcry_sexp_find_token (key, "n", 0);
-  if (list == NULL)
-    {
-      gnutls_assert ();
-      gcry_sexp_release (key);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  resarr[0] = gcry_sexp_nth_mpi (list, 1, 0);
-  gcry_sexp_release (list);
-
-  list = gcry_sexp_find_token (key, "e", 0);
-  if (list == NULL)
-    {
-      gnutls_assert ();
-      gcry_sexp_release (key);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  resarr[1] = gcry_sexp_nth_mpi (list, 1, 0);
-  gcry_sexp_release (list);
-
-  list = gcry_sexp_find_token (key, "d", 0);
-  if (list == NULL)
-    {
-      gnutls_assert ();
-      gcry_sexp_release (key);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  resarr[2] = gcry_sexp_nth_mpi (list, 1, 0);
-  gcry_sexp_release (list);
-
-  list = gcry_sexp_find_token (key, "p", 0);
-  if (list == NULL)
-    {
-      gnutls_assert ();
-      gcry_sexp_release (key);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  resarr[3] = gcry_sexp_nth_mpi (list, 1, 0);
-  gcry_sexp_release (list);
-
-
-  list = gcry_sexp_find_token (key, "q", 0);
-  if (list == NULL)
-    {
-      gnutls_assert ();
-      gcry_sexp_release (key);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  resarr[4] = gcry_sexp_nth_mpi (list, 1, 0);
-  gcry_sexp_release (list);
-
-
-  list = gcry_sexp_find_token (key, "u", 0);
-  if (list == NULL)
-    {
-      gnutls_assert ();
-      gcry_sexp_release (key);
-      return GNUTLS_E_INTERNAL_ERROR;
-    }
-
-  resarr[5] = gcry_sexp_nth_mpi (list, 1, 0);
-
-  gcry_sexp_release (list);
-  gcry_sexp_release (key);
-
-  _gnutls_mpi_log ("n: ", resarr[0]);
-  _gnutls_mpi_log ("e: ", resarr[1]);
-  _gnutls_mpi_log ("d: ", resarr[2]);
-  _gnutls_mpi_log ("p: ", resarr[3]);
-  _gnutls_mpi_log ("q: ", resarr[4]);
-  _gnutls_mpi_log ("u: ", resarr[5]);
-
-  /* generate e1 and e2 */
-
-  *resarr_len = 6;
-
-  tmp = _gnutls_mpi_alloc_like (resarr[0]);
-  if (tmp == NULL)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_MEMORY_ERROR;
-      goto cleanup;
-    }
-
-  ret = _gnutls_calc_rsa_exp (resarr, 2 + *resarr_len);
-  if (ret < 0)
-    {
-      gnutls_assert ();
-      ret = GNUTLS_E_MEMORY_ERROR;
-      goto cleanup;
-    }
-
-  (*resarr_len) += 2;
-
-  return 0;
-
-cleanup:
-  for (i = 0; i < *resarr_len; i++)
-    _gnutls_mpi_release (&resarr[i]);
-
-  return ret;
-}
-
-
-static int
-wrap_gcry_pk_generate_params (gnutls_pk_algorithm_t algo,
-                              unsigned int level /*bits */ ,
-                              gnutls_pk_params_st * params)
-{
-
-  switch (algo)
-    {
-
-    case GNUTLS_PK_DSA:
-      params->params_nr = DSA_PRIVATE_PARAMS;
-      if (params->params_nr > GNUTLS_MAX_PK_PARAMS)
-        {
-          gnutls_assert ();
-          return GNUTLS_E_INTERNAL_ERROR;
-        }
-      return _dsa_generate_params (params->params, &params->params_nr, level);
-
-    case GNUTLS_PK_RSA:
-      params->params_nr = RSA_PRIVATE_PARAMS;
-      if (params->params_nr > GNUTLS_MAX_PK_PARAMS)
-        {
-          gnutls_assert ();
-          return GNUTLS_E_INTERNAL_ERROR;
-        }
-      return _rsa_generate_params (params->params, &params->params_nr, level);
-
-    default:
-      gnutls_assert ();
-      return GNUTLS_E_INVALID_REQUEST;
-    }
-}
-
-
-static int
-wrap_gcry_pk_fixup (gnutls_pk_algorithm_t algo,
-                    gnutls_direction_t direction,
-                    gnutls_pk_params_st * params)
-{
-  int ret, result;
-
-  /* only for RSA we invert the coefficient --pgp type */
-
-  if (algo != GNUTLS_PK_RSA)
-    return 0;
-
-  if (params->params[5] == NULL)
-    params->params[5] =
-      _gnutls_mpi_new (_gnutls_mpi_get_nbits (params->params[0]));
-
-  if (params->params[5] == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  ret = 1;
-  if (direction == GNUTLS_IMPORT)
-    {
-      /* calculate exp1 [6] and exp2 [7] */
-      _gnutls_mpi_release (&params->params[6]);
-      _gnutls_mpi_release (&params->params[7]);
-      result = _gnutls_calc_rsa_exp (params->params, RSA_PRIVATE_PARAMS);
-      if (result < 0)
-        {
-          gnutls_assert ();
-          return result;
-        }
-
-      ret =
-        gcry_mpi_invm (params->params[5], params->params[3],
-                       params->params[4]);
-
-      params->params_nr = RSA_PRIVATE_PARAMS;
-    }
-  else if (direction == GNUTLS_EXPORT)
-    ret =
-      gcry_mpi_invm (params->params[5], params->params[4], params->params[3]);
-  if (ret == 0)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INVALID_REQUEST;
-    }
-
-  return 0;
-}
-
-int crypto_pk_prio = INT_MAX;
-
-gnutls_crypto_pk_st _gnutls_pk_ops = {
-  .encrypt = _wrap_gcry_pk_encrypt,
-  .decrypt = _wrap_gcry_pk_decrypt,
-  .sign = _wrap_gcry_pk_sign,
-  .verify = _wrap_gcry_pk_verify,
-  .generate = wrap_gcry_pk_generate_params,
-  .pk_fixup_private_params = wrap_gcry_pk_fixup,
-};
diff --git a/lib/gcrypt/rnd.c b/lib/gcrypt/rnd.c
deleted file mode 100644
index 842b09e..0000000
--- a/lib/gcrypt/rnd.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright (C) 2008-2011 Free Software Foundation, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS.
- *
- * The GnuTLS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-/* Here is the libgcrypt random generator layer.
- */
-
-#include <gnutls_int.h>
-#include <gnutls_errors.h>
-#include <gnutls_num.h>
-#include <gnutls_mpi.h>
-#include <gcrypt.h>
-
-static int
-wrap_gcry_rnd_init (void **ctx)
-{
-  char c;
-
-  gcry_create_nonce (&c, 1);
-  gcry_randomize (&c, 1, GCRY_STRONG_RANDOM);
-
-  return 0;
-}
-
-static int
-wrap_gcry_rnd (void *ctx, int level, void *data, size_t datasize)
-{
-  if (level == GNUTLS_RND_NONCE)
-    gcry_create_nonce (data, datasize);
-  else
-    gcry_randomize (data, datasize, level);
-
-  return 0;
-}
-
-int crypto_rnd_prio = INT_MAX;
-
-gnutls_crypto_rnd_st _gnutls_rnd_ops = {
-  .init = wrap_gcry_rnd_init,
-  .deinit = NULL,
-  .rnd = wrap_gcry_rnd,
-};
diff --git a/lib/gnutls_cert.c b/lib/gnutls_cert.c
index e72a662..802f671 100644
--- a/lib/gnutls_cert.c
+++ b/lib/gnutls_cert.c
@@ -790,7 +790,7 @@ gnutls_certificate_activation_time_peers (gnutls_session_t 
session)
  * can be used to store application-specific data needed in the
  * callback function.  See also gnutls_sign_callback_get().
  *
- * Deprecated: Use the PKCS 11 interfaces instead.
+ * Deprecated: Use the PKCS 11 or #gnutls_privkey_t interfacess instead.
  */
 void
 gnutls_sign_callback_set (gnutls_session_t session,
diff --git a/lib/gnutls_cipher.c b/lib/gnutls_cipher.c
index 75ca6ab..716b7c9 100644
--- a/lib/gnutls_cipher.c
+++ b/lib/gnutls_cipher.c
@@ -105,7 +105,7 @@ _gnutls_encrypt (gnutls_session_t session, const opaque * 
headers,
       if (comp.data == NULL)
         return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
       
-      ret = _gnutls_compress( params->write.compression_state, data, 
data_size, comp.data, comp.size);
+      ret = _gnutls_compress( &params->write.compression_state, data, 
data_size, comp.data, comp.size);
       if (ret < 0)
         {
           gnutls_free(comp.data);
@@ -182,7 +182,7 @@ _gnutls_decrypt (gnutls_session_t session, opaque * 
ciphertext,
         
       if (ret != 0)
         {
-          ret = _gnutls_decompress(params->read.compression_state, tmp_data, 
data_size, data, max_data_size);
+          ret = _gnutls_decompress( &params->read.compression_state, tmp_data, 
data_size, data, max_data_size);
           if (ret < 0)
             goto leave;
         }
diff --git a/lib/gnutls_cipher_int.c b/lib/gnutls_cipher_int.c
index d61d2c8..5814d51 100644
--- a/lib/gnutls_cipher_int.c
+++ b/lib/gnutls_cipher_int.c
@@ -41,6 +41,9 @@ _gnutls_cipher_init (cipher_hd_st * handle, 
gnutls_cipher_algorithm_t cipher,
   int ret = GNUTLS_E_INTERNAL_ERROR;
   const gnutls_crypto_cipher_st *cc = NULL;
 
+  if (cipher == GNUTLS_CIPHER_NULL)
+    return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+
   handle->is_aead = _gnutls_cipher_algo_is_aead(cipher);
   if (handle->is_aead)
      handle->tag_size = gnutls_cipher_get_block_size(cipher);
@@ -124,12 +127,14 @@ int ret;
 
   memset(handle, 0, sizeof(*handle));
 
-  ret = _gnutls_cipher_init(&handle->cipher, cipher, cipher_key, iv, enc);
-  if (ret < 0)
+  if (cipher != GNUTLS_CIPHER_NULL)
     {
-      gnutls_assert();
-      return ret;
+      ret = _gnutls_cipher_init(&handle->cipher, cipher, cipher_key, iv, enc);
+      if (ret < 0)
+        return gnutls_assert_val(ret);
     }
+  else
+    handle->is_null = 1;
 
   if (mac != GNUTLS_MAC_AEAD)
     {
@@ -153,7 +158,8 @@ int ret;
 
   return 0;
 cleanup:
-  _gnutls_cipher_deinit(&handle->cipher);
+  if (handle->is_null == 0)
+    _gnutls_cipher_deinit(&handle->cipher);
   return ret;
 
 }
@@ -196,9 +202,12 @@ int ret;
       if (ret < 0)
         return gnutls_assert_val(ret);
 
-      ret = _gnutls_cipher_encrypt2(&handle->cipher, text, textlen, 
ciphertext, ciphertextlen);
-      if (ret < 0)
-        return gnutls_assert_val(ret);
+      if (handle->is_null==0)
+        {
+          ret = _gnutls_cipher_encrypt2(&handle->cipher, text, textlen, 
ciphertext, ciphertextlen);
+          if (ret < 0)
+            return gnutls_assert_val(ret);
+        }
     }
   else if (_gnutls_cipher_is_aead(&handle->cipher))
     {
@@ -220,12 +229,12 @@ int _gnutls_auth_cipher_decrypt2 (auth_cipher_hd_st * 
handle,
 {
 int ret;
 
-  ret = _gnutls_cipher_decrypt2(&handle->cipher, ciphertext, ciphertextlen, 
-    text, textlen);
-  if (ret < 0)
+  if (handle->is_null==0)
     {
-      gnutls_assert();
-      return ret;
+      ret = _gnutls_cipher_decrypt2(&handle->cipher, ciphertext, 
ciphertextlen, 
+        text, textlen);
+      if (ret < 0)
+        return gnutls_assert_val(ret);
     }
 
   if (handle->is_mac)
@@ -278,5 +287,6 @@ void _gnutls_auth_cipher_deinit (auth_cipher_hd_st * handle)
       else
         _gnutls_hmac_deinit(&handle->mac, NULL);
     }
-  _gnutls_cipher_deinit(&handle->cipher);
+  if (handle->is_null==0)
+    _gnutls_cipher_deinit(&handle->cipher);
 }
diff --git a/lib/gnutls_cipher_int.h b/lib/gnutls_cipher_int.h
index bd2b68d..301bce8 100644
--- a/lib/gnutls_cipher_int.h
+++ b/lib/gnutls_cipher_int.h
@@ -141,8 +141,9 @@ typedef struct
 {
   cipher_hd_st cipher;
   digest_hd_st mac;
-  int is_mac:1;
-  int ssl_hmac:1;
+  unsigned int is_mac:1;
+  unsigned int ssl_hmac:1;
+  unsigned int is_null:1;
   int tag_size;
 } auth_cipher_hd_st;
 
diff --git a/lib/gnutls_compress.c b/lib/gnutls_compress.c
index d682511..3821a84 100644
--- a/lib/gnutls_compress.c
+++ b/lib/gnutls_compress.c
@@ -241,20 +241,10 @@ _gnutls_supported_compression_methods (gnutls_session_t 
session,
 /* The flag d is the direction (compress, decompress). Non zero is
  * decompress.
  */
-comp_hd_t
-_gnutls_comp_init (gnutls_compression_method_t method, int d)
+int _gnutls_comp_init (comp_hd_st* handle, gnutls_compression_method_t method, 
int d)
 {
-  comp_hd_t ret;
-
-  ret = gnutls_malloc (sizeof (struct comp_hd_t_STRUCT));
-  if (ret == NULL)
-    {
-      gnutls_assert ();
-      return NULL;
-    }
-
-  ret->algo = method;
-  ret->handle = NULL;
+  handle->algo = method;
+  handle->handle = NULL;
 
   switch (method)
     {
@@ -270,14 +260,11 @@ _gnutls_comp_init (gnutls_compression_method_t method, 
int d)
         mem_level = get_mem_level (method);
         comp_level = get_comp_level (method);
 
-        ret->handle = gnutls_malloc (sizeof (z_stream));
-        if (ret->handle == NULL)
-          {
-            gnutls_assert ();
-            goto cleanup_ret;
-          }
+        handle->handle = gnutls_malloc (sizeof (z_stream));
+        if (handle->handle == NULL)
+          return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
 
-        zhandle = ret->handle;
+        zhandle = handle->handle;
 
         zhandle->zalloc = (alloc_func) 0;
         zhandle->zfree = (free_func) 0;
@@ -294,8 +281,8 @@ _gnutls_comp_init (gnutls_compression_method_t method, int 
d)
         if (err != Z_OK)
           {
             gnutls_assert ();
-            gnutls_free (ret->handle);
-            goto cleanup_ret;
+            gnutls_free (handle->handle);
+            return GNUTLS_E_COMPRESSION_FAILED;
           }
       }
       break;
@@ -303,20 +290,18 @@ _gnutls_comp_init (gnutls_compression_method_t method, 
int d)
     case GNUTLS_COMP_NULL:
     case GNUTLS_COMP_UNKNOWN:
       break;
+    default:
+      return GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM;
     }
 
-  return ret;
-
-cleanup_ret:
-  gnutls_free (ret);
-  return NULL;
+  return 0;
 }
 
 /* The flag d is the direction (compress, decompress). Non zero is
  * decompress.
  */
 void
-_gnutls_comp_deinit (comp_hd_t handle, int d)
+_gnutls_comp_deinit (comp_hd_st* handle, int d)
 {
   if (handle != NULL)
     {
@@ -336,8 +321,7 @@ _gnutls_comp_deinit (comp_hd_t handle, int d)
           break;
         }
       gnutls_free (handle->handle);
-      gnutls_free (handle);
-
+      handle->handle = NULL;
     }
 }
 
@@ -345,7 +329,7 @@ _gnutls_comp_deinit (comp_hd_t handle, int d)
  */
 
 int
-_gnutls_compress (comp_hd_t handle, const opaque * plain,
+_gnutls_compress (comp_hd_st *handle, const opaque * plain,
                   size_t plain_size, opaque * compressed,
                   size_t max_comp_size)
 {
@@ -399,7 +383,7 @@ _gnutls_compress (comp_hd_t handle, const opaque * plain,
 
 
 int
-_gnutls_decompress (comp_hd_t handle, opaque * compressed,
+_gnutls_decompress (comp_hd_st *handle, opaque * compressed,
                     size_t compressed_size, opaque * plain,
                     size_t max_plain_size)
 {
diff --git a/lib/gnutls_compress.h b/lib/gnutls_compress.h
index 7f3545c..559906d 100644
--- a/lib/gnutls_compress.h
+++ b/lib/gnutls_compress.h
@@ -35,19 +35,19 @@ gnutls_compression_method_t _gnutls_compression_get_id (int 
num);
 
 #define GNUTLS_COMP_FAILED NULL
 
-typedef struct comp_hd_t_STRUCT
+typedef struct comp_hd_st
 {
   void *handle;
   gnutls_compression_method_t algo;
-} *comp_hd_t;
+} comp_hd_st;
 
-comp_hd_t _gnutls_comp_init (gnutls_compression_method_t, int d);
-void _gnutls_comp_deinit (comp_hd_t handle, int d);
+int _gnutls_comp_init (comp_hd_st*, gnutls_compression_method_t, int d);
+void _gnutls_comp_deinit (comp_hd_st* handle, int d);
 
-int _gnutls_decompress (comp_hd_t handle, opaque * compressed,
+int _gnutls_decompress (comp_hd_st* handle, opaque * compressed,
                         size_t compressed_size, opaque * plain,
                         size_t max_plain_size);
-int _gnutls_compress (comp_hd_t, const opaque * plain, size_t plain_size,
+int _gnutls_compress (comp_hd_st*, const opaque * plain, size_t plain_size,
                       opaque * compressed, size_t max_comp_size);
 
 struct gnutls_compression_entry
diff --git a/lib/gnutls_constate.c b/lib/gnutls_constate.c
index d747cc3..f1d7528 100644
--- a/lib/gnutls_constate.c
+++ b/lib/gnutls_constate.c
@@ -71,13 +71,17 @@ _gnutls_set_keys (gnutls_session_t session, 
record_parameters_st * params,
                    2 * MAX_CIPHER_BLOCK_SIZE];
   record_state_st *client_write, *server_write;
 
-  client_write =
-    session->security_parameters.entity ==
-    GNUTLS_CLIENT ? &params->write : &params->read;
-  server_write =
-    session->security_parameters.entity ==
-    GNUTLS_SERVER ? &params->write : &params->read;
-
+  if (session->security_parameters.entity == GNUTLS_CLIENT)
+    {
+      client_write = &params->write;
+      server_write = &params->read;
+    }
+  else
+    {
+      client_write = &params->read;
+      server_write = &params->write;
+    }
+      
   block_size = 2 * hash_size + 2 * key_size;
   if (export_flag == 0)
     block_size += 2 * IV_size;
@@ -306,11 +310,11 @@ _gnutls_init_record_state (record_parameters_st * params, 
gnutls_protocol_t ver,
   if (ret < 0 && params->cipher_algorithm != GNUTLS_CIPHER_NULL)
     return gnutls_assert_val (ret);
 
-  state->compression_state =
-    _gnutls_comp_init (params->compression_algorithm, read/*1==decompress*/);
+  ret =
+    _gnutls_comp_init (&state->compression_state, 
params->compression_algorithm, read/*1==decompress*/);
 
-  if (state->compression_state == GNUTLS_COMP_FAILED)
-    return gnutls_assert_val (GNUTLS_E_UNKNOWN_COMPRESSION_ALGORITHM);
+  if (ret < 0)
+    return gnutls_assert_val (ret);
 
   return 0;
 }
@@ -815,8 +819,8 @@ free_record_state (record_state_st * state, int d)
 
   _gnutls_auth_cipher_deinit (&state->cipher_state);
 
-  if (state->compression_state != NULL)
-    _gnutls_comp_deinit (state->compression_state, d);
+  if (state->compression_state.handle != NULL)
+    _gnutls_comp_deinit (&state->compression_state, d);
 }
 
 void
diff --git a/lib/gnutls_db.c b/lib/gnutls_db.c
index ff8de18..5e07b04 100644
--- a/lib/gnutls_db.c
+++ b/lib/gnutls_db.c
@@ -1,6 +1,5 @@
 /*
- * Copyright (C) 2000, 2002, 2003, 2004, 2005, 2008, 2010, 2011 Free Software
- * Foundation, Inc.
+ * Copyright (C) 2000-2011 Free Software Foundation, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
  *
@@ -28,7 +27,6 @@
 #include "gnutls_int.h"
 #include "gnutls_errors.h"
 #include <gnutls_db.h>
-#include "debug.h"
 #include <gnutls_session_pack.h>
 #include <gnutls_datum.h>
 
@@ -165,51 +163,11 @@ gnutls_db_check_entry (gnutls_session_t session, 
gnutls_datum_t session_entry)
   return 0;
 }
 
-/* The format of storing data is:
- * (forget it). Check gnutls_session_pack.c
- */
-int
-_gnutls_server_register_current_session (gnutls_session_t session)
-{
-  gnutls_datum_t key;
-  gnutls_datum_t content;
-  int ret = 0;
-
-  key.data = session->security_parameters.session_id;
-  key.size = session->security_parameters.session_id_size;
-
-  if (session->internals.resumable == RESUME_FALSE)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INVALID_SESSION;
-    }
-
-  if (session->security_parameters.session_id == NULL
-      || session->security_parameters.session_id_size == 0)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_INVALID_SESSION;
-    }
-
-/* copy data */
-  ret = _gnutls_session_pack (session, &content);
-  if (ret < 0)
-    {
-      gnutls_assert ();
-      return ret;
-    }
-
-  ret = _gnutls_store_session (session, key, content);
-  _gnutls_free_datum (&content);
-
-  return ret;
-}
-
 /* Checks if both db_store and db_retrieve functions have
  * been set up.
  */
 static int
-_gnutls_db_func_is_ok (gnutls_session_t session)
+db_func_is_ok (gnutls_session_t session)
 {
   if (session->internals.db_store_func != NULL &&
       session->internals.db_retrieve_func != NULL &&
@@ -219,103 +177,86 @@ _gnutls_db_func_is_ok (gnutls_session_t session)
     return GNUTLS_E_DB_ERROR;
 }
 
-
-int
-_gnutls_server_restore_session (gnutls_session_t session,
-                                uint8_t * session_id, int session_id_size)
+/* Stores session data to the db backend.
+ */
+static int
+store_session (gnutls_session_t session,
+              gnutls_datum_t session_id,
+              gnutls_datum_t session_data)
 {
-  gnutls_datum_t data;
-  gnutls_datum_t key;
-  int ret;
-
-  key.data = session_id;
-  key.size = session_id_size;
+  int ret = 0;
 
-  if (_gnutls_db_func_is_ok (session) != 0)
+  if (session->internals.resumable == RESUME_FALSE)
     {
       gnutls_assert ();
       return GNUTLS_E_INVALID_SESSION;
     }
 
-  data = _gnutls_retrieve_session (session, key);
+  if (db_func_is_ok (session) != 0)
+    {
+      return GNUTLS_E_DB_ERROR;
+    }
 
-  if (data.data == NULL)
+  if (session_id.data == NULL || session_id.size == 0)
     {
       gnutls_assert ();
       return GNUTLS_E_INVALID_SESSION;
     }
 
-  /* expiration check is performed inside */
-  ret = gnutls_session_set_data (session, data.data, data.size);
-  if (ret < 0)
+  if (session_data.data == NULL || session_data.size == 0)
     {
       gnutls_assert ();
-      return ret;
+      return GNUTLS_E_INVALID_SESSION;
     }
 
-  gnutls_free (data.data);
+  /* if we can't read why bother writing? */
+  if (session->internals.db_store_func != NULL)
+    ret = session->internals.db_store_func (session->internals.db_ptr,
+                                           session_id, session_data);
 
-  return 0;
+  return (ret == 0 ? ret : GNUTLS_E_DB_ERROR);
 }
 
 int
-_gnutls_db_remove_session (gnutls_session_t session, uint8_t * session_id,
-                           int session_id_size)
+_gnutls_server_register_current_session (gnutls_session_t session)
 {
   gnutls_datum_t key;
-
-  key.data = session_id;
-  key.size = session_id_size;
-
-  return _gnutls_remove_session (session, key);
-}
-
-
-/* Stores session data to the db backend.
- */
-int
-_gnutls_store_session (gnutls_session_t session,
-                       gnutls_datum_t session_id, gnutls_datum_t session_data)
-{
+  gnutls_datum_t content;
   int ret = 0;
 
+  key.data = session->security_parameters.session_id;
+  key.size = session->security_parameters.session_id_size;
+
   if (session->internals.resumable == RESUME_FALSE)
     {
       gnutls_assert ();
       return GNUTLS_E_INVALID_SESSION;
     }
 
-  if (_gnutls_db_func_is_ok (session) != 0)
-    {
-      return GNUTLS_E_DB_ERROR;
-    }
-
-  if (session_id.data == NULL || session_id.size == 0)
+  if (session->security_parameters.session_id == NULL
+      || session->security_parameters.session_id_size == 0)
     {
       gnutls_assert ();
       return GNUTLS_E_INVALID_SESSION;
     }
 
-  if (session_data.data == NULL || session_data.size == 0)
+  ret = _gnutls_session_pack (session, &content);
+  if (ret < 0)
     {
       gnutls_assert ();
-      return GNUTLS_E_INVALID_SESSION;
+      return ret;
     }
-  /* if we can't read why bother writing? */
 
-  if (session->internals.db_store_func != NULL)
-    ret =
-      session->internals.db_store_func (session->internals.db_ptr,
-                                        session_id, session_data);
-
-  return (ret == 0 ? ret : GNUTLS_E_DB_ERROR);
+  ret = store_session (session, key, content);
+  _gnutls_free_datum (&content);
 
+  return ret;
 }
 
 /* Retrieves session data from the db backend.
  */
-gnutls_datum_t
-_gnutls_retrieve_session (gnutls_session_t session, gnutls_datum_t session_id)
+static gnutls_datum_t
+retrieve_session (gnutls_session_t session, gnutls_datum_t session_id)
 {
   gnutls_datum_t ret = { NULL, 0 };
 
@@ -326,37 +267,48 @@ _gnutls_retrieve_session (gnutls_session_t session, 
gnutls_datum_t session_id)
     }
 
   if (session->internals.db_retrieve_func != NULL)
-    ret =
-      session->internals.db_retrieve_func (session->internals.db_ptr,
-                                           session_id);
+    ret = session->internals.db_retrieve_func (session->internals.db_ptr,
+                                              session_id);
 
   return ret;
-
 }
 
-/* Removes session data from the db backend.
- */
 int
-_gnutls_remove_session (gnutls_session_t session, gnutls_datum_t session_id)
+_gnutls_server_restore_session (gnutls_session_t session,
+                                uint8_t * session_id, int session_id_size)
 {
-  int ret = 0;
+  gnutls_datum_t data;
+  gnutls_datum_t key;
+  int ret;
 
-  if (_gnutls_db_func_is_ok (session) != 0)
+  key.data = session_id;
+  key.size = session_id_size;
+
+  if (db_func_is_ok (session) != 0)
     {
-      return GNUTLS_E_DB_ERROR;
+      gnutls_assert ();
+      return GNUTLS_E_INVALID_SESSION;
     }
 
-  if (session_id.data == NULL || session_id.size == 0)
-    return GNUTLS_E_INVALID_SESSION;
+  data = retrieve_session (session, key);
 
-  /* if we can't read why bother writing? */
-  if (session->internals.db_remove_func != NULL)
-    ret =
-      session->internals.db_remove_func (session->internals.db_ptr,
-                                         session_id);
+  if (data.data == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_INVALID_SESSION;
+    }
 
-  return (ret == 0 ? ret : GNUTLS_E_DB_ERROR);
+  /* expiration check is performed inside */
+  ret = gnutls_session_set_data (session, data.data, data.size);
+  if (ret < 0)
+    {
+      gnutls_assert ();
+      return ret;
+    }
 
+  gnutls_free (data.data);
+
+  return 0;
 }
 
 /**
@@ -374,7 +326,30 @@ _gnutls_remove_session (gnutls_session_t session, 
gnutls_datum_t session_id)
 void
 gnutls_db_remove_session (gnutls_session_t session)
 {
-  _gnutls_db_remove_session (session,
-                             session->security_parameters.session_id,
-                             session->security_parameters.session_id_size);
+  gnutls_datum_t session_id;
+  int ret = 0;
+
+  session_id.data = session->security_parameters.session_id;
+  session_id.size = session->security_parameters.session_id_size;
+
+  if (db_func_is_ok (session) != 0)
+    {
+      gnutls_assert ();
+      return /* GNUTLS_E_DB_ERROR */;
+    }
+
+  if (session_id.data == NULL || session_id.size == 0)
+    {
+      gnutls_assert ();
+      return /* GNUTLS_E_INVALID_SESSION */;
+    }
+
+  /* if we can't read why bother writing? */
+  if (session->internals.db_remove_func != NULL)
+    {
+      ret = session->internals.db_remove_func (session->internals.db_ptr,
+                                              session_id);
+      if (ret != 0)
+       gnutls_assert ();
+    }
 }
diff --git a/lib/gnutls_db.h b/lib/gnutls_db.h
index 94b00a4..bf43e02 100644
--- a/lib/gnutls_db.h
+++ b/lib/gnutls_db.h
@@ -24,12 +24,3 @@ int _gnutls_server_register_current_session 
(gnutls_session_t session);
 int _gnutls_server_restore_session (gnutls_session_t session,
                                     uint8_t * session_id,
                                     int session_id_size);
-int _gnutls_db_remove_session (gnutls_session_t session, uint8_t * session_id,
-                               int session_id_size);
-int _gnutls_store_session (gnutls_session_t session,
-                           gnutls_datum_t session_id,
-                           gnutls_datum_t session_data);
-gnutls_datum_t _gnutls_retrieve_session (gnutls_session_t session,
-                                         gnutls_datum_t session_id);
-int _gnutls_remove_session (gnutls_session_t session,
-                            gnutls_datum_t session_id);
diff --git a/lib/gnutls_dtls.c b/lib/gnutls_dtls.c
index 7f4bab6..16a6179 100644
--- a/lib/gnutls_dtls.c
+++ b/lib/gnutls_dtls.c
@@ -45,7 +45,7 @@ transmit_message (gnutls_session_t session,
   opaque *data, *mtu_data;
   int ret = 0;
   unsigned int offset, frag_len, data_size;
-  const uint mtu = gnutls_dtls_get_data_mtu(session) - 
DTLS_HANDSHAKE_HEADER_SIZE;
+  const unsigned int mtu = gnutls_dtls_get_data_mtu(session) - 
DTLS_HANDSHAKE_HEADER_SIZE;
 
   if (bufel->type == GNUTLS_CHANGE_CIPHER_SPEC)
     {
diff --git a/lib/gnutls_ecc.c b/lib/gnutls_ecc.c
index cd2a4b3..4d85f9f 100644
--- a/lib/gnutls_ecc.c
+++ b/lib/gnutls_ecc.c
@@ -161,6 +161,22 @@ int ret;
       goto cleanup;
     }
   params->params_nr++;
+
+  val_size = sizeof(val);
+  ret = _gnutls_hex2bin(st->B, strlen(st->B), val, &val_size);
+  if (ret < 0)
+    {
+      gnutls_assert();
+      goto cleanup;
+    }
+
+  ret = _gnutls_mpi_scan_nz(&params->params[3], val, val_size);
+  if (ret < 0)
+    {
+      gnutls_assert();
+      goto cleanup;
+    }
+  params->params_nr++;
   
   val_size = sizeof(val);
   ret = _gnutls_hex2bin(st->Gx, strlen(st->Gx), val, &val_size);
@@ -170,7 +186,7 @@ int ret;
       goto cleanup;
     }
 
-  ret = _gnutls_mpi_scan_nz(&params->params[3], val, val_size);
+  ret = _gnutls_mpi_scan_nz(&params->params[4], val, val_size);
   if (ret < 0)
     {
       gnutls_assert();
@@ -186,7 +202,7 @@ int ret;
       goto cleanup;
     }
 
-  ret = _gnutls_mpi_scan_nz(&params->params[4], val, val_size);
+  ret = _gnutls_mpi_scan_nz(&params->params[5], val, val_size);
   if (ret < 0)
     {
       gnutls_assert();
diff --git a/lib/gnutls_errors.c b/lib/gnutls_errors.c
index cfb3433..0084a88 100644
--- a/lib/gnutls_errors.c
+++ b/lib/gnutls_errors.c
@@ -204,11 +204,6 @@ static const gnutls_error_entry error_algorithms[] = {
                GNUTLS_E_TOO_MANY_EMPTY_PACKETS, 1),
   ERROR_ENTRY (N_("Too many handshake packets have been received."),
                GNUTLS_E_TOO_MANY_HANDSHAKE_PACKETS, 1),
-  ERROR_ENTRY (N_("The initialization of GnuTLS-extra has failed."),
-               GNUTLS_E_INIT_LIBEXTRA, 1),
-  ERROR_ENTRY (N_
-               ("The GnuTLS library version does not match the GnuTLS-extra 
library version."),
-               GNUTLS_E_LIBRARY_VERSION_MISMATCH, 1),
   ERROR_ENTRY (N_("The crypto library version is too old."),
                GNUTLS_E_INCOMPATIBLE_GCRYPT_LIBRARY, 1),
 
diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c
index e99f1c1..010e614 100644
--- a/lib/gnutls_global.c
+++ b/lib/gnutls_global.c
@@ -212,7 +212,7 @@ gnutls_global_init (void)
     goto out;
 
   if (gl_sockets_startup (SOCKETS_1_1))
-    return GNUTLS_E_LIBRARY_VERSION_MISMATCH;
+    return gnutls_assert_val(GNUTLS_E_FILE_ERROR);
 
   bindtextdomain (PACKAGE, LOCALEDIR);
 
diff --git a/lib/gnutls_handshake.c b/lib/gnutls_handshake.c
index 5a4b462..8363bf1 100644
--- a/lib/gnutls_handshake.c
+++ b/lib/gnutls_handshake.c
@@ -552,7 +552,7 @@ _gnutls_read_client_hello (gnutls_session_t session, opaque 
* data,
     }
 
   /* resumed by session_ticket extension */
-  if (session->internals.resumed == RESUME_TRUE)
+  if (session->internals.resumed != RESUME_FALSE)
     {
       /* to indicate the client that the current session is resumed */
       memcpy (session->internals.resumed_security_parameters.session_id,
@@ -643,7 +643,7 @@ _gnutls_send_finished (gnutls_session_t session, int again)
 
       if ((session->internals.resumed == RESUME_FALSE
            && session->security_parameters.entity == GNUTLS_CLIENT)
-          || (session->internals.resumed == RESUME_TRUE
+          || (session->internals.resumed != RESUME_FALSE
               && session->security_parameters.entity == GNUTLS_SERVER))
         {
           /* if we are a client not resuming - or we are a server resuming */
@@ -740,7 +740,7 @@ _gnutls_recv_finished (gnutls_session_t session)
       goto cleanup;
     }
 
-  if ((session->internals.resumed == RESUME_TRUE
+  if ((session->internals.resumed != RESUME_FALSE
        && session->security_parameters.entity == GNUTLS_CLIENT)
       || (session->internals.resumed == RESUME_FALSE
           && session->security_parameters.entity == GNUTLS_SERVER))
@@ -2778,7 +2778,7 @@ _gnutls_handshake_common (gnutls_session_t session)
   int ret = 0;
 
   /* send and recv the change cipher spec and finished messages */
-  if ((session->internals.resumed == RESUME_TRUE
+  if ((session->internals.resumed != RESUME_FALSE
        && session->security_parameters.entity == GNUTLS_CLIENT)
       || (session->internals.resumed == RESUME_FALSE
           && session->security_parameters.entity == GNUTLS_SERVER))
diff --git a/lib/gnutls_hash_int.c b/lib/gnutls_hash_int.c
index 9dd5b09..b316ece 100644
--- a/lib/gnutls_hash_int.c
+++ b/lib/gnutls_hash_int.c
@@ -68,7 +68,7 @@ _gnutls_hash_init (digest_hd_st * dig, 
gnutls_digest_algorithm_t algorithm)
   /* check if a digest has been registered 
    */
   cc = _gnutls_get_crypto_digest (algorithm);
-  if (cc != NULL)
+  if (cc != NULL && cc->init)
     {
       if (cc->init (algorithm, &dig->handle) < 0)
         {
@@ -145,25 +145,30 @@ int
 _gnutls_hash_fast (gnutls_digest_algorithm_t algorithm,
                    const void *text, size_t textlen, void *digest)
 {
-  digest_hd_st dig;
   int ret;
+  const gnutls_crypto_digest_st *cc = NULL;
 
-  ret = _gnutls_hash_init (&dig, algorithm);
-  if (ret < 0)
+  /* check if a digest has been registered 
+   */
+  cc = _gnutls_get_crypto_digest (algorithm);
+  if (cc != NULL)
     {
-      gnutls_assert ();
-      return ret;
+      if (cc->fast (algorithm, text, textlen, digest) < 0)
+        {
+          gnutls_assert ();
+          return GNUTLS_E_HASH_FAILED;
+        }
+
+      return 0;
     }
 
-  ret = _gnutls_hash (&dig, text, textlen);
+  ret = _gnutls_digest_ops.fast (algorithm, text, textlen, digest);
   if (ret < 0)
     {
       gnutls_assert ();
-      _gnutls_hash_deinit (&dig, NULL);
       return ret;
     }
 
-  _gnutls_hash_deinit (&dig, digest);
   return 0;
 }
 
@@ -174,26 +179,32 @@ int
 _gnutls_hmac_fast (gnutls_mac_algorithm_t algorithm, const void *key,
                    int keylen, const void *text, size_t textlen, void *digest)
 {
-  digest_hd_st dig;
   int ret;
+  const gnutls_crypto_mac_st *cc = NULL;
 
-  ret = _gnutls_hmac_init (&dig, algorithm, key, keylen);
-  if (ret < 0)
+  /* check if a digest has been registered 
+   */
+  cc = _gnutls_get_crypto_mac (algorithm);
+  if (cc != NULL)
     {
-      gnutls_assert ();
-      return ret;
+      if (cc->fast (algorithm, key, keylen, text, textlen, digest) < 0)
+        {
+          gnutls_assert ();
+          return GNUTLS_E_HASH_FAILED;
+        }
+
+      return 0;
     }
 
-  ret = _gnutls_hmac (&dig, text, textlen);
+  ret = _gnutls_mac_ops.fast (algorithm, key, keylen, text, textlen, digest);
   if (ret < 0)
     {
       gnutls_assert ();
-      _gnutls_hmac_deinit (&dig, NULL);
       return ret;
     }
 
-  _gnutls_hmac_deinit (&dig, digest);
   return 0;
+
 }
 
 int
@@ -210,7 +221,7 @@ _gnutls_hmac_init (digest_hd_st * dig, 
gnutls_mac_algorithm_t algorithm,
   /* check if a digest has been registered 
    */
   cc = _gnutls_get_crypto_mac (algorithm);
-  if (cc != NULL)
+  if (cc != NULL && cc->init != NULL)
     {
       if (cc->init (algorithm, &dig->handle) < 0)
         {
diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h
index 9b0b8bf..3c888fa 100644
--- a/lib/gnutls_int.h
+++ b/lib/gnutls_int.h
@@ -43,7 +43,11 @@ typedef int ssize_t;
 #include <sys/types.h>
 #include <unistd.h>
 #include <sys/stat.h>
-#include <sys/socket.h>
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#elif HAVE_WS2TCPIP_H
+# include <ws2tcpip.h>
+#endif
 #include <time.h>
 #include <u64.h> /* gnulib for uint64_t */
 
@@ -137,6 +141,9 @@ typedef struct
 /* expire time for resuming sessions */
 #define DEFAULT_EXPIRE_TIME 3600
 
+/* printing period of messages */
+#define PRINT_MESSAGE_PERIOD 30
+
 typedef enum transport_t
 {
   GNUTLS_STREAM,
@@ -188,8 +195,6 @@ typedef enum transport_t
 #define DECR_LENGTH_RET(len, x, RET) do { len-=x; if (len<0) {gnutls_assert(); 
return RET;} } while (0)
 #define DECR_LENGTH_COM(len, x, COM) do { len-=x; if (len<0) {gnutls_assert(); 
COM;} } while (0)
 
-#define HASH2MAC(x) ((gnutls_mac_algorithm_t)x)
-
 #define GNUTLS_POINTER_TO_INT(_) ((int) GNUTLS_POINTER_TO_INT_CAST (_))
 #define GNUTLS_INT_TO_POINTER(_) ((void*) GNUTLS_POINTER_TO_INT_CAST (_))
 
@@ -233,8 +238,8 @@ typedef enum extensions_t
 typedef enum
 { CIPHER_STREAM, CIPHER_BLOCK } cipher_type_t;
 
-#define RESUME_TRUE 0
-#define RESUME_FALSE -1
+#define RESUME_TRUE 1
+#define RESUME_FALSE 0
 
 /* Record Protocol */
 typedef enum content_type_t
@@ -495,7 +500,7 @@ struct record_state_st
   gnutls_datum_t IV;
   gnutls_datum_t key;
   auth_cipher_hd_st cipher_state;
-  comp_hd_t compression_state;
+  comp_hd_st compression_state;
   uint64 sequence_number;
 };
 
@@ -623,6 +628,7 @@ typedef struct
   /* last retransmission triggered by record layer */
   time_t last_retransmit;
   unsigned int packets_dropped;
+  time_t last_print;
 } dtls_st;
 
 
@@ -641,7 +647,7 @@ typedef struct
                                                  * the last received message */
   gnutls_buffer_st handshake_hash_buffer;       /* used to keep the last 
received handshake 
                                                  * message */
-  int resumable:1;              /* TRUE or FALSE - if we can resume that 
session */
+  unsigned int resumable:1;              /* TRUE or FALSE - if we can resume 
that session */
   handshake_state_t handshake_state;    /* holds
                                          * a number which indicates where
                                          * the handshake procedure has been
@@ -667,7 +673,7 @@ typedef struct
   struct gnutls_priority_st priorities;
 
   /* resumed session */
-  int resumed:1;                /* RESUME_TRUE or FALSE - if we are resuming a 
session */
+  unsigned int resumed:1;                /* RESUME_TRUE or FALSE - if we are 
resuming a session */
   security_parameters_st resumed_security_parameters;
 
   /* These buffers are used in the handshake
diff --git a/lib/gnutls_pcert.c b/lib/gnutls_pcert.c
index 9ee43f3..b277472 100644
--- a/lib/gnutls_pcert.c
+++ b/lib/gnutls_pcert.c
@@ -218,6 +218,8 @@ cleanup:
   return ret;
 }
 
+#ifdef ENABLE_OPENPGP
+
 /**
  * gnutls_pcert_import_openpgp:
  * @pcert: The pcert structure
@@ -355,6 +357,8 @@ cleanup:
   return ret;
 }
 
+#endif
+
 /**
  * gnutls_pcert_deinit:
  * @pcert: The structure to be deinitialized
diff --git a/lib/gnutls_priority.c b/lib/gnutls_priority.c
index 22641bf..7d071ec 100644
--- a/lib/gnutls_priority.c
+++ b/lib/gnutls_priority.c
@@ -285,10 +285,10 @@ static const int kx_priority_secure[] = {
   /* The ciphersuites that offer forward secrecy take
    * precendance
    */
-  GNUTLS_KX_DHE_RSA,
-  GNUTLS_KX_DHE_DSS,
   GNUTLS_KX_ECDHE_ECDSA,
   GNUTLS_KX_ECDHE_RSA,
+  GNUTLS_KX_DHE_RSA,
+  GNUTLS_KX_DHE_DSS,
   GNUTLS_KX_RSA,
   /* GNUTLS_KX_ANON_DH: Man-in-the-middle prone, don't add!
    * GNUTLS_KX_RSA_EXPORT: Deprecated, don't add!
diff --git a/lib/gnutls_privkey.c b/lib/gnutls_privkey.c
index 87ed1c1..3b43eaf 100644
--- a/lib/gnutls_privkey.c
+++ b/lib/gnutls_privkey.c
@@ -47,6 +47,11 @@ struct gnutls_privkey_st
 #ifdef ENABLE_OPENPGP
     gnutls_openpgp_privkey_t openpgp;
 #endif
+    struct {
+      gnutls_privkey_sign_func sign_func;
+      gnutls_privkey_decrypt_func decrypt_func;
+      void* userdata;
+    } ext;
   } key;
 
   unsigned int flags;
@@ -101,6 +106,10 @@ gnutls_privkey_get_pk_algorithm (gnutls_privkey_t key, 
unsigned int *bits)
       if (bits)
         *bits = _gnutls_mpi_get_nbits (key->key.x509->params.params[0]);
       return gnutls_x509_privkey_get_pk_algorithm (key->key.x509);
+    case GNUTLS_PRIVKEY_EXT:
+      if (bits)
+        *bits = 0;
+      return key->pk_algorithm;
     default:
       gnutls_assert ();
       return GNUTLS_E_INVALID_REQUEST;
@@ -156,6 +165,7 @@ privkey_to_pubkey (gnutls_pk_algorithm_t pk,
       pub->params[4] = _gnutls_mpi_copy (priv->params[4]);
       pub->params[5] = _gnutls_mpi_copy (priv->params[5]);
       pub->params[6] = _gnutls_mpi_copy (priv->params[6]);
+      pub->params[7] = _gnutls_mpi_copy (priv->params[7]);
 
       pub->params_nr = ECC_PUBLIC_PARAMS;
       pub->flags = priv->flags;
@@ -163,7 +173,7 @@ privkey_to_pubkey (gnutls_pk_algorithm_t pk,
       if (pub->params[0] == NULL || pub->params[1] == NULL ||
           pub->params[2] == NULL || pub->params[3] == NULL ||
           pub->params[4] == NULL || pub->params[5] == NULL ||
-          pub->params[6] == NULL)
+          pub->params[6] == NULL || pub->params[7] == NULL)
         {
           gnutls_assert ();
           ret = GNUTLS_E_MEMORY_ERROR;
@@ -360,6 +370,54 @@ int ret;
 #endif /* ENABLE_PKCS11 */
 
 /**
+ * gnutls_privkey_import_ext:
+ * @pkey: The private key
+ * @pk: The public key algorithm
+ * @userdata: private data to be provided to the callbacks
+ * @sign_func: callback for signature operations
+ * @decrypt_func: callback for decryption operations
+ * @flags: Flags for the import
+ *
+ * This function will associate the given callbacks with the
+ * #gnutls_privkey_t structure. At least one of the two callbacks
+ * must be non-null.
+ *
+ * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a
+ *   negative error value.
+ *
+ * Since: 3.0.0
+ **/
+int
+gnutls_privkey_import_ext (gnutls_privkey_t pkey,
+                           gnutls_pk_algorithm_t pk,
+                           void* userdata,
+                           gnutls_privkey_sign_func sign_func,
+                           gnutls_privkey_decrypt_func decrypt_func,
+                           unsigned int flags)
+{
+int ret;
+
+  ret = check_if_clean(pkey);
+  if (ret < 0)
+    {
+      gnutls_assert();
+      return ret;
+    }
+  
+  if (sign_func == NULL && decrypt_func == NULL)
+    return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+
+  pkey->key.ext.sign_func = sign_func;
+  pkey->key.ext.decrypt_func = decrypt_func;
+  pkey->key.ext.userdata = userdata;
+  pkey->type = GNUTLS_PRIVKEY_EXT;
+  pkey->pk_algorithm = pk;
+  pkey->flags = flags;
+
+  return 0;
+}
+
+/**
  * gnutls_privkey_import_x509:
  * @pkey: The private key
  * @key: The private key to be imported
@@ -646,6 +704,10 @@ _gnutls_privkey_sign_hash (gnutls_privkey_t key,
       return _gnutls_soft_sign (key->key.x509->pk_algorithm,
                                 &key->key.x509->params,
                                 hash, signature);
+    case GNUTLS_PRIVKEY_EXT:
+      if (key->key.ext.sign_func == NULL)
+        return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+      return key->key.ext.sign_func(key, key->key.ext.userdata, hash, 
signature);
     default:
       gnutls_assert ();
       return GNUTLS_E_INVALID_REQUEST;
@@ -696,6 +758,11 @@ gnutls_privkey_decrypt_data (gnutls_privkey_t key,
                                                  flags,
                                                  ciphertext, plaintext);
 #endif
+    case GNUTLS_PRIVKEY_EXT:
+      if (key->key.ext.decrypt_func == NULL)
+        return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
+
+      return key->key.ext.decrypt_func(key, key->key.ext.userdata, ciphertext, 
plaintext);
     default:
       gnutls_assert ();
       return GNUTLS_E_INVALID_REQUEST;
diff --git a/lib/gnutls_pubkey.c b/lib/gnutls_pubkey.c
index a20b801..fbbaa57 100644
--- a/lib/gnutls_pubkey.c
+++ b/lib/gnutls_pubkey.c
@@ -159,7 +159,7 @@ gnutls_pubkey_deinit (gnutls_pubkey_t key)
 {
   if (!key)
     return;
-  gnutls_pk_params_release(&key->params);
+  gnutls_pk_params_release (&key->params);
   gnutls_free (key);
 }
 
@@ -740,7 +740,7 @@ gnutls_pubkey_get_pk_ecc_raw (gnutls_pubkey_t key, 
gnutls_ecc_curve_t *curve,
   *curve = key->params.flags;
 
   /* X */
-  ret = _gnutls_mpi_dprint_lz (key->params.params[5], x);
+  ret = _gnutls_mpi_dprint_lz (key->params.params[6], x);
   if (ret < 0)
     {
       gnutls_assert ();
@@ -748,7 +748,7 @@ gnutls_pubkey_get_pk_ecc_raw (gnutls_pubkey_t key, 
gnutls_ecc_curve_t *curve,
     }
 
   /* Y */
-  ret = _gnutls_mpi_dprint_lz (key->params.params[6], y);
+  ret = _gnutls_mpi_dprint_lz (key->params.params[7], y);
   if (ret < 0)
     {
       gnutls_assert ();
@@ -1137,7 +1137,7 @@ gnutls_pubkey_import_ecc_raw (gnutls_pubkey_t key,
   if (ret < 0)
     return gnutls_assert_val(ret);
 
-  if (_gnutls_mpi_scan_nz (&key->params.params[5], x->data, x->size))
+  if (_gnutls_mpi_scan_nz (&key->params.params[6], x->data, x->size))
     {
       gnutls_assert ();
       ret = GNUTLS_E_MPI_SCAN_FAILED;
@@ -1145,7 +1145,7 @@ gnutls_pubkey_import_ecc_raw (gnutls_pubkey_t key,
     }
   key->params.params_nr++;
 
-  if (_gnutls_mpi_scan_nz (&key->params.params[6], y->data, y->size))
+  if (_gnutls_mpi_scan_nz (&key->params.params[7], y->data, y->size))
     {
       gnutls_assert ();
       ret = GNUTLS_E_MPI_SCAN_FAILED;
@@ -1199,7 +1199,7 @@ gnutls_pubkey_import_ecc_x962 (gnutls_pubkey_t key,
     }
 
   ret = _gnutls_ecc_ansi_x963_import(ecpoint->data, ecpoint->size,
-         &key->params.params[5], &key->params.params[6]);
+         &key->params.params[6], &key->params.params[7]);
   if (ret < 0)
     {
       gnutls_assert ();
diff --git a/lib/gnutls_record.c b/lib/gnutls_record.c
index 4ff2951..3b89c35 100644
--- a/lib/gnutls_record.c
+++ b/lib/gnutls_record.c
@@ -1020,8 +1020,7 @@ begin:
       ret = _dtls_record_check(session, packet_sequence);
       if (ret < 0)
         {
-          _gnutls_audit_log(session, "Discarded duplicate message[%u]\n",
-            (unsigned int) _gnutls_uint64touint32 (packet_sequence));
+          gnutls_assert();
           goto sanity_check_error;
         }
     }
@@ -1088,8 +1087,15 @@ discard:
 sanity_check_error:
   if (IS_DTLS(session))
     {
-      _gnutls_audit_log(session, "Discarded message[%u] due to invalid 
decryption\n", 
-            (unsigned int)_gnutls_uint64touint32 (packet_sequence));
+      time_t now = time(0);
+      session->internals.dtls.packets_dropped++;
+
+      if (now - session->internals.dtls.last_print < PRINT_MESSAGE_PERIOD)
+        {
+          session->internals.dtls.last_print = now;
+          _gnutls_audit_log(session, "Discarded %u messages (duplicates or 
invalid decryption)\n", 
+               (unsigned int)session->internals.dtls.packets_dropped);
+        }
       ret = gnutls_assert_val(GNUTLS_E_AGAIN);
       goto cleanup;
     }
diff --git a/lib/gnutls_session.c b/lib/gnutls_session.c
index 8028d5a..fd012fe 100644
--- a/lib/gnutls_session.c
+++ b/lib/gnutls_session.c
@@ -63,13 +63,14 @@ gnutls_session_get_data (gnutls_session_t session,
       gnutls_assert ();
       return ret;
     }
-  *session_data_size = psession.size;
 
   if (psession.size > *session_data_size)
     {
+      *session_data_size = psession.size;
       ret = GNUTLS_E_SHORT_MEMORY_BUFFER;
       goto error;
     }
+  *session_data_size = psession.size;
 
   if (session_data != NULL)
     memcpy (session_data, psession.data, psession.size);
diff --git a/lib/gnutls_sig.c b/lib/gnutls_sig.c
index 5500148..cdd46fe 100644
--- a/lib/gnutls_sig.c
+++ b/lib/gnutls_sig.c
@@ -225,15 +225,41 @@ sign_tls_hash (gnutls_session_t session, 
gnutls_digest_algorithm_t hash_algo,
             return GNUTLS_E_KEY_USAGE_VIOLATION;
           }
 
-      /* External signing. */
+      /* External signing. Deprecated. To be removed. */
       if (!pkey)
         {
+          int ret;
+
           if (!session->internals.sign_func)
-            return GNUTLS_E_INSUFFICIENT_CREDENTIALS;
+            return gnutls_assert_val(GNUTLS_E_INSUFFICIENT_CREDENTIALS);
 
-          return (*session->internals.sign_func)
-            (session, session->internals.sign_func_userdata,
-             cert->type, &cert->cert, hash_concat, signature);
+          if (!_gnutls_version_has_selectable_sighash (ver))
+            return (*session->internals.sign_func)
+              (session, session->internals.sign_func_userdata,
+               cert->type, &cert->cert, hash_concat, signature);
+          else
+            {
+              gnutls_datum_t digest;
+
+              ret = _gnutls_set_datum(&digest, hash_concat->data, 
hash_concat->size);
+              if (ret < 0)
+                return gnutls_assert_val(ret);
+              
+              ret = pk_prepare_hash (gnutls_privkey_get_pk_algorithm(pkey, 
NULL), hash_algo, &digest);
+              if (ret < 0)
+                {
+                  gnutls_assert ();
+                  goto es_cleanup;
+                }
+
+              ret = (*session->internals.sign_func)
+                (session, session->internals.sign_func_userdata,
+                 cert->type, &cert->cert, &digest, signature);
+es_cleanup:
+              gnutls_free(digest.data);
+              
+              return ret;
+            }
         }
     }
 
diff --git a/lib/gnutls_srp.c b/lib/gnutls_srp.c
index 4509834..2339649 100644
--- a/lib/gnutls_srp.c
+++ b/lib/gnutls_srp.c
@@ -579,7 +579,7 @@ gnutls_srp_set_server_credentials_file 
(gnutls_srp_server_credentials_t res,
  * @username contains the actual username.
  * The @salt, @verifier, @generator and @prime must be filled
  * in using the gnutls_malloc(). For convenience @prime and @generator
- * may also be one of the static parameters defined in extra.h.
+ * may also be one of the static parameters defined in gnutls.h.
  *
  * In case the callback returned a negative number then gnutls will
  * assume that the username does not exist.
@@ -671,7 +671,7 @@ gnutls_srp_server_get_username (gnutls_session_t session)
  *
  * This function will create an SRP verifier, as specified in
  * RFC2945.  The @prime and @generator should be one of the static
- * parameters defined in gnutls/extra.h or may be generated.
+ * parameters defined in gnutls/gnutls.h or may be generated.
  *
  * The verifier will be allocated with @gnutls_malloc() and will be stored in
  * @res using binary format.
diff --git a/lib/gnutls_state.c b/lib/gnutls_state.c
index 8eda274..43602cc 100644
--- a/lib/gnutls_state.c
+++ b/lib/gnutls_state.c
@@ -425,6 +425,10 @@ gnutls_deinit (gnutls_session_t session)
   if (session == NULL)
     return;
 
+  if (IS_DTLS(session) && session->internals.dtls.packets_dropped > 0)
+    _gnutls_audit_log(session, "Discarded %u messages (duplicates or invalid 
decryption)\n", 
+                      (unsigned int)session->internals.dtls.packets_dropped);
+
   /* remove auth info firstly */
   _gnutls_free_auth_info (session);
 
@@ -1105,7 +1109,7 @@ gnutls_session_is_resumed (gnutls_session_t session)
     }
   else
     {
-      if (session->internals.resumed == RESUME_TRUE)
+      if (session->internals.resumed != RESUME_FALSE)
         return 1;
     }
 
diff --git a/lib/gnutls_str.c b/lib/gnutls_str.c
index c7c8e9d..c668b08 100644
--- a/lib/gnutls_str.c
+++ b/lib/gnutls_str.c
@@ -1,6 +1,5 @@
 /*
- * Copyright (C) 2002, 2004, 2005, 2007, 2008, 2009, 2010 Free Software
- * Foundation, Inc.
+ * Copyright (C) 2002-2011 Free Software Foundation, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
  *
@@ -730,3 +729,56 @@ _gnutls_buffer_pop_data_prefix (gnutls_buffer_st * buf, 
void *data,
 
   return 0;
 }
+
+void
+_gnutls_buffer_hexprint (gnutls_buffer_st * str,
+                        const char *data, size_t len)
+{
+  size_t j;
+
+  if (len == 0)
+    _gnutls_buffer_append_str (str, "00");
+  else
+    {
+      for (j = 0; j < len; j++)
+        _gnutls_buffer_append_printf (str, "%.2x", (unsigned char) data[j]);
+    }
+}
+
+void
+_gnutls_buffer_hexdump (gnutls_buffer_st * str, const char *data, size_t len,
+                       const char *spc)
+{
+  size_t j;
+
+  if (spc)
+    _gnutls_buffer_append_str (str, spc);
+  for (j = 0; j < len; j++)
+    {
+      if (((j + 1) % 16) == 0)
+        {
+          _gnutls_buffer_append_printf (str, "%.2x\n", (unsigned char) 
data[j]);
+          if (spc && j != (len - 1))
+            _gnutls_buffer_append_str (str, spc);
+        }
+      else if (j == (len - 1))
+        _gnutls_buffer_append_printf (str, "%.2x", (unsigned char) data[j]);
+      else
+        _gnutls_buffer_append_printf (str, "%.2x:", (unsigned char) data[j]);
+    }
+  if ((j % 16) != 0)
+    _gnutls_buffer_append_str (str, "\n");
+}
+
+void
+_gnutls_buffer_asciiprint (gnutls_buffer_st * str,
+                          const char *data, size_t len)
+{
+  size_t j;
+
+  for (j = 0; j < len; j++)
+    if (c_isprint (data[j]))
+      _gnutls_buffer_append_printf (str, "%c", (unsigned char) data[j]);
+    else
+      _gnutls_buffer_append_printf (str, ".");
+}
diff --git a/lib/gnutls_str.h b/lib/gnutls_str.h
index dbf299c..770a7b7 100644
--- a/lib/gnutls_str.h
+++ b/lib/gnutls_str.h
@@ -41,6 +41,12 @@ typedef struct
 
 void _gnutls_buffer_init (gnutls_buffer_st *);
 void _gnutls_buffer_clear (gnutls_buffer_st *);
+inline static void _gnutls_buffer_reset (gnutls_buffer_st * buf)
+{
+  buf->data = buf->allocd;
+  buf->length = 0;
+}
+
 int _gnutls_buffer_resize (gnutls_buffer_st *, size_t new_size);
 
 int _gnutls_buffer_append_str (gnutls_buffer_st *, const char *str);
@@ -86,6 +92,13 @@ int _gnutls_buffer_append_printf (gnutls_buffer_st * dest, 
const char *fmt,
                                   ...)
   __attribute__ ((format (printf, 2, 3)));
 
+void _gnutls_buffer_hexprint (gnutls_buffer_st * str,
+                             const char *data, size_t len);
+void _gnutls_buffer_hexdump (gnutls_buffer_st * str, const char *data,
+                            size_t len, const char *spc);
+void _gnutls_buffer_asciiprint (gnutls_buffer_st * str,
+                               const char *data, size_t len);
+
 char *_gnutls_bin2hex (const void *old, size_t oldlen, char *buffer,
                        size_t buffer_size, const char *separator);
 int _gnutls_hex2bin (const opaque * hex_data, int hex_size, opaque * bin_data,
@@ -93,6 +106,7 @@ int _gnutls_hex2bin (const opaque * hex_data, int hex_size, 
opaque * bin_data,
 
 int _gnutls_hostname_compare (const char *certname, size_t certnamesize,
                               const char *hostname, int level);
+
 #define MAX_CN 256
 #define MAX_DN 1024
 
diff --git a/lib/gnutls_str_array.h b/lib/gnutls_str_array.h
index 7cc1ec2..b13e093 100644
--- a/lib/gnutls_str_array.h
+++ b/lib/gnutls_str_array.h
@@ -24,6 +24,7 @@
 #define GNUTLS_STR_ARRAY_H
 
 #include <gnutls_int.h>
+#include <gnutls_errors.h>
 
 /* Functionality to allow an array of strings. Strings
  * are allowed to be added to the list and matched against it.
diff --git a/lib/gnutls_ui.c b/lib/gnutls_ui.c
index 79b17d5..248c8a0 100644
--- a/lib/gnutls_ui.c
+++ b/lib/gnutls_ui.c
@@ -557,7 +557,7 @@ gnutls_fingerprint (gnutls_digest_algorithm_t algo,
                     size_t * result_size)
 {
   int ret;
-  int hash_len = _gnutls_hash_get_algo_len (HASH2MAC (algo));
+  int hash_len = _gnutls_hash_get_algo_len (algo);
 
   if (hash_len < 0 || (unsigned) hash_len > *result_size || result == NULL)
     {
diff --git a/lib/gnutls_x509.c b/lib/gnutls_x509.c
index 1d4ed53..c86c4ed 100644
--- a/lib/gnutls_x509.c
+++ b/lib/gnutls_x509.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+ * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
  * Free Software Foundation, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
@@ -1100,6 +1100,84 @@ cleanup:
 }
 
 /**
+ * gnutls_certificate_set_key:
+ * @res: is a #gnutls_certificate_credentials_t structure.
+ * @names: is an array of DNS name of the certificate (NULL if none)
+ * @names_size: holds the size of the names list
+ * @pcert_list: contains a certificate list (path) for the specified private 
key
+ * @pcert_list_size: holds the size of the certificate list
+ * @key: is a gnutls_x509_privkey_t key
+ *
+ * This function sets a certificate/private key pair in the
+ * gnutls_certificate_credentials_t structure.  This function may be
+ * called more than once, in case multiple keys/certificates exist for
+ * the server.  For clients that wants to send more than its own end
+ * entity certificate (e.g., also an intermediate CA cert) then put
+ * the certificate chain in @pcert_list. The @pcert_list and @key will
+ * become part of the credentials structure and must not
+ * be deallocated. They will be automatically deallocated when
+ * @res is deinitialized.
+ *
+ * Returns: %GNUTLS_E_SUCCESS (0) on success, or a negative error code.
+ *
+ * Since: 3.0.0
+ **/
+int
+gnutls_certificate_set_key (gnutls_certificate_credentials_t res,
+                            const char** names,
+                            int names_size,
+                            gnutls_pcert_st * pcert_list,
+                            int pcert_list_size,
+                            gnutls_privkey_t key)
+{
+  int ret, i;
+  gnutls_str_array_t str_names;
+  
+  _gnutls_str_array_init(&str_names);
+
+  if (names != NULL && names_size > 0)
+    {
+      for (i=0;i<names_size;i++)
+        {
+          ret = _gnutls_str_array_append(&str_names, names[i], 
strlen(names[i]));
+          if (ret < 0)
+            {
+              ret = gnutls_assert_val(ret);
+              goto cleanup;
+            }
+        }
+    }
+
+  ret = certificate_credentials_append_pkey (res, key);
+  if (ret < 0)
+    {
+      gnutls_assert ();
+      goto cleanup;
+    }
+
+  ret = certificate_credential_append_crt_list (res, str_names, pcert_list, 
pcert_list_size);
+  if (ret < 0)
+    {
+      gnutls_assert ();
+      goto cleanup;
+    }
+
+  res->ncerts++;
+
+  if ((ret = _gnutls_check_key_cert_match (res)) < 0)
+    {
+      gnutls_assert ();
+      return ret;
+    }
+
+  return 0;
+  
+cleanup:
+  _gnutls_str_array_clear(&str_names);
+  return ret;
+}
+
+/**
  * gnutls_certificate_set_x509_key_file:
  * @res: is a #gnutls_certificate_credentials_t structure.
  * @certfile: is a file that containing the certificate list (path) for
diff --git a/lib/includes/gnutls/abstract.h b/lib/includes/gnutls/abstract.h
index 2d57079..02821de 100644
--- a/lib/includes/gnutls/abstract.h
+++ b/lib/includes/gnutls/abstract.h
@@ -37,6 +37,15 @@ typedef struct gnutls_pubkey_st *gnutls_pubkey_t;
 struct gnutls_privkey_st;
 typedef struct gnutls_privkey_st *gnutls_privkey_t;
 
+typedef int (*gnutls_privkey_sign_func) (gnutls_privkey_t key,
+                                         void *userdata,
+                                         const gnutls_datum_t * raw_data,
+                                         gnutls_datum_t * signature);
+typedef int (*gnutls_privkey_decrypt_func) (gnutls_privkey_t key,
+                                            void *userdata,
+                                            const gnutls_datum_t * ciphertext,
+                                            gnutls_datum_t * plaintext);
+
 int gnutls_pubkey_init (gnutls_pubkey_t * key);
 void gnutls_pubkey_deinit (gnutls_pubkey_t key);
 int gnutls_pubkey_get_pk_algorithm (gnutls_pubkey_t key, unsigned int *bits);
@@ -157,6 +166,13 @@ int gnutls_privkey_import_x509 (gnutls_privkey_t pkey,
 int gnutls_privkey_import_openpgp (gnutls_privkey_t pkey,
                                    gnutls_openpgp_privkey_t key,
                                    unsigned int flags);
+int
+gnutls_privkey_import_ext (gnutls_privkey_t pkey,
+                           gnutls_pk_algorithm_t pk,
+                           void* userdata,
+                           gnutls_privkey_sign_func sign_func,
+                           gnutls_privkey_decrypt_func decrypt_func,
+                           unsigned int flags);
 
 int gnutls_privkey_sign_data (gnutls_privkey_t signer,
                               gnutls_digest_algorithm_t hash,
@@ -252,9 +268,16 @@ void gnutls_pcert_deinit (gnutls_pcert_st* pcert);
                                                     gnutls_privkey_t *privkey);
 
 
-  void gnutls_certificate_set_retrieve_function2
-    (gnutls_certificate_credentials_t cred,
-     gnutls_certificate_retrieve_function2 * func);
+void gnutls_certificate_set_retrieve_function2
+  (gnutls_certificate_credentials_t cred,
+   gnutls_certificate_retrieve_function2 * func);
 
+int
+gnutls_certificate_set_key (gnutls_certificate_credentials_t res,
+                            const char** names,
+                            int names_size,
+                            gnutls_pcert_st * pcert_list,
+                            int pcert_list_size,
+                            gnutls_privkey_t key);
 
 #endif
diff --git a/lib/includes/gnutls/compat.h b/lib/includes/gnutls/compat.h
index becf98b..d18424b 100644
--- a/lib/includes/gnutls/compat.h
+++ b/lib/includes/gnutls/compat.h
@@ -192,7 +192,7 @@ void
    func) _GNUTLS_GCC_ATTR_DEPRECATED;
 
   /* External signing callback.  No longer supported because it
-   * was deprecated by the PKCS #11 API. */
+   * was deprecated by the PKCS #11 API and gnutls_privkey_t. */
 typedef int (*gnutls_sign_func) (gnutls_session_t session,
                                  void *userdata,
                                  gnutls_certificate_type_t cert_type,
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in
index 83d4743..77dd47e 100644
--- a/lib/includes/gnutls/gnutls.h.in
+++ b/lib/includes/gnutls/gnutls.h.in
@@ -1314,6 +1314,12 @@ gnutls_ecc_curve_t gnutls_ecc_curve_get(gnutls_session_t 
session);
 /* The static parameters defined in draft-ietf-tls-srp-05
  * Those should be used as input to gnutls_srp_verifier().
  */
+  extern const gnutls_datum_t gnutls_srp_4096_group_prime;
+  extern const gnutls_datum_t gnutls_srp_4096_group_generator;
+
+  extern const gnutls_datum_t gnutls_srp_3072_group_prime;
+  extern const gnutls_datum_t gnutls_srp_3072_group_generator;
+
   extern const gnutls_datum_t gnutls_srp_2048_group_prime;
   extern const gnutls_datum_t gnutls_srp_2048_group_generator;
 
@@ -1468,6 +1474,7 @@ gnutls_ecc_curve_t gnutls_ecc_curve_get(gnutls_session_t 
session);
  * @GNUTLS_PRIVKEY_X509: X.509 private key, #gnutls_x509_privkey_t.
  * @GNUTLS_PRIVKEY_OPENPGP: OpenPGP private key, #gnutls_openpgp_privkey_t.
  * @GNUTLS_PRIVKEY_PKCS11: PKCS11 private key, #gnutls_pkcs11_privkey_t.
+ * @GNUTLS_PRIVKEY_EXT: External private key, operating using callbacks.
  *
  * Enumeration of different private key types.
  */
@@ -1475,7 +1482,8 @@ gnutls_ecc_curve_t gnutls_ecc_curve_get(gnutls_session_t 
session);
     {
       GNUTLS_PRIVKEY_X509,
       GNUTLS_PRIVKEY_OPENPGP,
-      GNUTLS_PRIVKEY_PKCS11
+      GNUTLS_PRIVKEY_PKCS11,
+      GNUTLS_PRIVKEY_EXT
     } gnutls_privkey_type_t;
 
   typedef struct gnutls_retr2_st
@@ -1679,13 +1687,6 @@ gnutls_ecc_curve_t gnutls_ecc_curve_get(gnutls_session_t 
session);
 #define GNUTLS_E_UNKNOWN_PK_ALGORITHM -80
 #define GNUTLS_E_TOO_MANY_HANDSHAKE_PACKETS -81
 
-  /* returned if libextra functionality was requested but
-   * gnutls_global_init_extra() was not called.
-   */
-#define GNUTLS_E_INIT_LIBEXTRA -82
-#define GNUTLS_E_LIBRARY_VERSION_MISMATCH -83
-
-
   /* returned if you need to generate temporary RSA
    * parameters. These are needed for export cipher suites.
    */
diff --git a/lib/includes/gnutls/pkcs11.h b/lib/includes/gnutls/pkcs11.h
index 7db5d9e..31fa551 100644
--- a/lib/includes/gnutls/pkcs11.h
+++ b/lib/includes/gnutls/pkcs11.h
@@ -50,7 +50,7 @@
  **/
 typedef int (*gnutls_pkcs11_token_callback_t) (void *const userdata,
                                                const char *const label,
-                                               const unsigned retry);
+                                               unsigned retry);
 
 /**
  * gnutls_pkcs11_pin_flag_t:
diff --git a/lib/libgnutls.map b/lib/libgnutls.map
index 58a4d79..d5bee1b 100644
--- a/lib/libgnutls.map
+++ b/lib/libgnutls.map
@@ -748,6 +748,12 @@ GNUTLS_3_0_0 {
        gnutls_ocsp_resp_get_nonce;
        gnutls_ocsp_req_set_nonce;
        gnutls_ocsp_resp_verify;
+       gnutls_privkey_import_ext;
+       gnutls_certificate_set_key;
+       gnutls_srp_3072_group_generator;
+       gnutls_srp_3072_group_prime;
+       gnutls_srp_4096_group_generator;
+       gnutls_srp_4096_group_prime;
 } GNUTLS_2_12;
 
 GNUTLS_PRIVATE {
diff --git a/lib/minitasn1/Makefile.am b/lib/minitasn1/Makefile.am
index e5be71b..d2985a9 100644
--- a/lib/minitasn1/Makefile.am
+++ b/lib/minitasn1/Makefile.am
@@ -23,6 +23,7 @@
 
 AM_CPPFLAGS = -DASN1_BUILDING          \
        -I$(srcdir)/../../gl            \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/..
 
 noinst_LTLIBRARIES = libminitasn1.la
diff --git a/lib/minitasn1/coding.c b/lib/minitasn1/coding.c
index 31b5ebb..3cc0ef8 100644
--- a/lib/minitasn1/coding.c
+++ b/lib/minitasn1/coding.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002, 2004, 2006, 2008, 2009, 2010 Free Software
+ * Copyright (C) 2002, 2004, 2006, 2008, 2009, 2010, 2011 Free Software
  * Foundation, Inc.
  *
  * This file is part of LIBTASN1.
@@ -256,15 +256,17 @@ _asn1_objectid_der (unsigned char *str, unsigned char 
*der, int *der_len)
   char *temp, *n_end, *n_start;
   unsigned char bit7;
   unsigned long val, val1 = 0;
+  int str_len = strlen(str);
 
   max_len = *der_len;
 
-  temp = (char *) _asn1_malloc (strlen (str) + 2);
+  temp = _asn1_malloc (str_len + 2);
   if (temp == NULL)
     return ASN1_MEM_ALLOC_ERROR;
 
-  strcpy (temp, str);
-  strcat (temp, ".");
+  memcpy (temp, str, str_len);
+  temp[str_len] = '.';
+  temp[str_len+1] = 0;
 
   counter = 0;
   n_start = temp;
@@ -857,16 +859,11 @@ _asn1_ordering_set_of (unsigned char *der, int der_len, 
ASN1_TYPE node)
  * Creates the DER encoding for the NAME structure (inside *POINTER
  * structure).
  *
- * Returns:
- *
- *   %ASN1_SUCCESS: DER encoding OK.
- *
- *   %ASN1_ELEMENT_NOT_FOUND: NAME is not a valid element.
- *
- *   %ASN1_VALUE_NOT_FOUND: There is an element without a value.
- *
- *   %ASN1_MEM_ERROR: @ider vector isn't big enough. Also in this case
- *     LEN will contain the length needed.
+ * Returns: %ASN1_SUCCESS if DER encoding OK, %ASN1_ELEMENT_NOT_FOUND
+ *   if @name is not a valid element, %ASN1_VALUE_NOT_FOUND if there
+ *   is an element without a value, %ASN1_MEM_ERROR if the @ider
+ *   vector isn't big enough and in this case @len will contain the
+ *   length needed.
  **/
 asn1_retCode
 asn1_der_coding (ASN1_TYPE element, const char *name, void *ider, int *len,
diff --git a/lib/minitasn1/decoding.c b/lib/minitasn1/decoding.c
index ae32c98..3849375 100644
--- a/lib/minitasn1/decoding.c
+++ b/lib/minitasn1/decoding.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002, 2004, 2006, 2008, 2009, 2010 Free Software
+ * Copyright (C) 2002, 2004, 2006, 2008, 2009, 2010, 2011 Free Software
  * Foundation, Inc.
  *
  * This file is part of LIBTASN1.
@@ -168,7 +168,7 @@ asn1_get_tag_der (const unsigned char *der, int der_len,
  * asn1_get_length_der() is that this function will return a length
  * even if the value has indefinite encoding.
  *
- * Returns: Return the decoded length value, or negative error code when
+ * Returns: Return the decoded length value, or negative value when
  *   the value was too big.
  *
  * Since: 2.0
@@ -1367,7 +1367,7 @@ asn1_der_decoding_element (ASN1_TYPE * structure, const 
char *elementName,
   char temp[128], currentName[ASN1_MAX_NAME_SIZE * 10], *dot_p, *char_p;
   int nameLen = ASN1_MAX_NAME_SIZE * 10 - 1, state;
   int counter, len2, len3, len4, move, ris, tlen;
-  unsigned char class, *temp2;
+  unsigned char class;
   unsigned long tag;
   int indefinite, result;
   const unsigned char *der = ider;
@@ -1921,7 +1921,6 @@ asn1_der_decoding_element (ASN1_TYPE * structure, const 
char *elementName,
                  if (state == FOUND)
                    {
                      _asn1_set_value_octet (p, der + counter, len2 + len3);
-                     temp2 = NULL;
 
                      if (p == nodeFound)
                        state = EXIT;
diff --git a/lib/minitasn1/element.c b/lib/minitasn1/element.c
index 51ade14..a8fdc92 100644
--- a/lib/minitasn1/element.c
+++ b/lib/minitasn1/element.c
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2008, 2009, 2010
- * Free Software Foundation, Inc.
+ * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2008, 2009, 2010,
+ * 2011 Free Software Foundation, Inc.
  *
  * This file is part of LIBTASN1.
  *
@@ -264,13 +264,9 @@ _asn1_append_sequence_set (ASN1_TYPE node)
  *           result=asn1_write_value(cert,
  *           "tbsCertificate.subject.rdnSequence.?LAST", "NEW", 1);
  *
- * Returns:
- *
- *   %ASN1_SUCCESS: Set value OK.
- *
- *   %ASN1_ELEMENT_NOT_FOUND: NAME is not a valid element.
- *
- *   %ASN1_VALUE_NOT_VALID: VALUE has a wrong format.
+ * Returns: %ASN1_SUCCESS if the value was set,
+ *   %ASN1_ELEMENT_NOT_FOUND if @name is not a valid element, and
+ *   %ASN1_VALUE_NOT_VALID if @ivalue has a wrong format.
  **/
 asn1_retCode
 asn1_write_value (ASN1_TYPE node_root, const char *name,
@@ -697,16 +693,12 @@ asn1_write_value (ASN1_TYPE node_root, const char *name,
  * ANY: If NAME indicates an any type, VALUE will indicate the DER
  *   encoding of the structure actually used.
  *
- * Returns:
- *
- *   %ASN1_SUCCESS: Set value OK.
- *
- *   %ASN1_ELEMENT_NOT_FOUND: NAME is not a valid element.
- *
- *   %ASN1_VALUE_NOT_FOUND: There isn't any value for the element selected.
- *
- *   %ASN1_MEM_ERROR: The value vector isn't big enough to store the result.
- *   In this case LEN will contain the number of bytes needed.
+ * Returns: %ASN1_SUCCESS if value is returned,
+ *   %ASN1_ELEMENT_NOT_FOUND if @name is not a valid element,
+ *   %ASN1_VALUE_NOT_FOUND if there isn't any value for the element
+ *   selected, and %ASN1_MEM_ERROR if The value vector isn't big enough
+ *   to store the result, and in this case @len will contain the number of
+ *   bytes needed.
  **/
 asn1_retCode
 asn1_read_value (ASN1_TYPE root, const char *name, void *ivalue, int *len)
@@ -883,11 +875,8 @@ asn1_read_value (ASN1_TYPE root, const char *name, void 
*ivalue, int *len)
  * %ASN1_CLASS_UNIVERSAL, %ASN1_CLASS_PRIVATE or
  * %ASN1_CLASS_CONTEXT_SPECIFIC.
  *
- * Returns:
- *
- *   %ASN1_SUCCESS: Set value OK.
- *
- *   %ASN1_ELEMENT_NOT_FOUND: NAME is not a valid element.
+ * Returns: %ASN1_SUCCESS if successful, %ASN1_ELEMENT_NOT_FOUND if
+ *   @name is not a valid element.
  **/
 asn1_retCode
 asn1_read_tag (ASN1_TYPE root, const char *name, int *tagValue,
@@ -986,7 +975,5 @@ asn1_read_tag (ASN1_TYPE root, const char *name, int 
*tagValue,
        }
     }
 
-
   return ASN1_SUCCESS;
-
 }
diff --git a/lib/minitasn1/element.h b/lib/minitasn1/element.h
index 95c382a..67a234f 100644
--- a/lib/minitasn1/element.h
+++ b/lib/minitasn1/element.h
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2008, 2009, 2010
- * Free Software Foundation, Inc.
+ * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2006, 2008, 2009, 2010,
+ * 2011 Free Software Foundation, Inc.
  *
  * This file is part of LIBTASN1.
  *
diff --git a/lib/minitasn1/errors.c b/lib/minitasn1/errors.c
index 271158d..c5508da 100644
--- a/lib/minitasn1/errors.c
+++ b/lib/minitasn1/errors.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002, 2005, 2006, 2008, 2009, 2010 Free Software
+ * Copyright (C) 2002, 2005, 2006, 2008, 2009, 2010, 2011 Free Software
  * Foundation, Inc.
  *
  * This file is part of LIBTASN1.
@@ -85,7 +85,7 @@ asn1_perror (asn1_retCode error)
  *
  * This function replaces libtasn1_strerror() in older libtasn1.
  *
- * Returns: Pointer to static (0)-terminated string describing error
+ * Returns: Pointer to static zero-terminated string describing error
  *   code.
  *
  * Since: 1.6
@@ -130,7 +130,7 @@ libtasn1_perror (asn1_retCode error)
  * similar to strerror.  The only difference is that it accepts an
  * error (number) returned by a libtasn1 function.
  *
- * Returns: Pointer to static (0)-terminated string describing error
+ * Returns: Pointer to static zero-terminated string describing error
  *   code.
  *
  * Deprecated: Use asn1_strerror() instead.
diff --git a/lib/minitasn1/gstr.c b/lib/minitasn1/gstr.c
index b3f6af2..32ab904 100644
--- a/lib/minitasn1/gstr.c
+++ b/lib/minitasn1/gstr.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010 Free Software
+ * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
  * Foundation, Inc.
  *
  * This file is part of LIBTASN1.
diff --git a/lib/minitasn1/gstr.h b/lib/minitasn1/gstr.h
index bffb912..33bdec9 100644
--- a/lib/minitasn1/gstr.h
+++ b/lib/minitasn1/gstr.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010 Free Software
+ * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010, 2011 Free Software
  * Foundation, Inc.
  *
  * This file is part of LIBTASN1.
diff --git a/lib/minitasn1/int.h b/lib/minitasn1/int.h
index def4927..6b2b5eb 100644
--- a/lib/minitasn1/int.h
+++ b/lib/minitasn1/int.h
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
- * Software Foundation, Inc.
+ * Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+ * Free Software Foundation, Inc.
  *
  * This file is part of LIBTASN1.
  *
diff --git a/lib/minitasn1/libtasn1.h b/lib/minitasn1/libtasn1.h
index fd3a139..78f7b54 100644
--- a/lib/minitasn1/libtasn1.h
+++ b/lib/minitasn1/libtasn1.h
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
- * Software Foundation, Inc.
+ * Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+ * Free Software Foundation, Inc.
  *
  * This file is part of LIBTASN1.
  *
@@ -45,7 +45,7 @@ extern "C"
 {
 #endif
 
-#define ASN1_VERSION "2.6"
+#define ASN1_VERSION "2.10"
 
   typedef int asn1_retCode;    /* type returned by libtasn1 functions */
 
diff --git a/lib/minitasn1/parser_aux.c b/lib/minitasn1/parser_aux.c
index a3150a8..597fe6d 100644
--- a/lib/minitasn1/parser_aux.c
+++ b/lib/minitasn1/parser_aux.c
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010 Free
- * Software Foundation, Inc.
+ * Copyright (C) 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010, 2011
+ * Free Software Foundation, Inc.
  *
  * This file is part of LIBTASN1.
  *
diff --git a/lib/minitasn1/parser_aux.h b/lib/minitasn1/parser_aux.h
index def52ed..ca9e66c 100644
--- a/lib/minitasn1/parser_aux.h
+++ b/lib/minitasn1/parser_aux.h
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010 Free
- * Software Foundation, Inc.
+ * Copyright (C) 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010, 2011
+ * Free Software Foundation, Inc.
  *
  * This file is part of LIBTASN1.
  *
diff --git a/lib/minitasn1/structure.c b/lib/minitasn1/structure.c
index b1c5b30..c3d7896 100644
--- a/lib/minitasn1/structure.c
+++ b/lib/minitasn1/structure.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002, 2004, 2006, 2007, 2008, 2009, 2010 Free
+ * Copyright (C) 2002, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Free
  * Software Foundation, Inc.
  *
  * This file is part of LIBTASN1.
@@ -168,16 +168,11 @@ _asn1_create_static_structure (ASN1_TYPE pointer, char 
*output_file_name,
  * Creates the structures needed to manage the ASN.1 definitions.
  * @array is a vector created by asn1_parser2array().
  *
- * Returns:
- *
- * %ASN1_SUCCESS: Structure created correctly.
- *
- * %ASN1_ELEMENT_NOT_EMPTY: address@hidden not ASN1_TYPE_EMPTY.
- *
- * %ASN1_IDENTIFIER_NOT_FOUND: In the file there is an identifier that
- *   is not defined (see @errorDescription for more information).
- *
- * %ASN1_ARRAY_ERROR: The array pointed by @array is wrong.
+ * Returns: %ASN1_SUCCESS if structure was created correctly,
+ *   %ASN1_ELEMENT_NOT_EMPTY if address@hidden not ASN1_TYPE_EMPTY,
+ *   %ASN1_IDENTIFIER_NOT_FOUND if in the file there is an identifier
+ *   that is not defined (see @errorDescription for more information),
+ *   %ASN1_ARRAY_ERROR if the array pointed by @array is wrong.
  **/
 asn1_retCode
 asn1_array2tree (const ASN1_ARRAY_TYPE * array, ASN1_TYPE * definitions,
@@ -284,11 +279,8 @@ asn1_array2tree (const ASN1_ARRAY_TYPE * array, ASN1_TYPE 
* definitions,
  * Deletes the structure address@hidden  At the end, address@hidden is set
  * to ASN1_TYPE_EMPTY.
  *
- * Returns:
- *
- * %ASN1_SUCCESS: Everything OK.
- *
- * %ASN1_ELEMENT_NOT_FOUND: address@hidden was ASN1_TYPE_EMPTY.
+ * Returns: %ASN1_SUCCESS if successful, %ASN1_ELEMENT_NOT_FOUND if
+ *   address@hidden was ASN1_TYPE_EMPTY.
  **/
 asn1_retCode
 asn1_delete_structure (ASN1_TYPE * structure)
@@ -351,11 +343,8 @@ asn1_delete_structure (ASN1_TYPE * structure)
  *
  * Deletes the element named address@hidden inside address@hidden
  *
- * Returns:
- *
- * %ASN1_SUCCESS: Everything OK.
- *
- * %ASN1_ELEMENT_NOT_FOUND: The name element was not found.
+ * Returns: %ASN1_SUCCESS if successful, %ASN1_ELEMENT_NOT_FOUND if
+ *   the @element_name was not found.
  **/
 asn1_retCode
 asn1_delete_element (ASN1_TYPE structure, const char *element_name)
@@ -670,11 +659,8 @@ _asn1_expand_identifier (ASN1_TYPE * node, ASN1_TYPE root)
  *
  * rc = asn1_create_element(cert_def, "PKIX1.Certificate", certptr);
  *
- * Returns:
- *
- * %ASN1_SUCCESS: Creation OK.
- *
- * %ASN1_ELEMENT_NOT_FOUND: SOURCE_NAME isn't known
+ * Returns: %ASN1_SUCCESS if creation OK, %ASN1_ELEMENT_NOT_FOUND if
+ *   @source_name is not known.
  **/
 asn1_retCode
 asn1_create_element (ASN1_TYPE definitions, const char *source_name,
@@ -1072,13 +1058,8 @@ asn1_print_structure (FILE * out, ASN1_TYPE structure, 
const char *name,
  * Counts the number of elements of a sub-structure called NAME with
  * names equal to "?1","?2", ...
  *
- * Returns:
- *
- *  %ASN1_SUCCESS: Creation OK.
- *
- *  %ASN1_ELEMENT_NOT_FOUND: NAME isn't known.
- *
- *  %ASN1_GENERIC_ERROR: Pointer num equal to NULL.
+ * Returns: %ASN1_SUCCESS if successful, %ASN1_ELEMENT_NOT_FOUND if
+ *   @name is not known, %ASN1_GENERIC_ERROR if pointer @num is %NULL.
  **/
 asn1_retCode
 asn1_number_of_elements (ASN1_TYPE element, const char *name, int *num)
@@ -1171,7 +1152,7 @@ asn1_find_structure_from_oid (ASN1_TYPE definitions, 
const char *oidValue)
  *
  * Create a deep copy of a ASN1_TYPE variable.
  *
- * Return value: Return %ASN1_SUCCESS on success.
+ * Returns: Return %ASN1_SUCCESS on success.
  **/
 asn1_retCode
 asn1_copy_node (ASN1_TYPE dst, const char *dst_name,
diff --git a/lib/minitasn1/structure.h b/lib/minitasn1/structure.h
index 3885afc..98d32ab 100644
--- a/lib/minitasn1/structure.h
+++ b/lib/minitasn1/structure.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2002, 2004, 2006, 2007, 2008, 2009, 2010 Free
+ * Copyright (C) 2002, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Free
  * Software Foundation, Inc.
  *
  * This file is part of LIBTASN1.
diff --git a/lib/minitasn1/version.c b/lib/minitasn1/version.c
index ad7b43e..c0cf1f2 100644
--- a/lib/minitasn1/version.c
+++ b/lib/minitasn1/version.c
@@ -1,6 +1,6 @@
 /*
- * Copyright (C) 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010 Free
- * Software Foundation, Inc.
+ * Copyright (C) 2000, 2001, 2004, 2006, 2007, 2008, 2009, 2010, 2011
+ * Free Software Foundation, Inc.
  *
  * This file is part of LIBTASN1.
  *
diff --git a/lib/nettle/Makefile.am b/lib/nettle/Makefile.am
index a2aadad..24552dc 100644
--- a/lib/nettle/Makefile.am
+++ b/lib/nettle/Makefile.am
@@ -21,8 +21,10 @@
 AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
 AM_CPPFLAGS = \
        -I$(srcdir)/../../gl            \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/../includes         \
        -I$(builddir)/../includes       \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/..
 
 if ENABLE_MINITASN1
@@ -34,5 +36,5 @@ noinst_LTLIBRARIES = libcrypto.la
 libcrypto_la_SOURCES = pk.c mpi.c mac.c cipher.c rnd.c init.c egd.c egd.h \
        multi.c ecc_free.c ecc.h ecc_make_key.c ecc_shared_secret.c \
        ecc_map.c ecc_mulmod.c ecc_points.c ecc_projective_dbl_point_3.c \
-       ecc_projective_add_point.c ecc_projective_dbl_point.c \
+       ecc_projective_add_point.c ecc_projective_check_point.c \
        ecc_sign_hash.c ecc_verify_hash.c gnettle.h
diff --git a/lib/nettle/cipher.c b/lib/nettle/cipher.c
index 014a549..83da473 100644
--- a/lib/nettle/cipher.c
+++ b/lib/nettle/cipher.c
@@ -182,6 +182,7 @@ wrap_nettle_cipher_init (gnutls_cipher_algorithm_t algo, 
void **_ctx, int enc)
       break;
     default:
       gnutls_assert ();
+      gnutls_free(ctx);
       return GNUTLS_E_INVALID_REQUEST;
     }
 
diff --git a/lib/nettle/ecc.h b/lib/nettle/ecc.h
index caa465b..d5a5fa0 100644
--- a/lib/nettle/ecc.h
+++ b/lib/nettle/ecc.h
@@ -69,6 +69,7 @@ typedef struct {
     mpz_t prime;
     mpz_t order;
     mpz_t A;
+    mpz_t B;
     mpz_t Gx;
     mpz_t Gy;
 
@@ -79,12 +80,11 @@ typedef struct {
     mpz_t k;
 } ecc_key;
 
-int  ecc_test(void);
 void ecc_sizes(int *low, int *high);
 int  ecc_get_size(ecc_key *key);
 
 int ecc_make_key(void *random_ctx, nettle_random_func random, ecc_key *key, 
const ecc_set_type *dp);
-int ecc_make_key_ex(void *random_ctx, nettle_random_func random, ecc_key *key, 
mpz_t prime, mpz_t order, mpz_t A, mpz_t Gx, mpz_t Gy);
+int ecc_make_key_ex(void *random_ctx, nettle_random_func random, ecc_key *key, 
mpz_t prime, mpz_t order, mpz_t A, mpz_t B, mpz_t Gx, mpz_t Gy);
 void ecc_free(ecc_key *key);
 
 int  ecc_shared_secret(ecc_key *private_key, ecc_key *public_key, 
@@ -115,9 +115,10 @@ int ecc_mulmod(mpz_t k, ecc_point *G, ecc_point *R, mpz_t 
a, mpz_t modulus, int
 /* map P to affine from projective */
 int ecc_map(ecc_point *P, mpz_t modulus);
 
+/* check whether a point lies on the curve */
+int ecc_projective_check_point (ecc_point * P, mpz_t b, mpz_t modulus);
+
 /* helper functions */
 int mp_init_multi(mpz_t *a, ...);
 void mp_clear_multi(mpz_t *a, ...);
-#define mp_isodd(a)                  (mpz_size(a) > 0 ? (mpz_getlimbn(a, 0) & 
1 ? 1 : 0) : 0)
 
-#define MP_DIGIT_BIT (sizeof(mp_limb_t) * 8 - GMP_NAIL_BITS)
diff --git a/lib/nettle/ecc_free.c b/lib/nettle/ecc_free.c
index ab04d03..d5708dd 100644
--- a/lib/nettle/ecc_free.c
+++ b/lib/nettle/ecc_free.c
@@ -37,7 +37,7 @@ void
 ecc_free (ecc_key * key)
 {
   mp_clear_multi (&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k,
-                  &key->prime, &key->order, &key->Gx, &key->Gy, &key->A, NULL);
+                  &key->prime, &key->order, &key->Gx, &key->Gy, &key->A, 
&key->B, NULL);
 }
 
 /* $Source: /cvs/libtom/libtomcrypt/src/pk/ecc/ecc_free.c,v $ */
diff --git a/lib/nettle/ecc_make_key.c b/lib/nettle/ecc_make_key.c
index 3476276..4972eab 100644
--- a/lib/nettle/ecc_make_key.c
+++ b/lib/nettle/ecc_make_key.c
@@ -43,7 +43,7 @@
 
 int
 ecc_make_key_ex (void *random_ctx, nettle_random_func random, ecc_key * key,
-                 mpz_t prime, mpz_t order, mpz_t A, mpz_t Gx, mpz_t Gy)
+                 mpz_t prime, mpz_t order, mpz_t A, mpz_t B, mpz_t Gx, mpz_t 
Gy)
 {
   int err;
   ecc_point *base;
@@ -67,7 +67,7 @@ ecc_make_key_ex (void *random_ctx, nettle_random_func random, 
ecc_key * key,
   /* setup the key variables */
   if ((err =
        mp_init_multi (&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k,
-                      &key->prime, &key->order, &key->A, &key->Gx, &key->Gy,
+                      &key->prime, &key->order, &key->A, &key->B, &key->Gx, 
&key->Gy,
                       NULL)) != 0)
     {
       goto ERR_BUF;
@@ -85,6 +85,7 @@ ecc_make_key_ex (void *random_ctx, nettle_random_func random, 
ecc_key * key,
   mpz_set (key->Gx, Gx);
   mpz_set (key->Gy, Gy);
   mpz_set (key->A, A);
+  mpz_set (key->B, B);
 
   mpz_set (base->x, key->Gx);
   mpz_set (base->y, key->Gy);
@@ -111,7 +112,7 @@ ecc_make_key_ex (void *random_ctx, nettle_random_func 
random, ecc_key * key,
   goto cleanup;
 errkey:
   mp_clear_multi (&key->pubkey.x, &key->pubkey.y, &key->pubkey.z, &key->k,
-                  &key->order, &key->prime, &key->Gx, &key->Gy, &key->A,
+                  &key->order, &key->prime, &key->Gx, &key->Gy, &key->A, 
&key->B,
                   NULL);
 cleanup:
   ecc_del_point (base);
@@ -124,11 +125,11 @@ int
 ecc_make_key (void *random_ctx, nettle_random_func random, ecc_key * key,
               const ecc_set_type * dp)
 {
-  mpz_t prime, order, Gx, Gy, A;
+  mpz_t prime, order, Gx, Gy, A, B;
   int err;
 
   /* setup the key variables */
-  if ((err = mp_init_multi (&prime, &order, &A, &Gx, &Gy, NULL)) != 0)
+  if ((err = mp_init_multi (&prime, &order, &A, &B, &Gx, &Gy, NULL)) != 0)
     {
       goto cleanup;
     }
@@ -139,10 +140,11 @@ ecc_make_key (void *random_ctx, nettle_random_func 
random, ecc_key * key,
   mpz_set_str (Gx, (char *) dp->Gx, 16);
   mpz_set_str (Gy, (char *) dp->Gy, 16);
   mpz_set_str (A, (char *) dp->A, 16);
+  mpz_set_str (B, (char *) dp->B, 16);
 
-  err = ecc_make_key_ex (random_ctx, random, key, prime, order, A, Gx, Gy);
+  err = ecc_make_key_ex (random_ctx, random, key, prime, order, A, B, Gx, Gy);
 
-  mp_clear_multi (&prime, &order, &A, &Gx, &Gy, NULL);
+  mp_clear_multi (&prime, &order, &A, &B, &Gx, &Gy, NULL);
 cleanup:
   return err;
 }
diff --git a/lib/nettle/ecc_mulmod.c b/lib/nettle/ecc_mulmod.c
index e9eebe3..2f12759 100644
--- a/lib/nettle/ecc_mulmod.c
+++ b/lib/nettle/ecc_mulmod.c
@@ -45,8 +45,8 @@ ecc_mulmod (mpz_t k, ecc_point * G, ecc_point * R, mpz_t a, 
mpz_t modulus,
 {
   ecc_point *tG, *M[3];
   int i, j, err;
-  unsigned long buf;
-  int bitcnt, mode, digidx;
+  int bit_to_read;
+  int mode;
 
   if (k == NULL || G == NULL || R == NULL || modulus == NULL)
     return -1;
@@ -91,29 +91,16 @@ ecc_mulmod (mpz_t k, ecc_point * G, ecc_point * R, mpz_t a, 
mpz_t modulus,
 
   /* setup sliding window */
   mode = 0;
-  bitcnt = 1;
-  buf = 0;
-  digidx = mpz_size (k) - 1;
+  bit_to_read = mpz_size (k) * GMP_NUMB_BITS - 1;
 
   /* perform ops */
   for (;;)
     {
       /* grab next digit as required */
-      if (--bitcnt == 0)
-        {
-          if (digidx == -1)
-            {
-              break;
-            }
-          buf = mpz_getlimbn (k, digidx);
-          bitcnt = (int) MP_DIGIT_BIT;
-          --digidx;
-        }
-
-      /* grab the next msb from the ltiplicand */
-      i = (buf >> (MP_DIGIT_BIT - 1)) & 1;
-      buf <<= 1;
-
+      if (bit_to_read == -1)
+        break;
+      i = mpz_tstbit (k, bit_to_read--);
+      
       if (mode == 0 && i == 0)
         {
           /* dummy operations */
diff --git a/lib/nettle/ecc_projective_add_point.c 
b/lib/nettle/ecc_projective_add_point.c
index 292a0a3..6e8d599 100644
--- a/lib/nettle/ecc_projective_add_point.c
+++ b/lib/nettle/ecc_projective_add_point.c
@@ -207,7 +207,7 @@ ecc_projective_add_point (ecc_point * P, ecc_point * Q, 
ecc_point * R,
       mpz_add (y, y, modulus);
     }
   /* Y = Y/2 */
-  if (mp_isodd (y))
+  if (mpz_odd_p (y))
     {
       mpz_add (y, y, modulus);
     }
diff --git a/lib/nettle/ecc_projective_check_point.c 
b/lib/nettle/ecc_projective_check_point.c
new file mode 100644
index 0000000..42abeea
--- /dev/null
+++ b/lib/nettle/ecc_projective_check_point.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * This file is part of GNUTLS.
+ *
+ * The GNUTLS library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "ecc.h"
+#include <gnutls_errors.h>
+
+#ifdef ECC_SECP_CURVES_ONLY
+
+/*
+  @file ecc_projective_check_point.c
+*/
+
+/*
+   Checks whether a point lies on the curve y^2 = x^3 - 3x + b
+   @param P   The point to check
+   @param modulus  The modulus of the field the ECC curve is in
+   @param b       The "B" value of the curve
+   @return 0 on success
+*/
+int ecc_projective_check_point (ecc_point * P, mpz_t b, mpz_t modulus)
+{
+    mpz_t t1, t2, t3;
+    int err;
+
+    if (P == NULL || b == NULL || modulus == NULL)
+       return -1;
+
+    if ((err = mp_init_multi (&t1, &t2, &t3, NULL)) != 0)
+      {
+         return err;
+      }
+
+    if (mpz_cmp_ui (P->z, 1) != 0)
+      {
+         gnutls_assert ();
+         return -1;
+      }
+
+    /* t1 = Z * Z */
+    mpz_mul (t1, P->y, P->y);
+    mpz_mod (t1, t1, modulus); /* t1 = y^2 */
+
+    mpz_mul (t2, P->x, P->x);
+    mpz_mod (t2, t2, modulus);
+
+    mpz_mul (t2, P->x, t2);
+    mpz_mod (t2, t2, modulus); /* t2 = x^3 */
+
+    mpz_add (t3, P->x, P->x);
+    if (mpz_cmp (t3, modulus) >= 0)
+      {
+         mpz_sub (t3, t3, modulus);
+      }
+
+    mpz_add (t3, t3, P->x);    /* t3 = 3x */
+    if (mpz_cmp (t3, modulus) >= 0)
+      {
+         mpz_sub (t3, t3, modulus);
+      }
+
+    mpz_sub (t1, t1, t2);      /* t1 = y^2 - x^3 */
+    if (mpz_cmp_ui (t1, 0) < 0)
+      {
+         mpz_add (t1, t1, modulus);
+      }
+
+    mpz_add (t1, t1, t3);      /* t1 = y^2 - x^3 + 3x */
+    if (mpz_cmp (t1, modulus) >= 0)
+      {
+         mpz_sub (t1, t1, modulus);
+      }
+
+    mpz_sub (t1, t1, b);       /* t1 = y^2 - x^3 + 3x - b */
+    if (mpz_cmp_ui (t1, 0) < 0)
+      {
+         mpz_add (t1, t1, modulus);
+      }
+
+    if (mpz_cmp_ui (t1, 0) != 0)
+      {
+         return -1;
+      }
+    else
+      {
+         return 0;
+      }
+}
+
+#endif
diff --git a/lib/nettle/ecc_projective_dbl_point.c 
b/lib/nettle/ecc_projective_dbl_point.c
deleted file mode 100644
index 4128062..0000000
--- a/lib/nettle/ecc_projective_dbl_point.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * Copyright (C) 2011 Free Software Foundation, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GNUTLS.
- *
- * The GNUTLS library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-/* Implements ECC point doubling over Z/pZ for curve y^2 = x^3 + ax + b
- */
-#include "ecc.h"
-
-#ifndef ECC_SECP_CURVES_ONLY
-
-/*
-   Double an ECC point
-   @param P   The point to double
-   @param R   [out] The destination of the double
-   @param a       The "a" value from curve
-   @param modulus  The modulus of the field the ECC curve is in
-   @return 0 on success
-*/
-int
-ecc_projective_dbl_point (ecc_point * P, ecc_point * R, mpz_t a,
-                              mpz_t modulus)
-{
-  mpz_t t1, m, s;
-  int err;
-
-   if (P == NULL || R == NULL || modulus == NULL)
-     return -1;
-
-  /*
-    algorithm used:
-     if (Y == 0)
-       return POINT_AT_INFINITY
-     S = 4*X*Y^2
-     M = 3*X^2 + a*Z^4
-     X' = M^2 - 2*S
-     Y' = M*(S - X') - 8*Y^4
-     Z' = 2*Y*Z
-     return (X', Y', Z')
-   */
-
-  if (mpz_cmp_ui(P->y, 0) == 0)
-    {
-      /* point at infinity 
-       * under jacobian coordinates
-       */
-      mpz_set(R->x, 1);
-      mpz_set(R->y, 1);
-      mpz_set(R->z, 0);
-      
-      return 0;
-    }
-
-  if ((err = mp_init_multi (&t1, &m, &s, NULL)) != 0)
-    {
-      return err;
-    }
-
-  if (P != R)
-    {
-      mpz_set (R->x, P->x);
-      mpz_set (R->y, P->y);
-      mpz_set (R->z, P->z);
-    }
-
-
-  /* m = Z * Z */
-  mpz_mul (m, R->z, R->z);
-  mpz_mod (m, m, modulus);
-
-  /* Calculate Z and get rid of it */
-  /* Z = Y * Z */
-  mpz_mul (R->z, R->y, R->z);
-  mpz_mod (R->z, R->z, modulus);
-  /* Z = 2Z */
-  mpz_add (R->z, R->z, R->z);
-  if (mpz_cmp (R->z, modulus) >= 0)
-    {
-      mpz_sub (R->z, R->z, modulus);
-    }
-
-  /* continue with M and S calculations */
-
-  /* m = m * m = z^4 */
-  mpz_mul (m, m, m);
-  mpz_mod (m, m, modulus);
-
-  /* m = a * m = a*z^4 */
-  mpz_mul (m, a, m);
-  mpz_mod (m, m, modulus);
-
-  /* Y = 2y */
-  mpz_add (R->y, R->y, R->y);
-  if (mpz_cmp (R->y, modulus) >= 0)
-    {
-      mpz_sub (R->y, R->y, modulus);
-    }
-
-  /* Y = Y * Y = 4y^2 */
-  mpz_mul (R->y, R->y, R->y);
-  mpz_mod (R->y, R->y, modulus);
-
-  /* s = X*Y = 4xy^2 */
-  mpz_mul (s, R->x, R->y);
-  mpz_mod (s, s, modulus);
-
-  /* X = x^2 */
-  mpz_mul (R->x, R->x, R->x);
-  mpz_mod (R->x, R->x, modulus);
-
-  /* t1 = 2X = 2x^2 */
-  mpz_add (t1, R->x, R->x);
-  if (mpz_cmp (t1, modulus) >= 0)
-    {
-      mpz_sub (t1, t1, modulus);
-    }
-
-  /* t1 = t1+X = 3X =  3x^2 */
-  mpz_add (t1, t1, R->x);
-  if (mpz_cmp (t1, modulus) >= 0)
-    {
-      mpz_sub (t1, t1, modulus);
-    }
-
-  /* m = t1+m = 3x^2 + a*z^4 */
-  mpz_add (m, m, t1);
-  if (mpz_cmp (m, modulus) >= 0)
-    {
-      mpz_sub (m, m, modulus);
-    }
-
-  /*
-     X' = M^2 - 2*S
-     Y' = M*(S - X') - 8*Y^4
-   */
-
-  /* Y = Y*Y = 16y^4 */
-  mpz_mul (R->y, R->y, R->y);
-  mpz_mod (R->y, R->y, modulus);
-
-  /* Y = 8y^4 */
-  if (mp_isodd (R->y))
-    {
-      mpz_add (R->y, R->y, modulus);
-    }
-  mpz_divexact_ui (R->y, R->y, 2);
-
-  /* X = m^2 */
-  mpz_mul (R->x, m, m);
-  mpz_mod (R->x, R->x, modulus);
-
-  /* X = X - s = m^2 - s */
-  mpz_sub (R->x, R->x, s);
-  if (mpz_cmp_ui (R->x, 0) < 0)
-    {
-      mpz_add (R->x, R->x, modulus);
-    }
-
-  /* X = X - s = m^2 - 2s */
-  mpz_sub (R->x, R->x, s);
-  if (mpz_cmp_ui (R->x, 0) < 0)
-    {
-      mpz_add (R->x, R->x, modulus);
-    }
-
-  /* t1 = s - X */
-  mpz_sub (t1, s, R->x);
-  if (mpz_cmp_ui (t1, 0) < 0)
-    {
-      mpz_add (t1, t1, modulus);
-    }
-
-  /* t1 = M * t1 = M * (s-X) */
-  mpz_mul (t1, m, t1);
-  mpz_mod (t1, t1, modulus);
-
-  /* Y = t1 - Y = (M * (s-X)) - 8y^4 */
-  mpz_sub (R->y, t1, R->y);
-  if (mpz_cmp_ui (R->y, 0) < 0)
-    {
-      mpz_add (R->y, R->y, modulus);
-    }
-
-  err = 0;
-
-  mp_clear_multi (&t1, &m, &s, NULL);
-  return err;
-}
-
-#endif
diff --git a/lib/nettle/ecc_projective_dbl_point_3.c 
b/lib/nettle/ecc_projective_dbl_point_3.c
index e25c612..64e1cf9 100644
--- a/lib/nettle/ecc_projective_dbl_point_3.c
+++ b/lib/nettle/ecc_projective_dbl_point_3.c
@@ -107,7 +107,7 @@ ecc_projective_dbl_point (ecc_point * P, ecc_point * R, 
mpz_t a /* a is -3 */,
    mpz_mul(t2, R->y, R->y);
    mpz_mod(t2, t2, modulus);
    /* T2 = T2/2 */
-   if (mp_isodd(t2)) {
+   if (mpz_odd_p(t2)) {
       mpz_add(t2, t2, modulus);
    }
    mpz_divexact_ui(t2, t2, 2);
diff --git a/lib/nettle/ecc_sign_hash.c b/lib/nettle/ecc_sign_hash.c
index ab7f943..04c3f1d 100644
--- a/lib/nettle/ecc_sign_hash.c
+++ b/lib/nettle/ecc_sign_hash.c
@@ -72,7 +72,7 @@ ecc_sign_hash (const unsigned char *in, unsigned long inlen,
     {
       if ((err =
            ecc_make_key_ex (random_ctx, random, &pubkey, key->prime,
-                            key->order, key->A, key->Gx, key->Gy)) != 0)
+                            key->order, key->A, key->B, key->Gx, key->Gy)) != 
0)
         {
           goto errnokey;
         }
diff --git a/lib/nettle/egd.c b/lib/nettle/egd.c
index bd35d56..1b67e42 100644
--- a/lib/nettle/egd.c
+++ b/lib/nettle/egd.c
@@ -19,6 +19,9 @@
  */
 
 #include <config.h>
+
+#ifndef _WIN32
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -34,6 +37,12 @@
 #include <gnutls_str.h>
 #include <gnutls_errors.h>
 
+#ifdef AF_UNIX
+# define LOCAL_SOCKET_TYPE AF_UNIX
+#else
+# define LOCAL_SOCKET_TYPE AF_LOCAL
+#endif
+
 #ifndef offsetof
 #define offsetof(type, member) ((size_t) &((type *)0)->member)
 #endif
@@ -142,12 +151,12 @@ _rndegd_connect_socket (void)
     }
 
   memset (&addr, 0, sizeof addr);
-  addr.sun_family = AF_LOCAL;
+  addr.sun_family = LOCAL_SOCKET_TYPE;
   _gnutls_str_cpy (addr.sun_path, sizeof(addr.sun_path), name);
   addr_len = (offsetof (struct sockaddr_un, sun_path)
               + strlen (addr.sun_path));
 
-  fd = socket (AF_LOCAL, SOCK_STREAM, 0);
+  fd = socket (LOCAL_SOCKET_TYPE, SOCK_STREAM, 0);
   if (fd == -1)
     {
       _gnutls_debug_log ("can't create unix domain socket: %s\n",
@@ -262,3 +271,5 @@ restart:
 
   return _length;               /* success */
 }
+
+#endif
diff --git a/lib/nettle/mac.c b/lib/nettle/mac.c
index 3be974a..4a77895 100644
--- a/lib/nettle/mac.c
+++ b/lib/nettle/mac.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008, 2010 Free Software Foundation, Inc.
+ * Copyright (C) 2008, 2010, 2011 Free Software Foundation, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
  *
@@ -35,7 +35,7 @@ typedef void (*update_func) (void *, unsigned, const uint8_t 
*);
 typedef void (*digest_func) (void *, unsigned, uint8_t *);
 typedef void (*set_key_func) (void *, unsigned, const uint8_t *);
 
-static int wrap_nettle_hash_init (gnutls_mac_algorithm_t algo, void **_ctx);
+static int wrap_nettle_hash_init (gnutls_digest_algorithm_t algo, void **_ctx);
 
 struct nettle_hash_ctx
 {
@@ -50,7 +50,7 @@ struct nettle_hash_ctx
     struct sha1_ctx sha1;
   } ctx;
   void *ctx_ptr;
-  gnutls_mac_algorithm_t algo;
+  gnutls_digest_algorithm_t algo;
   size_t length;
   update_func update;
   digest_func digest;
@@ -67,36 +67,29 @@ struct nettle_hmac_ctx
     struct hmac_sha512_ctx sha512;
     struct hmac_sha1_ctx sha1;
   } ctx;
+  
+  /* this is the context just after
+   * the set_key. Used in reset().
+   */
+  union
+  {
+    struct hmac_md5_ctx md5;
+    struct hmac_sha224_ctx sha224;
+    struct hmac_sha256_ctx sha256;
+    struct hmac_sha384_ctx sha384;
+    struct hmac_sha512_ctx sha512;
+    struct hmac_sha1_ctx sha1;
+  } init_ctx;
   void *ctx_ptr;
   gnutls_mac_algorithm_t algo;
   size_t length;
   update_func update;
   digest_func digest;
   set_key_func setkey;
-
-/* Note: Nettle doesn't have a reset function for
- * hmac so we need to manually reset a context, by
- * calling set_key(). For that reason we need to
- * store the hmac key here.
- */
-  opaque *key;
-  size_t key_size;
 };
 
-static int
-wrap_nettle_hmac_init (gnutls_mac_algorithm_t algo, void **_ctx)
+static int _hmac_ctx_init(gnutls_mac_algorithm_t algo, struct nettle_hmac_ctx 
*ctx)
 {
-  struct nettle_hmac_ctx *ctx;
-
-  ctx = gnutls_calloc (1, sizeof (struct nettle_hmac_ctx));
-  if (ctx == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  ctx->algo = algo;
-
   switch (algo)
     {
     case GNUTLS_MAC_MD5:
@@ -145,28 +138,63 @@ wrap_nettle_hmac_init (gnutls_mac_algorithm_t algo, void 
**_ctx)
       gnutls_assert ();
       return GNUTLS_E_INVALID_REQUEST;
     }
+  
+  return 0;
+}
 
-  *_ctx = ctx;
+static int wrap_nettle_hmac_fast(gnutls_mac_algorithm_t algo, 
+  const void *key, size_t key_size, const void* text, size_t text_size, 
+  void* digest)
+{
+  struct nettle_hmac_ctx ctx;
+  int ret;
+  
+  ret = _hmac_ctx_init(algo, &ctx);
+  if (ret < 0)
+    return gnutls_assert_val(ret);
 
+  ctx.setkey (&ctx, key_size, key);
+  ctx.update (&ctx, text_size, text);
+  ctx.digest (&ctx, ctx.length, digest);
+  
   return 0;
 }
 
 static int
-wrap_nettle_hmac_setkey (void *_ctx, const void *key, size_t keylen)
+wrap_nettle_hmac_init (gnutls_mac_algorithm_t algo, void **_ctx)
 {
-  struct nettle_hmac_ctx *ctx = _ctx;
+  struct nettle_hmac_ctx *ctx;
+  int ret;
+
+  ctx = gnutls_calloc (1, sizeof (struct nettle_hmac_ctx));
+  if (ctx == NULL)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_MEMORY_ERROR;
+    }
+
+  ctx->algo = algo;
+
+  ret = _hmac_ctx_init(algo, ctx);
+  if (ret < 0)
+    {
+      gnutls_free(ctx);
+      return gnutls_assert_val(ret);
+    }
 
-  if (ctx->key)
-    gnutls_free(ctx->key);
+  *_ctx = ctx;
 
-  ctx->key = gnutls_malloc(keylen);
-  if (ctx->key == NULL)
-    return GNUTLS_E_MEMORY_ERROR;
+  return 0;
+}
 
-  memcpy(ctx->key, key, keylen);
-  ctx->key_size = keylen;
+static int
+wrap_nettle_hmac_setkey (void *_ctx, const void *key, size_t keylen)
+{
+  struct nettle_hmac_ctx *ctx = _ctx;
 
   ctx->setkey (ctx->ctx_ptr, keylen, key);
+  
+  memcpy(&ctx->init_ctx, &ctx->ctx, sizeof(ctx->ctx));
 
   return GNUTLS_E_SUCCESS;
 }
@@ -176,7 +204,7 @@ wrap_nettle_hmac_reset (void *_ctx)
 {
   struct nettle_hmac_ctx *ctx = _ctx;
 
-  ctx->setkey (ctx->ctx_ptr, ctx->key_size, ctx->key);
+  memcpy(&ctx->ctx, &ctx->init_ctx, sizeof(ctx->ctx));
 }
 
 static int
@@ -189,12 +217,26 @@ wrap_nettle_hmac_update (void *_ctx, const void *text, 
size_t textsize)
   return GNUTLS_E_SUCCESS;
 }
 
+static int
+wrap_nettle_hmac_output (void *src_ctx, void *digest, size_t digestsize)
+{
+  struct nettle_hmac_ctx *ctx;
+  ctx = src_ctx;
+
+  if (digestsize < ctx->length)
+    {
+      gnutls_assert ();
+      return GNUTLS_E_SHORT_MEMORY_BUFFER;
+    }
+
+  ctx->digest (ctx->ctx_ptr, digestsize, digest);
+
+  return 0;
+}
+
 static void
 wrap_nettle_hmac_deinit (void *hd)
 {
-  struct nettle_hmac_ctx *ctx = hd;
-
-  gnutls_free (ctx->key);
   gnutls_free (hd);
 }
 
@@ -237,7 +279,7 @@ wrap_nettle_hash_deinit (void *hd)
   gnutls_free (hd);
 }
 
-static int _ctx_init(struct nettle_hash_ctx *ctx, gnutls_mac_algorithm_t algo)
+static int _ctx_init(gnutls_digest_algorithm_t algo, struct nettle_hash_ctx 
*ctx)
 {
   switch (algo)
     {
@@ -298,8 +340,25 @@ static int _ctx_init(struct nettle_hash_ctx *ctx, 
gnutls_mac_algorithm_t algo)
     return 0;
 }
 
+static int wrap_nettle_hash_fast(gnutls_digest_algorithm_t algo, 
+  const void* text, size_t text_size, 
+  void* digest)
+{
+  struct nettle_hash_ctx ctx;
+  int ret;
+  
+  ret = _ctx_init(algo, &ctx);
+  if (ret < 0)
+    return gnutls_assert_val(ret);
+
+  ctx.update (&ctx, text_size, text);
+  ctx.digest (&ctx, ctx.length, digest);
+  
+  return 0;
+}
+
 static int
-wrap_nettle_hash_init (gnutls_mac_algorithm_t algo, void **_ctx)
+wrap_nettle_hash_init (gnutls_digest_algorithm_t algo, void **_ctx)
 {
   struct nettle_hash_ctx *ctx;
   int ret;
@@ -313,9 +372,10 @@ wrap_nettle_hash_init (gnutls_mac_algorithm_t algo, void 
**_ctx)
 
   ctx->algo = algo;
 
-  if ((ret=_ctx_init( ctx, algo)) < 0)
+  if ((ret=_ctx_init( algo, ctx)) < 0)
     {
       gnutls_assert ();
+      gnutls_free(ctx);
       return ret;
     }
 
@@ -347,25 +407,9 @@ wrap_nettle_hash_reset (void *src_ctx)
   struct nettle_hash_ctx *ctx;
   ctx = src_ctx;
 
-  _ctx_init(ctx->ctx_ptr, ctx->algo);
+  _ctx_init(ctx->algo, ctx->ctx_ptr);
 }
 
-static int
-wrap_nettle_hmac_output (void *src_ctx, void *digest, size_t digestsize)
-{
-  struct nettle_hmac_ctx *ctx;
-  ctx = src_ctx;
-
-  if (digestsize < ctx->length)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_SHORT_MEMORY_BUFFER;
-    }
-
-  ctx->digest (ctx->ctx_ptr, digestsize, digest);
-
-  return 0;
-}
 
 gnutls_crypto_mac_st _gnutls_mac_ops = {
   .init = wrap_nettle_hmac_init,
@@ -374,6 +418,7 @@ gnutls_crypto_mac_st _gnutls_mac_ops = {
   .reset = wrap_nettle_hmac_reset,
   .output = wrap_nettle_hmac_output,
   .deinit = wrap_nettle_hmac_deinit,
+  .fast = wrap_nettle_hmac_fast,
 };
 
 gnutls_crypto_digest_st _gnutls_digest_ops = {
@@ -383,4 +428,5 @@ gnutls_crypto_digest_st _gnutls_digest_ops = {
   .copy = wrap_nettle_hash_copy,
   .output = wrap_nettle_hash_output,
   .deinit = wrap_nettle_hash_deinit,
+  .fast = wrap_nettle_hash_fast,
 };
diff --git a/lib/nettle/pk.c b/lib/nettle/pk.c
index 794a2c9..826c27b 100644
--- a/lib/nettle/pk.c
+++ b/lib/nettle/pk.c
@@ -89,11 +89,12 @@ _ecc_params_to_privkey(const gnutls_pk_params_st * 
pk_params,
         memcpy(&priv->prime, pk_params->params[0], sizeof(mpz_t));
         memcpy(&priv->order, pk_params->params[1], sizeof(mpz_t));
         memcpy(&priv->A, pk_params->params[2], sizeof(mpz_t));
-        memcpy(&priv->Gx, pk_params->params[3], sizeof(mpz_t));
-        memcpy(&priv->Gy, pk_params->params[4], sizeof(mpz_t));
-        memcpy(&priv->pubkey.x, pk_params->params[5], sizeof(mpz_t));
-        memcpy(&priv->pubkey.y, pk_params->params[6], sizeof(mpz_t));
-        memcpy(&priv->k, pk_params->params[7], sizeof(mpz_t));
+        memcpy(&priv->B, pk_params->params[3], sizeof(mpz_t));
+        memcpy(&priv->Gx, pk_params->params[4], sizeof(mpz_t));
+        memcpy(&priv->Gy, pk_params->params[5], sizeof(mpz_t));
+        memcpy(&priv->pubkey.x, pk_params->params[6], sizeof(mpz_t));
+        memcpy(&priv->pubkey.y, pk_params->params[7], sizeof(mpz_t));
+        memcpy(&priv->k, pk_params->params[8], sizeof(mpz_t));
         mpz_init_set_ui(priv->pubkey.z, 1);
 }
 
@@ -110,10 +111,11 @@ _ecc_params_to_pubkey(const gnutls_pk_params_st * 
pk_params,
         memcpy(&pub->prime, pk_params->params[0], sizeof(mpz_t));
         memcpy(&pub->order, pk_params->params[1], sizeof(mpz_t));
         memcpy(&pub->A, pk_params->params[2], sizeof(mpz_t));
-        memcpy(&pub->Gx, pk_params->params[3], sizeof(mpz_t));
-        memcpy(&pub->Gy, pk_params->params[4], sizeof(mpz_t));
-        memcpy(&pub->pubkey.x, pk_params->params[5], sizeof(mpz_t));
-        memcpy(&pub->pubkey.y, pk_params->params[6], sizeof(mpz_t));
+        memcpy(&pub->B, pk_params->params[3], sizeof(mpz_t));
+        memcpy(&pub->Gx, pk_params->params[4], sizeof(mpz_t));
+        memcpy(&pub->Gy, pk_params->params[5], sizeof(mpz_t));
+        memcpy(&pub->pubkey.x, pk_params->params[6], sizeof(mpz_t));
+        memcpy(&pub->pubkey.y, pk_params->params[7], sizeof(mpz_t));
         mpz_init_set_ui(pub->pubkey.z, 1);
 }
 
@@ -138,6 +140,12 @@ static int _wrap_nettle_pk_derive(gnutls_pk_algorithm_t 
algo, gnutls_datum_t * o
 
         _ecc_params_to_pubkey(pub, &ecc_pub);
         _ecc_params_to_privkey(priv, &ecc_priv);
+        
+        if (ecc_projective_check_point(&ecc_pub.pubkey, pub->params[3], 
pub->params[0]) != 0)
+          {
+            ret = gnutls_assert_val(GNUTLS_E_RECEIVED_ILLEGAL_PARAMETER);
+            goto ecc_cleanup;
+          }
 
         sz = ECC_BUF_SIZE;
         out->data = gnutls_malloc(sz);
@@ -792,6 +800,7 @@ rsa_fail:
         tls_ecc_set.Gx = st->Gx;
         tls_ecc_set.Gy = st->Gy;
         tls_ecc_set.A = st->A;
+        tls_ecc_set.B = st->B;
 
         ret = ecc_make_key(NULL, rnd_func, &key, &tls_ecc_set);
         if (ret != 0)
@@ -813,11 +822,12 @@ rsa_fail:
         mpz_set(TOMPZ(params->params[0]), key.prime);
         mpz_set(TOMPZ(params->params[1]), key.order);
         mpz_set(TOMPZ(params->params[2]), key.A);
-        mpz_set(TOMPZ(params->params[3]), key.Gx);
-        mpz_set(TOMPZ(params->params[4]), key.Gy);
-        mpz_set(TOMPZ(params->params[5]), key.pubkey.x);
-        mpz_set(TOMPZ(params->params[6]), key.pubkey.y);
-        mpz_set(TOMPZ(params->params[7]), key.k);
+        mpz_set(TOMPZ(params->params[3]), key.B);
+        mpz_set(TOMPZ(params->params[4]), key.Gx);
+        mpz_set(TOMPZ(params->params[5]), key.Gy);
+        mpz_set(TOMPZ(params->params[6]), key.pubkey.x);
+        mpz_set(TOMPZ(params->params[7]), key.pubkey.y);
+        mpz_set(TOMPZ(params->params[8]), key.k);
         
 ecc_fail:
         ecc_free(&key);
diff --git a/lib/nettle/rnd.c b/lib/nettle/rnd.c
index b3e18ac..6e7c69a 100644
--- a/lib/nettle/rnd.c
+++ b/lib/nettle/rnd.c
@@ -29,6 +29,7 @@
 
 #include <gnutls_int.h>
 #include <gnutls_errors.h>
+#include <locks.h>
 #include <gnutls_num.h>
 #include <nettle/yarrow.h>
 
@@ -55,11 +56,12 @@ static void *rnd_mutex;
 #ifdef _WIN32
 
 #include <windows.h>
+#include <wincrypt.h>
 
 #define DEVICE_READ_SIZE 16
 #define DEVICE_READ_SIZE_MAX 32
 
-static HCRYPTPROV device_fd = NULL;
+static HCRYPTPROV device_fd = 0;
 
 static int
 do_trivia_source (int init)
@@ -110,7 +112,7 @@ do_device_source (int init)
       read_size = DEVICE_READ_SIZE_MAX; /* initially read more data */
     }
 
-  if ((device_fd != NULL)
+  if ((device_fd != 0)
       && (init || ((now - device_last_read) > DEVICE_READ_INTERVAL)))
     {
 
diff --git a/lib/opencdk/Makefile.am b/lib/opencdk/Makefile.am
index b2163fe..9622e2f 100644
--- a/lib/opencdk/Makefile.am
+++ b/lib/opencdk/Makefile.am
@@ -20,8 +20,10 @@
 
 AM_CPPFLAGS = \
        -I$(srcdir)/../../gl            \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/../includes         \
        -I$(builddir)/../includes       \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/..
 
 if ENABLE_MINITASN1
diff --git a/lib/opencdk/main.c b/lib/opencdk/main.c
index 6d32bd1..bb1a163 100644
--- a/lib/opencdk/main.c
+++ b/lib/opencdk/main.c
@@ -28,9 +28,6 @@
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
-#ifdef _WIN32
-#include <windows.h>
-#endif
 
 #include "opencdk.h"
 #include "main.h"
diff --git a/lib/opencdk/opencdk.h b/lib/opencdk/opencdk.h
index 0b1ec6c..113e64e 100644
--- a/lib/opencdk/opencdk.h
+++ b/lib/opencdk/opencdk.h
@@ -24,9 +24,10 @@
 #ifndef OPENCDK_H
 #define OPENCDK_H
 
+#include <config.h>
+#include <gnutls_int.h>
 #include <stddef.h>             /* for size_t */
 #include <stdarg.h>
-#include <gnutls_int.h>
 #include <gnutls_mem.h>
 #include <gnutls/gnutls.h>
 #include <gnutls_errors.h>
diff --git a/lib/opencdk/read-packet.c b/lib/opencdk/read-packet.c
index df0c04f..700f6ba 100644
--- a/lib/opencdk/read-packet.c
+++ b/lib/opencdk/read-packet.c
@@ -556,7 +556,7 @@ read_user_id (cdk_stream_t inp, size_t pktlen, 
cdk_pkt_userid_t user_id)
     return CDK_Inv_Packet;
 
   if (DEBUG_PKT)
-    _gnutls_write_log ("read_user_id: %lu octets\n", pktlen);
+    _gnutls_write_log ("read_user_id: %lu octets\n", (unsigned long)pktlen);
 
   user_id->len = pktlen;
   rc = stream_read (inp, user_id->name, pktlen, &nread);
diff --git a/lib/opencdk/stream.c b/lib/opencdk/stream.c
index 0c5f9e9..fe6f2a2 100644
--- a/lib/opencdk/stream.c
+++ b/lib/opencdk/stream.c
@@ -1477,7 +1477,7 @@ cdk_stream_mmap_part (cdk_stream_t s, off_t off, size_t 
len,
     len = cdk_stream_get_length (s);
   if (!len)
     {
-      _gnutls_read_log ("cdk_stream_mmap_part: invalid file size %lu\n", len);
+      _gnutls_read_log ("cdk_stream_mmap_part: invalid file size %lu\n", 
(unsigned long)len);
       gnutls_assert ();
       return s->error;
     }
diff --git a/lib/openpgp/Makefile.am b/lib/openpgp/Makefile.am
index 9fcd44f..4d06564 100644
--- a/lib/openpgp/Makefile.am
+++ b/lib/openpgp/Makefile.am
@@ -21,8 +21,10 @@
 AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
 AM_CPPFLAGS = \
        -I$(srcdir)/../../gl            \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/../includes         \
        -I$(builddir)/../includes       \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/..                  \
        -I$(srcdir)/../opencdk
 
diff --git a/lib/openpgp/output.c b/lib/openpgp/output.c
index d3a9405..2b5f12d 100644
--- a/lib/openpgp/output.c
+++ b/lib/openpgp/output.c
@@ -35,45 +35,6 @@
 #define adds _gnutls_buffer_append_str
 
 static void
-hexdump (gnutls_buffer_st * str, const char *data, size_t len,
-         const char *spc)
-{
-  size_t j;
-
-  if (spc)
-    adds (str, spc);
-  for (j = 0; j < len; j++)
-    {
-      if (((j + 1) % 16) == 0)
-        {
-          addf (str, "%.2x\n", (unsigned char) data[j]);
-          if (spc && j != (len - 1))
-            adds (str, spc);
-        }
-      else if (j == (len - 1))
-        addf (str, "%.2x", (unsigned char) data[j]);
-      else
-        addf (str, "%.2x:", (unsigned char) data[j]);
-    }
-  if ((j % 16) != 0)
-    adds (str, "\n");
-}
-
-static void
-hexprint (gnutls_buffer_st * str, const char *data, size_t len)
-{
-  size_t j;
-
-  if (len == 0)
-    adds (str, "00");
-  else
-    {
-      for (j = 0; j < len; j++)
-        addf (str, "%.2x", (unsigned char) data[j]);
-    }
-}
-
-static void
 print_key_usage (gnutls_buffer_st * str, gnutls_openpgp_crt_t cert,
                  unsigned int idx)
 {
@@ -124,7 +85,7 @@ print_key_id (gnutls_buffer_st * str, gnutls_openpgp_crt_t 
cert, int idx)
   else
     {
       adds (str, _("\tID (hex): "));
-      hexprint (str, id, sizeof (id));
+      _gnutls_buffer_hexprint (str, id, sizeof (id));
       addf (str, "\n");
     }
 }
@@ -145,7 +106,7 @@ print_key_fingerprint (gnutls_buffer_st * str, 
gnutls_openpgp_crt_t cert)
   else
     {
       adds (str, _("\tFingerprint (hex): "));
-      hexprint (str, fpr, fpr_size);
+      _gnutls_buffer_hexprint (str, fpr, fpr_size);
       addf (str, "\n");
     }
 }
@@ -258,9 +219,9 @@ print_key_info (gnutls_buffer_st * str, 
gnutls_openpgp_crt_t cert, int idx)
             else
               {
                 addf (str, _("\t\tModulus (bits %d):\n"), bits);
-                hexdump (str, m.data, m.size, "\t\t\t");
+                _gnutls_buffer_hexdump (str, m.data, m.size, "\t\t\t");
                 adds (str, _("\t\tExponent:\n"));
-                hexdump (str, e.data, e.size, "\t\t\t");
+                _gnutls_buffer_hexdump (str, e.data, e.size, "\t\t\t");
 
                 gnutls_free (m.data);
                 gnutls_free (e.data);
@@ -285,13 +246,13 @@ print_key_info (gnutls_buffer_st * str, 
gnutls_openpgp_crt_t cert, int idx)
             else
               {
                 addf (str, _("\t\tPublic key (bits %d):\n"), bits);
-                hexdump (str, y.data, y.size, "\t\t\t");
+                _gnutls_buffer_hexdump (str, y.data, y.size, "\t\t\t");
                 adds (str, _("\t\tP:\n"));
-                hexdump (str, p.data, p.size, "\t\t\t");
+                _gnutls_buffer_hexdump (str, p.data, p.size, "\t\t\t");
                 adds (str, _("\t\tQ:\n"));
-                hexdump (str, q.data, q.size, "\t\t\t");
+                _gnutls_buffer_hexdump (str, q.data, q.size, "\t\t\t");
                 adds (str, _("\t\tG:\n"));
-                hexdump (str, g.data, g.size, "\t\t\t");
+                _gnutls_buffer_hexdump (str, g.data, g.size, "\t\t\t");
 
                 gnutls_free (p.data);
                 gnutls_free (q.data);
@@ -440,7 +401,7 @@ print_oneline (gnutls_buffer_st * str, gnutls_openpgp_crt_t 
cert)
     else
       {
         adds (str, _("fingerprint: "));
-        hexprint (str, fpr, fpr_size);
+        _gnutls_buffer_hexprint (str, fpr, fpr_size);
         addf (str, ", ");
       }
   }
diff --git a/lib/pkcs11.c b/lib/pkcs11.c
index 4f4c071..367c2ce 100644
--- a/lib/pkcs11.c
+++ b/lib/pkcs11.c
@@ -3,7 +3,7 @@
  * Copyright (C) 2010, 2011 Free Software Foundation
  * Copyright (C) 2008, Joe Orton <address@hidden>
  * 
- * Author: Nikos Mavrogiannopoulos
+ * Authors: Nikos Mavrogiannopoulos, Stef Walter
  *
  * Inspired and some parts (pkcs11_login) based on neon PKCS #11 support 
  * by Joe Orton. More ideas came from the pkcs11-helper library by 
diff --git a/lib/pkcs11_privkey.c b/lib/pkcs11_privkey.c
index 91497e6..8210874 100644
--- a/lib/pkcs11_privkey.c
+++ b/lib/pkcs11_privkey.c
@@ -2,7 +2,7 @@
  * GnuTLS PKCS#11 support
  * Copyright (C) 2010,2011 Free Software Foundation
  * 
- * Author: Nikos Mavrogiannopoulos
+ * Authors: Nikos Mavrogiannopoulos, Stef Walter
  *
  * The GnuTLS is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
diff --git a/lib/pkcs11_secret.c b/lib/pkcs11_secret.c
index 6630a1c..ae408cc 100644
--- a/lib/pkcs11_secret.c
+++ b/lib/pkcs11_secret.c
@@ -2,7 +2,7 @@
  * GnuTLS PKCS#11 support
  * Copyright (C) 2010, 2011 Free Software Foundation
  * 
- * Author: Nikos Mavrogiannopoulos
+ * Author: Nikos Mavrogiannopoulos, Stef Walter
  *
  * The GnuTLS is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
diff --git a/lib/pkcs11_write.c b/lib/pkcs11_write.c
index 256a7d2..8d867fb 100644
--- a/lib/pkcs11_write.c
+++ b/lib/pkcs11_write.c
@@ -2,7 +2,7 @@
  * GnuTLS PKCS#11 support
  * Copyright (C) 2010, 2011 Free Software Foundation
  * 
- * Author: Nikos Mavrogiannopoulos
+ * Authors: Nikos Mavrogiannopoulos, Stef Walter
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -447,7 +447,7 @@ gnutls_pkcs11_copy_x509_privkey (const char *token_url,
             goto cleanup;
           }
 
-        ret = _gnutls_mpi_dprint_lz(&key->params.params[7], &x);
+        ret = _gnutls_mpi_dprint_lz(&key->params.params[8], &x);
         if (ret < 0)
           {
             gnutls_assert ();
diff --git a/lib/system.c b/lib/system.c
index 226692c..88468d6 100644
--- a/lib/system.c
+++ b/lib/system.c
@@ -39,6 +39,7 @@
    Windows interfaces. */
 #undef recv
 #undef send
+#undef select
 
 /* System specific function wrappers.
  */
diff --git a/lib/x509/Makefile.am b/lib/x509/Makefile.am
index 7a18dd1..7b74707 100644
--- a/lib/x509/Makefile.am
+++ b/lib/x509/Makefile.am
@@ -19,6 +19,7 @@
 AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
 AM_CPPFLAGS = \
        -I$(srcdir)/../../gl            \
+       -I$(builddir)/../../gl          \
        -I$(srcdir)/../includes         \
        -I$(builddir)/../includes       \
        -I$(srcdir)/..                  \
@@ -40,7 +41,6 @@ libgnutls_x509_la_SOURCES =   \
        extensions.c            \
        mpi.c                   \
        output.c                \
-       output.h                \
        pbkdf2-sha1.c           \
        pbkdf2-sha1.h           \
        pkcs12.c                \
diff --git a/lib/x509/common.c b/lib/x509/common.c
index 1f1e597..69db11d 100644
--- a/lib/x509/common.c
+++ b/lib/x509/common.c
@@ -1,6 +1,5 @@
 /*
- * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free
- * Software Foundation, Inc.
+ * Copyright (C) 2003-2011 Free Software Foundation, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
  *
@@ -390,6 +389,7 @@ _gnutls_x509_data2hex (const opaque * data, size_t 
data_size,
   if (out)
     {
       out[0] = '#';
+      out[1] = 0;
       _gnutls_str_cat (out, *sizeof_out, res);
     }
 
@@ -1169,6 +1169,7 @@ _asnstr_append_name (char *name, size_t name_size, const 
char *part1,
 }
 
 
+
 /* Encodes and copies the private key parameters into a
  * subjectPublicKeyInfo structure.
  *
@@ -1245,6 +1246,43 @@ _gnutls_x509_encode_and_copy_PKI_params (ASN1_TYPE dst,
   return 0;
 }
 
+/* Encodes and public key parameters into a
+ * subjectPublicKeyInfo structure and stores it in der.
+ */
+int
+_gnutls_x509_encode_PKI_params (gnutls_datum_t *der,
+                                gnutls_pk_algorithm_t
+                                pk_algorithm, gnutls_pk_params_st * params)
+{
+  int ret;
+  ASN1_TYPE tmp;
+
+  ret = asn1_create_element (_gnutls_get_pkix (),
+                                "PKIX1.Certificate", &tmp);
+  if (ret != ASN1_SUCCESS)
+    {
+      gnutls_assert ();
+      return _gnutls_asn2err (ret);
+    }
+    
+  ret = _gnutls_x509_encode_and_copy_PKI_params (tmp,
+                                         "tbsCertificate.subjectPublicKeyInfo",
+                                         pk_algorithm, params);
+  if (ret != ASN1_SUCCESS)
+    {
+      gnutls_assert ();
+      ret = _gnutls_asn2err (ret);
+      goto cleanup;
+    }
+
+  ret = _gnutls_x509_der_encode(tmp, "tbsCertificate.subjectPublicKeyInfo", 
der, 0);
+
+cleanup:
+  asn1_delete_structure (&tmp);
+
+  return ret;
+}
+
 /* Reads and returns the PK algorithm of the given certificate-like
  * ASN.1 structure. src_name should be something like 
"tbsCertificate.subjectPublicKeyInfo".
  */
diff --git a/lib/x509/common.h b/lib/x509/common.h
index 321bfb6..1d6caaf 100644
--- a/lib/x509/common.h
+++ b/lib/x509/common.h
@@ -132,6 +132,8 @@ int _gnutls_x509_encode_and_copy_PKI_params (ASN1_TYPE dst,
                                              const char *dst_name,
                                              gnutls_pk_algorithm_t
                                              pk_algorithm, gnutls_pk_params_st 
* params);
+int _gnutls_x509_encode_PKI_params(gnutls_datum_t* der,
+                                   gnutls_pk_algorithm_t, gnutls_pk_params_st* 
params);
 int _gnutls_asn1_copy_node (ASN1_TYPE * dst, const char *dst_name,
                             ASN1_TYPE src, const char *src_name);
 
diff --git a/lib/x509/crq.c b/lib/x509/crq.c
index ba7a7c6..fa4c25b 100644
--- a/lib/x509/crq.c
+++ b/lib/x509/crq.c
@@ -2264,55 +2264,6 @@ gnutls_x509_crq_set_key_purpose_oid (gnutls_x509_crq_t 
crq,
   return 0;
 }
 
-static int
-rsadsa_crq_get_key_id (gnutls_x509_crq_t crq, int pk,
-                       unsigned char *output_data, size_t * output_data_size)
-{
-  gnutls_pk_params_st params;
-  int result = 0;
-  gnutls_datum_t der = { NULL, 0 };
-  digest_hd_st hd;
-
-  gnutls_pk_params_init(&params);
-
-  result = _gnutls_x509_crq_get_mpis (crq, &params);
-  if (result < 0)
-    {
-      gnutls_assert ();
-      return result;
-    }
-
-  result = _gnutls_x509_write_pubkey( pk, &params, &der);
-  if (result < 0)
-    {
-      gnutls_assert ();
-      goto cleanup;
-    }
-
-  result = _gnutls_hash_init (&hd, GNUTLS_MAC_SHA1);
-  if (result < 0)
-    {
-      gnutls_assert ();
-      goto cleanup;
-    }
-
-  _gnutls_hash (&hd, der.data, der.size);
-
-  _gnutls_hash_deinit (&hd, output_data);
-  *output_data_size = 20;
-
-  result = 0;
-
-cleanup:
-
-  _gnutls_free_datum (&der);
-
-  /* release all allocated MPIs
-   */
-  gnutls_pk_params_release(&params);
-  return result;
-}
-
 /**
  * gnutls_x509_crq_get_key_id:
  * @crq: a certificate of type #gnutls_x509_crq_t
@@ -2340,8 +2291,8 @@ gnutls_x509_crq_get_key_id (gnutls_x509_crq_t crq, 
unsigned int flags,
                             unsigned char *output_data,
                             size_t * output_data_size)
 {
-  int pk, result = 0, len;
-  gnutls_datum_t pubkey;
+  int pk, ret = 0;
+  gnutls_pk_params_st params;
 
   if (crq == NULL)
     {
@@ -2349,12 +2300,6 @@ gnutls_x509_crq_get_key_id (gnutls_x509_crq_t crq, 
unsigned int flags,
       return GNUTLS_E_INVALID_REQUEST;
     }
 
-  if (*output_data_size < 20)
-    {
-      *output_data_size = 20;
-      return GNUTLS_E_SHORT_MEMORY_BUFFER;
-    }
-
   pk = gnutls_x509_crq_get_pk_algorithm (crq, NULL);
   if (pk < 0)
     {
@@ -2362,51 +2307,18 @@ gnutls_x509_crq_get_key_id (gnutls_x509_crq_t crq, 
unsigned int flags,
       return pk;
     }
 
-  if (pk == GNUTLS_PK_RSA || pk == GNUTLS_PK_DSA)
-    {
-      /* This is for compatibility with what GnuTLS has printed for
-         RSA/DSA before the code below was added.  The code below is
-         applicable to all types, and it would probably be a better
-         idea to use it for RSA/DSA too, but doing so would break
-         backwards compatibility.  */
-      return rsadsa_crq_get_key_id (crq, pk, output_data, output_data_size);
-    }
-
-  pubkey.size = 0;
-  result =
-    asn1_der_coding (crq->crq, "certificationRequestInfo.subjectPKInfo", NULL,
-                     &len, NULL);
-  if (result != ASN1_MEM_ERROR)
-    {
-      gnutls_assert ();
-      return _gnutls_asn2err (result);
-    }
-
-  pubkey.data = gnutls_malloc (len);
-  if (pubkey.data == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  result =
-    asn1_der_coding (crq->crq, "certificationRequestInfo.subjectPKInfo",
-                     pubkey.data, &len, NULL);
-  if (result != ASN1_SUCCESS)
+  ret = _gnutls_x509_crq_get_mpis (crq, &params);
+  if (ret < 0)
     {
       gnutls_assert ();
-      gnutls_free (pubkey.data);
-      return _gnutls_asn2err (result);
+      return ret;
     }
+  
+  ret = _gnutls_get_key_id(pk, &params, output_data, output_data_size);
 
-  pubkey.size = len;
-
-  result = gnutls_fingerprint (GNUTLS_DIG_SHA1, &pubkey,
-                               output_data, output_data_size);
-
-  gnutls_free (pubkey.data);
+  gnutls_pk_params_release(&params);
 
-  return result;
+  return ret;
 }
 
 /**
diff --git a/lib/x509/extensions.c b/lib/x509/extensions.c
index 37dba57..4e73fd9 100644
--- a/lib/x509/extensions.c
+++ b/lib/x509/extensions.c
@@ -1,6 +1,5 @@
 /*
- * Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011 Free Software
- * Foundation, Inc.
+ * Copyright (C) 2003-2011 Free Software Foundation, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
  *
diff --git a/lib/x509/key_decode.c b/lib/x509/key_decode.c
index a13a725..7d430e8 100644
--- a/lib/x509/key_decode.c
+++ b/lib/x509/key_decode.c
@@ -102,8 +102,8 @@ _gnutls_x509_read_ecc_pubkey (opaque * der, int dersize, 
gnutls_pk_params_st * p
 /* Eventhough RFC5480 defines the public key to be an ECPoint (i.e. OCTET 
STRING),
  * it is actually copied in raw there. Why do they use ASN.1 anyway?
  */
-  return _gnutls_ecc_ansi_x963_import (der, dersize, &params->params[5],
-                                     &params->params[6]);
+  return _gnutls_ecc_ansi_x963_import (der, dersize, &params->params[6],
+                                     &params->params[7]);
 }
 
 
diff --git a/lib/x509/key_encode.c b/lib/x509/key_encode.c
index 42df697..1caf721 100644
--- a/lib/x509/key_encode.c
+++ b/lib/x509/key_encode.c
@@ -118,7 +118,7 @@ _gnutls_x509_write_ecc_pubkey (gnutls_pk_params_st * params,
   if (params->params_nr < ECC_PUBLIC_PARAMS)
     return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
 
-  result = _gnutls_ecc_ansi_x963_export(params->flags, params->params[5], 
params->params[6], /*&out*/der);
+  result = _gnutls_ecc_ansi_x963_export(params->flags, params->params[6], 
params->params[7], /*&out*/der);
   if (result < 0)
     return gnutls_assert_val(result);
 
@@ -580,7 +580,7 @@ _gnutls_asn1_encode_ecc (ASN1_TYPE * c2, 
gnutls_pk_params_st * params)
   if (params->params_nr != ECC_PRIVATE_PARAMS || oid == NULL)
     return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
 
-  ret = _gnutls_ecc_ansi_x963_export(params->flags, params->params[5], 
params->params[6], &pubkey);
+  ret = _gnutls_ecc_ansi_x963_export(params->flags, params->params[6], 
params->params[7], &pubkey);
   if (ret < 0)
     return gnutls_assert_val(ret);
   
diff --git a/lib/x509/mpi.c b/lib/x509/mpi.c
index f8d0ee5..cf90bf9 100644
--- a/lib/x509/mpi.c
+++ b/lib/x509/mpi.c
@@ -29,8 +29,6 @@
 #include "common.h"
 #include "x509_int.h"
 #include <gnutls_num.h>
-#include <gnutls_ecc.h>
-
 
 /* Reads an Integer from the DER encoded data
  */
@@ -197,7 +195,7 @@ _gnutls_x509_write_sig_params (ASN1_TYPE dst, const char 
*dst_name,
   _gnutls_str_cpy (name, sizeof (name), dst_name);
   _gnutls_str_cat (name, sizeof (name), ".algorithm");
 
-  pk = _gnutls_x509_sign_to_oid (pk_algorithm, HASH2MAC (dig));
+  pk = _gnutls_x509_sign_to_oid (pk_algorithm, dig);
   if (pk == NULL)
     {
       gnutls_assert ();
diff --git a/lib/x509/output.c b/lib/x509/output.c
index ad78498..b0e8640 100644
--- a/lib/x509/output.c
+++ b/lib/x509/output.c
@@ -29,8 +29,6 @@
 #include <x509_int.h>
 #include <gnutls_num.h>
 #include <gnutls_errors.h>
-#include <c-ctype.h>
-#include "output.h"
 
 /* I18n of error codes. */
 #include "gettext.h"
@@ -41,57 +39,6 @@
 
 #define ERROR_STR (char*) "(error)"
 
-void
-hexdump (gnutls_buffer_st * str, const char *data, size_t len,
-         const char *spc)
-{
-  size_t j;
-
-  if (spc)
-    adds (str, spc);
-  for (j = 0; j < len; j++)
-    {
-      if (((j + 1) % 16) == 0)
-        {
-          addf (str, "%.2x\n", (unsigned char) data[j]);
-          if (spc && j != (len - 1))
-            adds (str, spc);
-        }
-      else if (j == (len - 1))
-        addf (str, "%.2x", (unsigned char) data[j]);
-      else
-        addf (str, "%.2x:", (unsigned char) data[j]);
-    }
-  if ((j % 16) != 0)
-    adds (str, "\n");
-}
-
-void
-hexprint (gnutls_buffer_st * str, const char *data, size_t len)
-{
-  size_t j;
-
-  if (len == 0)
-    adds (str, "00");
-  else
-    {
-      for (j = 0; j < len; j++)
-        addf (str, "%.2x", (unsigned char) data[j]);
-    }
-}
-
-void
-asciiprint (gnutls_buffer_st * str, const char *data, size_t len)
-{
-  size_t j;
-
-  for (j = 0; j < len; j++)
-    if (c_isprint (data[j]))
-      addf (str, "%c", (unsigned char) data[j]);
-    else
-      addf (str, ".");
-}
-
 static char *
 ip_to_string (void *_ip, int ip_size, char *string, int string_size)
 {
@@ -163,9 +110,9 @@ print_proxy (gnutls_buffer_st * str, gnutls_x509_crt_t cert)
   if (npolicy)
     {
       adds (str, _("\t\t\tPolicy:\n\t\t\t\tASCII: "));
-      asciiprint (str, policy, npolicy);
+      _gnutls_buffer_asciiprint (str, policy, npolicy);
       adds (str, _("\n\t\t\t\tHexdump: "));
-      hexprint (str, policy, npolicy);
+      _gnutls_buffer_hexprint (str, policy, npolicy);
       adds (str, "\n");
     }
 }
@@ -258,7 +205,7 @@ print_ski (gnutls_buffer_st * str, gnutls_x509_crt_t cert)
     }
 
   adds (str, "\t\t\t");
-  hexprint (str, buffer, size);
+  _gnutls_buffer_hexprint (str, buffer, size);
   adds (str, "\n");
 
   gnutls_free (buffer);
@@ -327,7 +274,7 @@ print_aki (gnutls_buffer_st * str, int type, cert_type_t 
cert)
     }
 
   adds (str, "\t\t\t");
-  hexprint (str, buffer, size);
+  _gnutls_buffer_hexprint (str, buffer, size);
   adds (str, "\n");
 
   gnutls_free (buffer);
@@ -744,9 +691,9 @@ print_altname (gnutls_buffer_st * str, const char *prefix, 
int altname_type,
                 addf (str, _("%s\t\t\totherName OID: %.*s\n"), prefix,
                       (int) oidsize, oid);
                 addf (str, _("%s\t\t\totherName DER: "), prefix);
-                hexprint (str, buffer, size);
+                _gnutls_buffer_hexprint (str, buffer, size);
                 addf (str, _("\n%s\t\t\totherName ASCII: "), prefix);
-                asciiprint (str, buffer, size);
+                _gnutls_buffer_asciiprint (str, buffer, size);
                 addf (str, "\n");
               }
             gnutls_free (oid);
@@ -803,7 +750,7 @@ print_unique_ids (gnutls_buffer_st * str, const 
gnutls_x509_crt_t cert)
   if (result >= 0)
     {
       addf (str, ("\t\tIssuer Unique ID:\n"));
-      hexdump (str, buf, buf_size, "\t\t\t");
+      _gnutls_buffer_hexdump (str, buf, buf_size, "\t\t\t");
       if (buf_size == 16)
         {                       /* this could be a GUID */
           guiddump (str, buf, buf_size, "\t\t\t");
@@ -815,7 +762,7 @@ print_unique_ids (gnutls_buffer_st * str, const 
gnutls_x509_crt_t cert)
   if (result >= 0)
     {
       addf (str, ("\t\tSubject Unique ID:\n"));
-      hexdump (str, buf, buf_size, "\t\t\t");
+      _gnutls_buffer_hexdump (str, buf, buf_size, "\t\t\t");
       if (buf_size == 16)
         {                       /* this could be a GUID */
           guiddump (str, buf, buf_size, "\t\t\t");
@@ -1077,11 +1024,11 @@ print_extensions (gnutls_buffer_st * str, const char 
*prefix, int type,
             }
 
           addf (str, _("%s\t\t\tASCII: "), prefix);
-          asciiprint (str, buffer, extlen);
+          _gnutls_buffer_asciiprint (str, buffer, extlen);
           addf (str, "\n");
 
           addf (str, _("%s\t\t\tHexdump: "), prefix);
-          hexprint (str, buffer, extlen);
+          _gnutls_buffer_hexprint (str, buffer, extlen);
           adds (str, "\n");
 
           gnutls_free (buffer);
@@ -1113,7 +1060,7 @@ print_cert (gnutls_buffer_st * str, gnutls_x509_crt_t 
cert, int notsigned)
     else
       {
         adds (str, _("\tSerial Number (hex): "));
-        hexprint (str, serial, serial_size);
+        _gnutls_buffer_hexprint (str, serial, serial_size);
         adds (str, "\n");
       }
   }
@@ -1258,9 +1205,9 @@ print_cert (gnutls_buffer_st * str, gnutls_x509_crt_t 
cert, int notsigned)
               else
                 {
                   addf (str, _("\t\tModulus (bits %d):\n"), bits);
-                  hexdump (str, m.data, m.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, m.data, m.size, "\t\t\t");
                   addf (str, _("\t\tExponent (bits %d):\n"), e.size * 8);
-                  hexdump (str, e.data, e.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, e.data, e.size, "\t\t\t");
 
                   gnutls_free (m.data);
                   gnutls_free (e.data);
@@ -1282,9 +1229,9 @@ print_cert (gnutls_buffer_st * str, gnutls_x509_crt_t 
cert, int notsigned)
                 {
                   addf (str, _("\t\tCurve:\t%s\n"), 
gnutls_ecc_curve_get_name(curve));
                   addf (str, _("\t\tX:\n"));
-                  hexdump (str, x.data, x.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, x.data, x.size, "\t\t\t");
                   adds (str, _("\t\tY:\n"));
-                  hexdump (str, y.data, y.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, y.data, y.size, "\t\t\t");
 
                   gnutls_free (x.data);
                   gnutls_free (y.data);
@@ -1303,13 +1250,13 @@ print_cert (gnutls_buffer_st * str, gnutls_x509_crt_t 
cert, int notsigned)
               else
                 {
                   addf (str, _("\t\tPublic key (bits %d):\n"), bits);
-                  hexdump (str, y.data, y.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, y.data, y.size, "\t\t\t");
                   adds (str, _("\t\tP:\n"));
-                  hexdump (str, p.data, p.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, p.data, p.size, "\t\t\t");
                   adds (str, _("\t\tQ:\n"));
-                  hexdump (str, q.data, q.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, q.data, q.size, "\t\t\t");
                   adds (str, _("\t\tG:\n"));
-                  hexdump (str, g.data, g.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, g.data, g.size, "\t\t\t");
 
                   gnutls_free (p.data);
                   gnutls_free (q.data);
@@ -1388,7 +1335,7 @@ print_cert (gnutls_buffer_st * str, gnutls_x509_crt_t 
cert, int notsigned)
         }
 
       adds (str, _("\tSignature:\n"));
-      hexdump (str, buffer, size, "\t\t");
+      _gnutls_buffer_hexdump (str, buffer, size, "\t\t");
 
       gnutls_free (buffer);
     }
@@ -1413,7 +1360,7 @@ print_fingerprint (gnutls_buffer_st * str, 
gnutls_x509_crt_t cert,
     adds (str, _("\tMD5 fingerprint:\n\t\t"));
   else
     adds (str, _("\tSHA-1 fingerprint:\n\t\t"));
-  hexprint (str, buffer, size);
+  _gnutls_buffer_hexprint (str, buffer, size);
   adds (str, "\n");
 }
 
@@ -1421,8 +1368,8 @@ static void
 print_keyid (gnutls_buffer_st * str, gnutls_x509_crt_t cert)
 {
   int err;
-  char buffer[20];
-  size_t size = 20;
+  char buffer[32];
+  size_t size = sizeof(buffer);
 
   err = gnutls_x509_crt_get_key_id (cert, 0, buffer, &size);
   if (err < 0)
@@ -1432,7 +1379,7 @@ print_keyid (gnutls_buffer_st * str, gnutls_x509_crt_t 
cert)
     }
 
   adds (str, _("\tPublic Key Id:\n\t\t"));
-  hexprint (str, buffer, size);
+  _gnutls_buffer_hexprint (str, buffer, size);
   adds (str, "\n");
 }
 
@@ -1604,7 +1551,7 @@ print_oneline (gnutls_buffer_st * str, gnutls_x509_crt_t 
cert)
     else
       {
         addf (str, "SHA-1 fingerprint `");
-        hexprint (str, buffer, size);
+        _gnutls_buffer_hexprint (str, buffer, size);
         adds (str, "'");
       }
   }
@@ -1804,7 +1751,7 @@ print_crl (gnutls_buffer_st * str, gnutls_x509_crl_t crl, 
int notsigned)
                 addf (str, "error: get_number: %s\n", gnutls_strerror (err));
               else
                 {
-                  hexprint (str, nr, nr_size);
+                  _gnutls_buffer_hexprint (str, nr, nr_size);
                   addf (str, "\n");
                 }
 
@@ -1864,11 +1811,11 @@ print_crl (gnutls_buffer_st * str, gnutls_x509_crl_t 
crl, int notsigned)
                 }
 
               adds (str, _("\t\t\tASCII: "));
-              asciiprint (str, buffer, extlen);
+              _gnutls_buffer_asciiprint (str, buffer, extlen);
               adds (str, "\n");
 
               adds (str, _("\t\t\tHexdump: "));
-              hexprint (str, buffer, extlen);
+              _gnutls_buffer_hexprint (str, buffer, extlen);
               adds (str, "\n");
 
               gnutls_free (buffer);
@@ -1905,7 +1852,7 @@ print_crl (gnutls_buffer_st * str, gnutls_x509_crl_t crl, 
int notsigned)
             struct tm t;
 
             adds (str, _("\t\tSerial Number (hex): "));
-            hexprint (str, serial, serial_size);
+            _gnutls_buffer_hexprint (str, serial, serial_size);
             adds (str, "\n");
 
             if (gmtime_r (&tim, &t) == NULL)
@@ -1966,7 +1913,7 @@ print_crl (gnutls_buffer_st * str, gnutls_x509_crl_t crl, 
int notsigned)
         }
 
       adds (str, _("\tSignature:\n"));
-      hexdump (str, buffer, size, "\t\t");
+      _gnutls_buffer_hexdump (str, buffer, size, "\t\t");
 
       gnutls_free (buffer);
     }
@@ -2074,9 +2021,9 @@ print_crq (gnutls_buffer_st * str, gnutls_x509_crq_t cert)
               else
                 {
                   addf (str, _("\t\tModulus (bits %d):\n"), bits);
-                  hexdump (str, m.data, m.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, m.data, m.size, "\t\t\t");
                   adds (str, _("\t\tExponent:\n"));
-                  hexdump (str, e.data, e.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, e.data, e.size, "\t\t\t");
 
                   gnutls_free (m.data);
                   gnutls_free (e.data);
@@ -2096,13 +2043,13 @@ print_crq (gnutls_buffer_st * str, gnutls_x509_crq_t 
cert)
               else
                 {
                   addf (str, _("\t\tPublic key (bits %d):\n"), bits);
-                  hexdump (str, y.data, y.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, y.data, y.size, "\t\t\t");
                   addf (str, _("\t\tP:\n"));
-                  hexdump (str, p.data, p.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, p.data, p.size, "\t\t\t");
                   addf (str, _("\t\tQ:\n"));
-                  hexdump (str, q.data, q.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, q.data, q.size, "\t\t\t");
                   addf (str, _("\t\tG:\n"));
-                  hexdump (str, g.data, g.size, "\t\t\t");
+                  _gnutls_buffer_hexdump (str, g.data, g.size, "\t\t\t");
 
                   gnutls_free (p.data);
                   gnutls_free (q.data);
@@ -2234,11 +2181,11 @@ print_crq (gnutls_buffer_st * str, gnutls_x509_crq_t 
cert)
               }
 
             adds (str, _("\t\t\tASCII: "));
-            asciiprint (str, buffer, extlen);
+            _gnutls_buffer_asciiprint (str, buffer, extlen);
             adds (str, "\n");
 
             adds (str, _("\t\t\tHexdump: "));
-            hexprint (str, buffer, extlen);
+            _gnutls_buffer_hexprint (str, buffer, extlen);
             adds (str, "\n");
 
             gnutls_free (buffer);
@@ -2278,7 +2225,7 @@ print_crq_other (gnutls_buffer_st * str, 
gnutls_x509_crq_t crq)
     }
 
   adds (str, _("\tPublic Key Id:\n\t\t"));
-  hexprint (str, buffer, size);
+  _gnutls_buffer_hexprint (str, buffer, size);
   adds (str, "\n");
 
   gnutls_free (buffer);
diff --git a/lib/x509/output.h b/lib/x509/output.h
deleted file mode 100644
index ebf1d6d..0000000
--- a/lib/x509/output.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (C) 2011 Free Software Foundation, Inc.
- *
- * Author: Simon Josefsson
- *
- * This file is part of GnuTLS.
- *
- * The GnuTLS is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-#ifndef OUTPUT_H
-#define OUTPUT_H
-
-void hexdump (gnutls_buffer_st * str, const char *data, size_t len,
-             const char *spc);
-void hexprint (gnutls_buffer_st * str, const char *data, size_t len);
-void asciiprint (gnutls_buffer_st * str, const char *data, size_t len);
-
-#endif
diff --git a/lib/x509/privkey.c b/lib/x509/privkey.c
index 9327bdf..f7d7f3d 100644
--- a/lib/x509/privkey.c
+++ b/lib/x509/privkey.c
@@ -307,8 +307,8 @@ _gnutls_privkey_decode_ecc_key (const gnutls_datum_t * 
raw_key,
       goto error;
     }
 
-  ret = _gnutls_ecc_ansi_x963_import (out.data, out.size, 
&pkey->params.params[5],
-                                         &pkey->params.params[6]);
+  ret = _gnutls_ecc_ansi_x963_import (out.data, out.size, 
&pkey->params.params[6],
+                                         &pkey->params.params[7]);
   
   _gnutls_free_datum(&out);
   if (ret < 0)
@@ -319,7 +319,7 @@ _gnutls_privkey_decode_ecc_key (const gnutls_datum_t * 
raw_key,
   pkey->params.params_nr += 2;
 
   /* read the private key */
-  ret = _gnutls_x509_read_int (pkey_asn, "privateKey", 
&pkey->params.params[7]);
+  ret = _gnutls_x509_read_int (pkey_asn, "privateKey", 
&pkey->params.params[8]);
   if (ret < 0)
     {
       gnutls_assert();
@@ -860,7 +860,7 @@ gnutls_x509_privkey_import_ecc_raw (gnutls_x509_privkey_t 
key,
   if (ret < 0)
     return gnutls_assert_val(ret);
 
-  if (_gnutls_mpi_scan_nz (&key->params.params[5], x->data, x->size))
+  if (_gnutls_mpi_scan_nz (&key->params.params[6], x->data, x->size))
     {
       gnutls_assert ();
       ret = GNUTLS_E_MPI_SCAN_FAILED;
@@ -868,7 +868,7 @@ gnutls_x509_privkey_import_ecc_raw (gnutls_x509_privkey_t 
key,
     }
   key->params.params_nr++;
 
-  if (_gnutls_mpi_scan_nz (&key->params.params[6], y->data, y->size))
+  if (_gnutls_mpi_scan_nz (&key->params.params[7], y->data, y->size))
     {
       gnutls_assert ();
       ret = GNUTLS_E_MPI_SCAN_FAILED;
@@ -876,7 +876,7 @@ gnutls_x509_privkey_import_ecc_raw (gnutls_x509_privkey_t 
key,
     }
   key->params.params_nr++;
 
-  if (_gnutls_mpi_scan_nz (&key->params.params[7], k->data, k->size))
+  if (_gnutls_mpi_scan_nz (&key->params.params[8], k->data, k->size))
     {
       gnutls_assert ();
       ret = GNUTLS_E_MPI_SCAN_FAILED;
@@ -1022,7 +1022,7 @@ int gnutls_x509_privkey_export_ecc_raw 
(gnutls_x509_privkey_t key,
   *curve = key->params.flags;
 
   /* X */
-  ret = _gnutls_mpi_dprint_lz (key->params.params[5], x);
+  ret = _gnutls_mpi_dprint_lz (key->params.params[6], x);
   if (ret < 0)
     {
       gnutls_assert ();
@@ -1030,7 +1030,7 @@ int gnutls_x509_privkey_export_ecc_raw 
(gnutls_x509_privkey_t key,
     }
 
   /* Y */
-  ret = _gnutls_mpi_dprint_lz (key->params.params[6], y);
+  ret = _gnutls_mpi_dprint_lz (key->params.params[7], y);
   if (ret < 0)
     {
       gnutls_assert ();
@@ -1040,7 +1040,7 @@ int gnutls_x509_privkey_export_ecc_raw 
(gnutls_x509_privkey_t key,
 
 
   /* K */
-  ret = _gnutls_mpi_dprint_lz (key->params.params[7], k);
+  ret = _gnutls_mpi_dprint_lz (key->params.params[8], k);
   if (ret < 0)
     {
       gnutls_assert ();
@@ -1391,9 +1391,7 @@ gnutls_x509_privkey_get_key_id (gnutls_x509_privkey_t key,
                                 unsigned char *output_data,
                                 size_t * output_data_size)
 {
-  int result;
-  digest_hd_st hd;
-  gnutls_datum_t der = { NULL, 0 };
+  int ret;
 
   if (key == NULL)
     {
@@ -1401,38 +1399,13 @@ gnutls_x509_privkey_get_key_id (gnutls_x509_privkey_t 
key,
       return GNUTLS_E_INVALID_REQUEST;
     }
 
-  if (*output_data_size < 20)
-    {
-      gnutls_assert ();
-      *output_data_size = 20;
-      return GNUTLS_E_SHORT_MEMORY_BUFFER;
-    }
-
-  result = _gnutls_x509_write_pubkey(key->pk_algorithm, &key->params, &der);
-  if (result < 0)
-    {
-      gnutls_assert ();
-      goto cleanup;
-    }
-
-  result = _gnutls_hash_init (&hd, GNUTLS_MAC_SHA1);
-  if (result < 0)
+  ret = _gnutls_get_key_id(key->pk_algorithm, &key->params, output_data, 
output_data_size);
+  if (ret < 0)
     {
       gnutls_assert ();
-      goto cleanup;
     }
 
-  _gnutls_hash (&hd, der.data, der.size);
-
-  _gnutls_hash_deinit (&hd, output_data);
-  *output_data_size = 20;
-
-  result = 0;
-
-cleanup:
-
-  _gnutls_free_datum (&der);
-  return result;
+  return ret;
 }
 
 
diff --git a/lib/x509/privkey_pkcs8.c b/lib/x509/privkey_pkcs8.c
index 106a13f..b9d2eca 100644
--- a/lib/x509/privkey_pkcs8.c
+++ b/lib/x509/privkey_pkcs8.c
@@ -994,6 +994,7 @@ _decode_pkcs8_ecc_key (ASN1_TYPE pkcs8_asn, 
gnutls_x509_privkey_t pkey)
   _gnutls_free_datum (&tmp);
   if (pkey->key == NULL)
     {
+      ret = GNUTLS_E_PARSING_ERROR;
       gnutls_assert ();
       goto error;
     }
diff --git a/lib/x509/verify-high.c b/lib/x509/verify-high.c
index fb096e8..b0efe32 100644
--- a/lib/x509/verify-high.c
+++ b/lib/x509/verify-high.c
@@ -32,11 +32,10 @@
 #include <hash.h>
 #include "x509_int.h"
 #include <common.h>
+#include "verify-high.h"
 
 #define DEFAULT_SIZE 503
 
-#include "verify-high.h"
-
 /**
  * gnutls_x509_trust_list_init:
  * @list: The structure to be initialized
diff --git a/lib/x509/x509.c b/lib/x509/x509.c
index 25de5ae..f186a6f 100644
--- a/lib/x509/x509.c
+++ b/lib/x509/x509.c
@@ -2186,76 +2186,36 @@ _gnutls_get_key_id (gnutls_pk_algorithm_t pk, 
gnutls_pk_params_st * params,
                     unsigned char *output_data,
                     size_t * output_data_size)
 {
-  int result = 0;
+  int ret = 0;
   gnutls_datum_t der = { NULL, 0 };
-  digest_hd_st hd;
+  const gnutls_digest_algorithm_t hash = GNUTLS_DIG_SHA1;
+  int digest_len = _gnutls_hash_get_algo_len(hash);
 
-  if (output_data == NULL || *output_data_size < 20)
+  if (output_data == NULL || *output_data_size < digest_len)
     {
       gnutls_assert ();
-      *output_data_size = 20;
+      *output_data_size = digest_len;
       return GNUTLS_E_SHORT_MEMORY_BUFFER;
     }
 
-  result = _gnutls_x509_write_pubkey(pk, params, &der);
-  if (result < 0)
-    {
-      gnutls_assert ();
-      goto cleanup;
-    }
+  ret = _gnutls_x509_encode_PKI_params(&der, pk, params);
+  if (ret < 0)
+    return gnutls_assert_val(ret);
 
-  result = _gnutls_hash_init (&hd, GNUTLS_MAC_SHA1);
-  if (result < 0)
+  ret = _gnutls_hash_fast(hash, der.data, der.size, output_data);
+  if (ret < 0)
     {
       gnutls_assert ();
       goto cleanup;
     }
+  *output_data_size = digest_len;
 
-  _gnutls_hash (&hd, der.data, der.size);
-
-  _gnutls_hash_deinit (&hd, output_data);
-  *output_data_size = 20;
-
-  result = 0;
+  ret = 0;
 
 cleanup:
 
   _gnutls_free_datum (&der);
-  return result;
-}
-
-
-static int
-rsadsa_get_key_id (gnutls_x509_crt_t crt, int pk,
-                   unsigned char *output_data, size_t * output_data_size)
-{
-  gnutls_pk_params_st params;
-  int result = 0;
-
-  result = _gnutls_x509_crt_get_mpis (crt, &params);
-  if (result < 0)
-    {
-      gnutls_assert ();
-      return result;
-    }
-
-  result =
-    _gnutls_get_key_id (pk, &params, output_data,
-                        output_data_size);
-  if (result < 0)
-    {
-      gnutls_assert ();
-      goto cleanup;
-    }
-
-  result = 0;
-
-cleanup:
-
-  /* release all allocated MPIs
-   */
-  gnutls_pk_params_release(&params);
-  return result;
+  return ret;
 }
 
 /**
@@ -2283,8 +2243,8 @@ gnutls_x509_crt_get_key_id (gnutls_x509_crt_t crt, 
unsigned int flags,
                             unsigned char *output_data,
                             size_t * output_data_size)
 {
-  int pk, result = 0, len;
-  gnutls_datum_t pubkey;
+  int pk, ret = 0;
+  gnutls_pk_params_st params;
 
   if (crt == NULL)
     {
@@ -2292,13 +2252,6 @@ gnutls_x509_crt_get_key_id (gnutls_x509_crt_t crt, 
unsigned int flags,
       return GNUTLS_E_INVALID_REQUEST;
     }
 
-  if (*output_data_size < 20)
-    {
-      gnutls_assert ();
-      *output_data_size = 20;
-      return GNUTLS_E_SHORT_MEMORY_BUFFER;
-    }
-
   pk = gnutls_x509_crt_get_pk_algorithm (crt, NULL);
   if (pk < 0)
     {
@@ -2306,51 +2259,18 @@ gnutls_x509_crt_get_key_id (gnutls_x509_crt_t crt, 
unsigned int flags,
       return pk;
     }
 
-  if (pk == GNUTLS_PK_RSA || pk == GNUTLS_PK_DSA)
-    {
-      /* This is for compatibility with what GnuTLS has printed for
-         RSA/DSA before the code below was added.  The code below is
-         applicable to all types, and it would probably be a better
-         idea to use it for RSA/DSA too, but doing so would break
-         backwards compatibility.  */
-      return rsadsa_get_key_id (crt, pk, output_data, output_data_size);
-    }
-
-  /* FIXME: what does this code do here? Isn't identical to the code
-   * in rsadsa_get_key_id?
-   */
-  pubkey.size = 0;
-  result = asn1_der_coding (crt->cert, "tbsCertificate.subjectPublicKeyInfo",
-                            NULL, &len, NULL);
-  if (result != ASN1_MEM_ERROR)
-    {
-      gnutls_assert ();
-      return _gnutls_asn2err (result);
-    }
-
-  pubkey.data = gnutls_malloc (len);
-  if (pubkey.data == NULL)
-    {
-      gnutls_assert ();
-      return GNUTLS_E_MEMORY_ERROR;
-    }
-
-  result = asn1_der_coding (crt->cert, "tbsCertificate.subjectPublicKeyInfo",
-                            pubkey.data, &len, NULL);
-  if (result != ASN1_SUCCESS)
+  ret = _gnutls_x509_crt_get_mpis (crt, &params);
+  if (ret < 0)
     {
       gnutls_assert ();
-      gnutls_free (pubkey.data);
-      return _gnutls_asn2err (result);
+      return ret;
     }
+  
+  ret = _gnutls_get_key_id(pk, &params, output_data, output_data_size);
 
-  pubkey.size = len;
-  result = gnutls_fingerprint (GNUTLS_DIG_SHA1, &pubkey,
-                               output_data, output_data_size);
-
-  gnutls_free (pubkey.data);
+  gnutls_pk_params_release(&params);
 
-  return result;
+  return ret;
 }
 
 
diff --git a/lib/x509/x509_int.h b/lib/x509/x509_int.h
index 6976b07..c0dbf7e 100644
--- a/lib/x509/x509_int.h
+++ b/lib/x509/x509_int.h
@@ -70,33 +70,6 @@ typedef struct gnutls_pkcs7_int
   ASN1_TYPE pkcs7;
 } gnutls_pkcs7_int;
 
-#define MAX_PUBLIC_PARAMS_SIZE 4        /* ok for RSA and DSA */
-
-/* parameters should not be larger than this limit */
-#define DSA_PUBLIC_PARAMS 4
-#define RSA_PUBLIC_PARAMS 2
-#define ECC_PUBLIC_PARAMS 7
-
-
-#define MAX_PRIV_PARAMS_SIZE GNUTLS_MAX_PK_PARAMS       /* ok for RSA and DSA 
*/
-
-/* parameters should not be larger than this limit */
-#define DSA_PRIVATE_PARAMS 5
-#define RSA_PRIVATE_PARAMS 8
-#define ECC_PRIVATE_PARAMS 8
-
-#if MAX_PRIV_PARAMS_SIZE - RSA_PRIVATE_PARAMS < 0
-#error INCREASE MAX_PRIV_PARAMS
-#endif
-
-#if MAX_PRIV_PARAMS_SIZE - ECC_PRIVATE_PARAMS < 0
-#error INCREASE MAX_PRIV_PARAMS
-#endif
-
-#if MAX_PRIV_PARAMS_SIZE - DSA_PRIVATE_PARAMS < 0
-#error INCREASE MAX_PRIV_PARAMS
-#endif
-
 typedef struct gnutls_x509_privkey_int
 {
   /* the size of params depends on the public
diff --git a/lib/x509_b64.c b/lib/x509_b64.c
index 4da11fe..f0fbb74 100644
--- a/lib/x509_b64.c
+++ b/lib/x509_b64.c
@@ -1,6 +1,5 @@
 /*
- * Copyright (C) 2000, 2001, 2003, 2004, 2005, 2008, 2010 Free Software
- * Foundation, Inc.
+ * Copyright (C) 2000-2011 Free Software Foundation, Inc.
  *
  * Author: Nikos Mavrogiannopoulos
  *
@@ -137,38 +136,6 @@ decode (uint8_t * result, const opaque * data)
   return ret;
 }
 
-/* encodes data and puts the result into result (locally allocated)
- * The result_size is the return value
- */
-int
-_gnutls_base64_encode (const uint8_t * data, size_t data_size,
-                       uint8_t ** result)
-{
-  unsigned int i, j;
-  int ret, tmp;
-  char tmpres[4];
-
-  ret = B64SIZE (data_size);
-
-  (*result) = gnutls_malloc (ret + 1);
-  if ((*result) == NULL)
-    return GNUTLS_E_MEMORY_ERROR;
-
-  for (i = j = 0; i < data_size; i += 3, j += 4)
-    {
-      tmp = encode (tmpres, &data[i], data_size - i);
-      if (tmp == -1)
-        {
-          gnutls_free ((*result));
-          return GNUTLS_E_MEMORY_ERROR;
-        }
-      memcpy (&(*result)[j], tmpres, tmp);
-    }
-  (*result)[ret] = 0;           /* null terminated */
-
-  return ret;
-}
-
 #define INCR(what, size) \
        do { \
        what+=size; \
@@ -365,7 +332,7 @@ gnutls_pem_base64_encode_alloc (const char *msg,
 /* decodes data and puts the result into result (locally allocated)
  * The result_size is the return value
  */
-int
+static int
 _gnutls_base64_decode (const uint8_t * data, size_t data_size,
                        uint8_t ** result)
 {
diff --git a/lib/x509_b64.h b/lib/x509_b64.h
index 10bc9fa..a3bf135 100644
--- a/lib/x509_b64.h
+++ b/lib/x509_b64.h
@@ -20,12 +20,8 @@
  *
  */
 
-int _gnutls_base64_encode (const uint8_t * data, size_t data_size,
-                           uint8_t ** result);
 int _gnutls_fbase64_encode (const char *msg, const uint8_t * data,
                             int data_size, uint8_t ** result);
-int _gnutls_base64_decode (const uint8_t * data, size_t data_size,
-                           uint8_t ** result);
 int _gnutls_fbase64_decode (const char *header, const uint8_t * data,
                             size_t data_size, uint8_t ** result);
 
diff --git a/libextra/Makefile.am b/libextra/Makefile.am
deleted file mode 100644
index 6bfe0b8..0000000
--- a/libextra/Makefile.am
+++ /dev/null
@@ -1,110 +0,0 @@
-## Process this file with automake to produce Makefile.in
-# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-# Free Software Foundation, Inc.
-#
-# Author: Nikos Mavrogiannopoulos
-#
-# This file is part of GnuTLS-EXTRA.
-#
-# GnuTLS-extra is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 3 of the
-# License, or (at your option) any later version.
-#
-# GnuTLS-extra is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GnuTLS-EXTRA; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
-
-ACLOCAL_AMFLAGS = -I ../m4 -I ../gl/m4
-
-AM_CFLAGS = $(WERROR_CFLAGS) $(WSTACK_CFLAGS) $(WARN_CFLAGS)
-AM_CPPFLAGS = \
-       -I$(srcdir)/../gl                       \
-       -I$(builddir)/../lib/includes   \
-       -I$(srcdir)/../lib/includes     \
-       -I$(srcdir)/includes            \
-       -I$(srcdir)/../lib
-
-if ENABLE_MINITASN1
-AM_CPPFLAGS += -I$(srcdir)/../lib/minitasn1
-endif
-
-SUBDIRS = includes
-
-# Pkg-config script.
-pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = gnutls-extra.pc
-DISTCLEANFILES = $(pkgconfig_DATA)
-
-defexecdir = $(bindir)
-defexec_DATA = 
-
-lib_LTLIBRARIES = libgnutls-extra.la
-
-libgnutls_extra_la_SOURCES = libgnutls-extra.map gnutls_extra.c fipsmd5.c
-
-libgnutls_openssl_la_LDFLAGS = -no-undefined
-
-# OpenSSL
-
-if ENABLE_OPENSSL
-lib_LTLIBRARIES += libgnutls-openssl.la
-
-libgnutls_openssl_la_SOURCES = gnutls_openssl.c openssl_compat.h       \
-       openssl_compat.c
-
-libgnutls_openssl_la_LIBADD = ../gl/libgnu.la $(LIBSOCKET) \
-       ../lib/libgnutls.la
-
-libgnutls_openssl_la_LDFLAGS += -version-info 
$(LT_SSL_CURRENT):$(LT_SSL_REVISION):$(LT_SSL_AGE)
-
-if ENABLE_MINITASN1
-libgnutls_openssl_la_LIBADD += ../lib/minitasn1/libminitasn1.la
-else
-libgnutls_openssl_la_LDFLAGS += $(LTLIBTASN1)
-endif
-
-if HAVE_LD_OUTPUT_DEF
-libgnutls_openssl_la_LDFLAGS += \
-       -Wl,--output-def,libgnutls-openssl-$(DLL_VERSION).def
-defexec_DATA += libgnutls-openssl-$(DLL_VERSION).def
-endif
-endif
-
-# OpenPGP
-
-libgnutls_extra_la_LIBADD = $(LIBSOCKET)
-libgnutls_extra_la_LDFLAGS = -no-undefined
-
-if !ENABLE_NETTLE
-libgnutls_extra_la_LIBADD += $(LTLIBGCRYPT)
-endif
-
-# Rest
-
-if HAVE_LD_OUTPUT_DEF
-libgnutls_extra_la_LDFLAGS += \
-       -Wl,--output-def,libgnutls-extra-$(DLL_VERSION).def
-defexec_DATA += libgnutls-extra-$(DLL_VERSION).def
-endif
-
-DISTCLEANFILES += $(defexec_DATA)
-
-libgnutls_extra_la_LDFLAGS += \
-       -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE)
-
-libgnutls_extra_la_LIBADD += ../gl/libgnu.la \
-       ../lib/libgnutls.la
-
-if HAVE_LD_VERSION_SCRIPT
-libgnutls_extra_la_LDFLAGS += \
-       -Wl,--version-script=$(srcdir)/libgnutls-extra.map
-else
-libgnutls_extra_la_LDFLAGS += -export-symbols-regex '^(gnutls_).*'
-endif
diff --git a/libextra/fipsmd5.c b/libextra/fipsmd5.c
deleted file mode 100644
index 801289a..0000000
--- a/libextra/fipsmd5.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright (C) 2008, 2010 Free Software Foundation, Inc.
- *
- * Author: Simon Josefsson
- *
- * This file is part of GnuTLS-EXTRA.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <gnutls_int.h>
-#include <gnutls/crypto.h>
-#include <gnutls/extra.h>
-
-#include <md5.h>
-#include <hmac.h>
-
-static int
-md5init (gnutls_mac_algorithm_t mac, void **ctx)
-{
-  *ctx = gnutls_malloc (sizeof (struct md5_ctx));
-  if (!*ctx)
-    return GNUTLS_E_MEMORY_ERROR;
-  md5_init_ctx (*ctx);
-  return 0;
-}
-
-static int
-md5hash (void *ctx, const void *text, size_t textsize)
-{
-  md5_process_bytes (text, textsize, ctx);
-  return 0;
-}
-
-static int
-md5copy (void **dst_ctx, void *src_ctx)
-{
-  *dst_ctx = gnutls_malloc (sizeof (struct md5_ctx));
-  if (!*dst_ctx)
-    return GNUTLS_E_MEMORY_ERROR;
-  memcpy (*dst_ctx, src_ctx, sizeof (struct md5_ctx));
-  return 0;
-}
-
-static int
-md5output (void *src_ctx, void *digest, size_t digestsize)
-{
-  char out[MD5_DIGEST_SIZE];
-  md5_finish_ctx (src_ctx, out);
-  memcpy (digest, out, digestsize);
-  return 0;
-}
-
-static void
-md5deinit (void *ctx)
-{
-  gnutls_free (ctx);
-}
-
-struct hmacctx
-{
-  char *data;
-  size_t datasize;
-  char *key;
-  size_t keysize;
-};
-
-static int
-hmacmd5init (gnutls_mac_algorithm_t mac, void **ctx)
-{
-  struct hmacctx *p;
-
-  p = gnutls_malloc (sizeof (struct hmacctx));
-  if (!p)
-    return -1;
-
-  p->data = NULL;
-  p->datasize = 0;
-  p->key = NULL;
-  p->keysize = 0;
-
-  *ctx = p;
-
-  return 0;
-}
-
-static int
-hmacmd5setkey (void *ctx, const void *key, size_t keysize)
-{
-  struct hmacctx *p = ctx;
-
-  if (p->key)
-    gnutls_free (p->key);
-
-  p->key = gnutls_malloc (keysize);
-  if (!p->key)
-    return -1;
-
-  memcpy (p->key, key, keysize);
-  p->keysize = keysize;
-
-  return 0;
-}
-
-static int
-hmacmd5hash (void *ctx, const void *text, size_t textsize)
-{
-  struct hmacctx *p = ctx;
-  char *new;
-
-  new = gnutls_realloc (p->data, p->datasize + textsize);
-  if (!new)
-    return -1;
-
-  memcpy (new + p->datasize, text, textsize);
-
-  p->data = new;
-  p->datasize += textsize;
-
-  return 0;
-}
-
-static int
-hmacmd5output (void *ctx, void *digest, size_t digestsize)
-{
-  struct hmacctx *p = ctx;
-  char out[MD5_DIGEST_SIZE];
-  int ret;
-
-  ret = hmac_md5 (p->key, p->keysize, p->data, p->datasize, out);
-  if (ret)
-    return GNUTLS_E_HASH_FAILED;
-
-  memcpy (digest, out, digestsize);
-
-  return 0;
-}
-
-static void
-hmacmd5deinit (void *ctx)
-{
-  struct hmacctx *p = ctx;
-
-  if (p->data)
-    gnutls_free (p->data);
-  if (p->key)
-    gnutls_free (p->key);
-
-  gnutls_free (p);
-}
-
-static gnutls_crypto_digest_st dig = {
-  .init = md5init,
-  .hash = md5hash,
-  .copy = md5copy,
-  .output = md5output,
-  .deinit = md5deinit
-};
-
-static gnutls_crypto_mac_st mac = {
-  .init = hmacmd5init,
-  .setkey = hmacmd5setkey,
-  .hash = hmacmd5hash,
-  .output = hmacmd5output,
-  .deinit = hmacmd5deinit
-};
-
-/**
- * gnutls_register_md5_handler:
- *
- * Register a non-libgcrypt based MD5 and HMAC-MD5 handler.  This is
- * useful if you run Libgcrypt in FIPS-mode.  Normally TLS requires
- * use of MD5, so without this you cannot use GnuTLS with libgcrypt in
- * FIPS mode.
- *
- * Returns: %GNUTLS_E_SUCCESS on success, otherwise an error.
- *
- * Since: 2.6.0
- **/
-int
-gnutls_register_md5_handler (void)
-{
-  int ret;
-
-  ret = gnutls_crypto_single_digest_register (GNUTLS_DIG_MD5, INT_MAX, &dig);
-  if (ret)
-    return ret;
-
-  ret = gnutls_crypto_single_mac_register (GNUTLS_MAC_MD5, INT_MAX, &mac);
-  if (ret)
-    return ret;
-
-  return 0;
-}
diff --git a/libextra/gnutls-extra.pc.in b/libextra/gnutls-extra.pc.in
deleted file mode 100644
index 2eb74ae..0000000
--- a/libextra/gnutls-extra.pc.in
+++ /dev/null
@@ -1,26 +0,0 @@
-# Process this file with autoconf to produce a pkg-config metadata file.
-# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2008, 2010 Free Software
-# Foundation, Inc.
-# Author: Simon Josefsson
-# 
-# This file is free software; as a special exception the author gives
-# unlimited permission to copy and/or distribute it, with or without
-# modifications, as long as this notice is preserved.
-# 
-# This file is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
-# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
address@hidden@
address@hidden@
address@hidden@
address@hidden@
-
-Name: GnuTLS-extra
-Description: Additional add-ons for GnuTLS licensed under GPL
-URL: http://www.gnu.org/software/gnutls/
-Requires: gnutls
-Version: @VERSION@
-Libs: -L${libdir} -lgnutls-extra
-Libs.private: @LIBGNUTLS_EXTRA_LIBS@
-Cflags: -I${includedir}
diff --git a/libextra/gnutls_extra.c b/libextra/gnutls_extra.c
deleted file mode 100644
index 71d051a..0000000
--- a/libextra/gnutls_extra.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2001, 2004, 2005, 2007, 2008, 2009, 2010 Free Software
- * Foundation, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS-EXTRA.
- *
- * GnuTLS-extra is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * GnuTLS-extra is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#include <gnutls_int.h>
-#include <gnutls_errors.h>
-#include <gnutls_extensions.h>
-#include <algorithms.h>
-#include <gnutls/extra.h>
-
-#ifdef HAVE_GCRYPT
-#include <gcrypt.h>
-#endif
-
-static int _gnutls_init_extra = 0;
-
-/**
- * gnutls_global_init_extra:
- *
- * This function initializes the global state of gnutls-extra library
- * to defaults.
- *
- * Note that gnutls_global_init() has to be called before this
- * function.  If this function is not called then the gnutls-extra
- * library will not be usable.
- *
- * This function is not thread safe, see the discussion for
- * gnutls_global_init() on how to deal with that.
- *
- * Returns: On success, %GNUTLS_E_SUCCESS (zero) is returned,
- *   otherwise an error code is returned.
- **/
-int
-gnutls_global_init_extra (void)
-{
-  /* If the version of libgnutls != version of
-   * libextra, then do not initialize the library.
-   * This is because it may break things.
-   */
-  if (strcmp (gnutls_check_version (NULL), VERSION) != 0)
-    {
-      return GNUTLS_E_LIBRARY_VERSION_MISMATCH;
-    }
-
-  _gnutls_init_extra++;
-
-  if (_gnutls_init_extra != 1)
-    return 0;
-
-#ifdef HAVE_GCRYPT
-#ifdef gcry_fips_mode_active
-  /* Libgcrypt manual says that gcry_version_check must be called
-     before calling gcry_fips_mode_active. */
-  gcry_check_version (NULL);
-  if (gcry_fips_mode_active ())
-    {
-      int ret;
-
-      ret = gnutls_register_md5_handler ();
-      if (ret)
-        fprintf (stderr, "gnutls_register_md5_handler: %s\n",
-                 gnutls_strerror (ret));
-    }
-#endif
-#endif
-
-  return 0;
-}
-
-/**
- * gnutls_extra_check_version:
- * @req_version: version string to compare with, or %NULL.
- *
- * Check GnuTLS Extra Library version.
- *
- * See %GNUTLS_EXTRA_VERSION for a suitable @req_version string.
- *
- * Return value: Check that the version of the library is at
- *   minimum the one given as a string in @req_version and return the
- *   actual version string of the library; return %NULL if the
- *   condition is not met.  If %NULL is passed to this function no
- *   check is done and only the version string is returned.
- **/
-const char *
-gnutls_extra_check_version (const char *req_version)
-{
-  if (!req_version || strverscmp (req_version, VERSION) <= 0)
-    return VERSION;
-
-  return NULL;
-}
diff --git a/libextra/includes/Makefile.am b/libextra/includes/Makefile.am
deleted file mode 100644
index 23faf4c..0000000
--- a/libextra/includes/Makefile.am
+++ /dev/null
@@ -1,28 +0,0 @@
-## Process this file with automake to produce Makefile.in
-# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010 Free
-# Software Foundation, Inc.
-#
-# Author: Nikos Mavrogiannopoulos
-#
-# This file is part of GnuTLS-EXTRA.
-#
-# GnuTLS-extra is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 3 of the
-# License, or (at your option) any later version.
-#
-# GnuTLS-extra is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GnuTLS-EXTRA; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
-
-nobase_include_HEADERS = gnutls/extra.h
-
-if ENABLE_OPENSSL
-nobase_include_HEADERS += gnutls/openssl.h
-endif
diff --git a/libextra/includes/gnutls/extra.h b/libextra/includes/gnutls/extra.h
deleted file mode 100644
index f6adc75..0000000
--- a/libextra/includes/gnutls/extra.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2002-2011 Free Software Foundation, Inc.
- *
- * Author: Nikos Mavrogiannopoulos
- *
- * This file is part of GnuTLS-EXTRA.
- *
- * GnuTLS-extra is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 3 of the
- * License, or (at your option) any later version.
- *
- * GnuTLS-extra is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with GnuTLS-EXTRA; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- */
-
-/* Note the libgnutls-extra is not a standalone library. It requires
- * to link also against libgnutls.
- */
-
-#ifndef GNUTLS_EXTRA_H
-#define GNUTLS_EXTRA_H
-
-#include <gnutls/gnutls.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#define GNUTLS_EXTRA_VERSION GNUTLS_VERSION
-
-  int gnutls_global_init_extra (void);
-
-  /* Use internal (HMAC-)MD5 code, typically for use if libgcrypt is
-     in FIPS mode. */
-  int gnutls_register_md5_handler (void);
-
-/* returns libgnutls-extra version (call it with a NULL argument) 
- */
-  const char *gnutls_extra_check_version (const char *req_version);
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/libextra/libgnutls-extra.map b/libextra/libgnutls-extra.map
deleted file mode 100644
index 746b821..0000000
--- a/libextra/libgnutls-extra.map
+++ /dev/null
@@ -1,33 +0,0 @@
-# libgnutls-extra.map -- libgnutls-extra linker version script-*- ld-script -*-
-# Copyright (C) 2005, 2007, 2008, 2009, 2010 Free Software Foundation,
-# Inc.
-#
-# Author: Simon Josefsson
-#
-# This file is part of GnuTLS-EXTRA.
-#
-# GnuTLS-extra is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 3 of the
-# License, or (at your option) any later version.
-#
-# GnuTLS-extra is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GnuTLS-EXTRA; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-# 02110-1301, USA.
-
-GNUTLS_1_4
-{
-  global:
-    gnutls_extra_check_version;
-    gnutls_global_init_extra;
-    gnutls_register_md5_handler;
-
-  local:
-    *;
-};
diff --git a/m4/hooks.m4 b/m4/hooks.m4
index 83e73b8..4d6e9c7 100644
--- a/m4/hooks.m4
+++ b/m4/hooks.m4
@@ -40,9 +40,9 @@ AC_DEFUN([LIBGNUTLS_HOOKS],
   # Interfaces changed/added/removed:   CURRENT++       REVISION=0
   # Interfaces added:                             AGE++
   # Interfaces removed:                           AGE=0
-  AC_SUBST(LT_CURRENT, 29)
-  AC_SUBST(LT_REVISION, 0)
-  AC_SUBST(LT_AGE, 1)
+  AC_SUBST(LT_CURRENT, 30)
+  AC_SUBST(LT_REVISION, 3)
+  AC_SUBST(LT_AGE, 2)
 
   AC_SUBST(LT_SSL_CURRENT, 27)
   AC_SUBST(LT_SSL_REVISION, 1)
@@ -82,12 +82,12 @@ dnl    fi
   AC_MSG_CHECKING([whether to use nettle])
 if test "$cryptolib" = "nettle";then
   AC_MSG_RESULT(yes)
-    AC_LIB_HAVE_LINKFLAGS([nettle], [hogweed gmp], [#include <nettle/gcm.h>],
-                          [gcm_set_iv (0, 0, 0, 0)])
+    AC_LIB_HAVE_LINKFLAGS([nettle], [hogweed gmp], [#include 
<nettle/ripemd160.h>],
+                          [ripemd160_init (0)])
     if test "$ac_cv_libnettle" != yes; then
       AC_MSG_ERROR([[
   *** 
-  *** Libnettle 2.2 was not found. 
+  *** Libnettle 2.4 was not found. 
   ]])
     fi
 else
diff --git a/maint.mk b/maint.mk
index 0137df1..d2f5830 100644
--- a/maint.mk
+++ b/maint.mk
@@ -21,8 +21,12 @@
 # ME := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
 ME := maint.mk
 
-# Override this in cfg.mk if you use a non-standard build-aux directory.
-build_aux ?= $(srcdir)/build-aux
+# Diagnostic for continued use of deprecated variable.
+# Remove in 2013
+ifneq ($(build_aux),)
+ $(error "$(ME): \
+set $$(_build-aux) relative to $$(srcdir) instead of $$(build_aux)")
+endif
 
 # Do not save the original name or timestamp in the .tar.gz file.
 # Use --rsyncable if available.
@@ -34,7 +38,7 @@ GZIP_ENV = '--no-name --best $(gzip_rsyncable)'
 GIT = git
 VC = $(GIT)
 
-VC_LIST = $(build_aux)/vc-list-files -C $(srcdir)
+VC_LIST = $(srcdir)/$(_build-aux)/vc-list-files -C $(srcdir)
 
 # You can override this variable in cfg.mk to set your own regexp
 # matching files to ignore.
@@ -274,7 +278,7 @@ define _sc_search_regexp
 endef
 
 sc_avoid_if_before_free:
-       @$(build_aux)/useless-if-before-free                            \
+       @$(srcdir)/$(_build-aux)/useless-if-before-free                 \
                $(useless_free_options)                                 \
            $$($(VC_LIST_EXCEPT) | grep -v useless-if-before-free) &&   \
          { echo '$(ME): found useless "if" before "free" above' 1>&2;  \
@@ -618,7 +622,17 @@ _stddef_syms_re = NULL|offsetof|ptrdiff_t|size_t|wchar_t
 # Prohibit the inclusion of stddef.h without an actual use.
 sc_prohibit_stddef_without_use:
        @h='stddef.h'                                                   \
-       re='\<($(_stddef_syms_re)) *\('                                 \
+       re='\<($(_stddef_syms_re))\>'                                   \
+         $(_sc_header_without_use)
+
+_de1 = dirfd|(close|(fd)?open|read|rewind|seek|tell)dir(64)?(_r)?
+_de2 = (versionsort|struct dirent|getdirentries|alphasort|scandir(at)?)(64)?
+_de3 = MAXNAMLEN|DIR|ino_t|d_ino|d_fileno|d_namlen
+_dirent_syms_re = $(_de1)|$(_de2)|$(_de3)
+# Prohibit the inclusion of dirent.h without an actual use.
+sc_prohibit_dirent_without_use:
+       @h='dirent.h'                                                   \
+       re='\<($(_dirent_syms_re))\>'                                   \
          $(_sc_header_without_use)
 
 # Prohibit the inclusion of verify.h without an actual use.
@@ -749,10 +763,12 @@ gl_other_headers_ ?= \
 
 # Perl -lne code to extract "significant" cpp-defined symbols from a
 # gnulib header file, eliminating a few common false-positives.
+# The exempted names below are defined only conditionally in gnulib,
+# and hence sometimes must/may be defined in application code.
 gl_extract_significant_defines_ = \
   /^\# *define ([^_ (][^ (]*)(\s*\(|\s+\w+)/\
     && $$2 !~ /(?:rpl_|_used_without_)/\
-    && $$1 !~ /^(?:NSIG)$$/\
+    && $$1 !~ /^(?:NSIG|ENODATA)$$/\
     && $$1 !~ /^(?:SA_RESETHAND|SA_RESTART)$$/\
     and print $$1
 
@@ -1079,16 +1095,20 @@ sc_makefile_path_separator_check:
        halt=$(msg)                                                     \
          $(_sc_search_regexp)
 
-# Check that `make alpha' will not fail at the end of the process.
+# Check that `make alpha' will not fail at the end of the process,
+# i.e., when pkg-M.N.tar.xz already exists (either in "." or in ../release)
+# and is read-only.
 writable-files:
-       if test -d $(release_archive_dir); then :; else                 \
-         for file in $(distdir).tar.gz                                 \
-                     $(release_archive_dir)/$(distdir).tar.gz; do      \
-           test -e $$file || continue;                                 \
-           test -w $$file                                              \
-             || { echo ERROR: $$file is not writable; fail=1; };       \
+       if test -d $(release_archive_dir); then                         \
+         for file in $(DIST_ARCHIVES); do                              \
+           for p in ./ $(release_archive_dir)/; do                     \
+             test -e $$p$$file || continue;                            \
+             test -w $$p$$file                                         \
+               || { echo ERROR: $$p$$file is not writable; fail=1; };  \
+           done;                                                       \
          done;                                                         \
          test "$$fail" && exit 1 || : ;                                \
+       else :;                                                         \
        fi
 
 v_etc_file = $(gnulib_dir)/lib/version-etc.c
@@ -1183,9 +1203,9 @@ bootstrap-tools ?= autoconf,automake,gnulib
 # If it's not already specified, derive the GPG key ID from
 # the signed tag we've just applied to mark this release.
 gpg_key_ID ?= \
-  $$(git cat-file tag v$(VERSION) > .ann-sig \
-     && gpgv .ann-sig - < /dev/null 2>&1 \
-         | sed -n '/.*key ID \([0-9A-F]*\)/s//\1/p'; rm -f .ann-sig)
+  $$(git cat-file tag v$(VERSION) \
+     | gpgv --status-fd 1 --keyring /dev/null - - 2>/dev/null \
+     | sed -n '/^\[GNUPG:\] ERRSIG /{s///;s/ .*//p;q}')
 
 translation_project_ ?= address@hidden
 
@@ -1204,7 +1224,7 @@ else
 endif
 
 announcement: NEWS ChangeLog $(rel-files)
-       @$(build_aux)/announce-gen                                      \
+       @$(srcdir)/$(_build-aux)/announce-gen                           \
            --mail-headers='$(announcement_mail_headers_)'              \
            --release-type=$(RELEASE_TYPE)                              \
            --package=$(PACKAGE)                                        \
@@ -1228,7 +1248,7 @@ upload_dest_dir_ ?= $(PACKAGE)
 emit_upload_commands:
        @echo =====================================
        @echo =====================================
-       @echo "$(build_aux)/gnupload $(GNUPLOADFLAGS) \\"
+       @echo "$(srcdir)/$(_build-aux)/gnupload $(GNUPLOADFLAGS) \\"
        @echo "    --to $(gnu_rel_host):$(upload_dest_dir_) \\"
        @echo "  $(rel-files)"
        @echo '# send the ~/announce-$(my_distdir) e-mail'
@@ -1323,7 +1343,7 @@ web-manual:
        @test -z "$(manual_title)" \
          && { echo define manual_title in cfg.mk 1>&2; exit 1; } || :
        @cd '$(srcdir)/doc'; \
-         $(SHELL) ../build-aux/gendocs.sh $(gendocs_options_) \
+         $(SHELL) ../$(_build-aux)/gendocs.sh $(gendocs_options_) \
             -o '$(abs_builddir)/doc/manual' \
             --email $(PACKAGE_BUGREPORT) $(PACKAGE) \
            "$(PACKAGE_NAME) - $(manual_title)"
@@ -1388,7 +1408,7 @@ update-copyright-env ?=
 update-copyright:
        grep -l -w Copyright                                             \
          $$(export VC_LIST_EXCEPT_DEFAULT=COPYING && $(VC_LIST_EXCEPT)) \
-         | $(update-copyright-env) xargs $(build_aux)/$@
+         | $(update-copyright-env) xargs $(srcdir)/$(_build-aux)/$@
 
 # This tight_scope test is skipped with a warning if $(_gl_TS_headers) is not
 # overridden and $(_gl_TS_dir)/Makefile.am does not mention noinst_HEADERS.
diff --git a/po/it.po.in b/po/it.po.in
index 6878f2b..2655c81 100644
--- a/po/it.po.in
+++ b/po/it.po.in
@@ -1,554 +1,693 @@
 # Italian translation for libgnutls.
-# Copyright (C) 2010 Free Software Foundation, Inc.
+# Copyright (C) 2010, 2011 Free Software Foundation, Inc.
 # This file is distributed under the same license as the libgnutls package.
-# Sergio Zanchetta <address@hidden>, 2010.
+# Sergio Zanchetta <address@hidden>, 2010, 2011.
+#
 msgid ""
 msgstr ""
-"Project-Id-Version: libgnutls-2.8.5\n"
+"Project-Id-Version: libgnutls-3.0.0\n"
 "Report-Msgid-Bugs-To: address@hidden"
-"POT-Creation-Date: 2009-11-02 11:37+0100\n"
-"PO-Revision-Date: 2010-03-26 10:40+0100\n"
+"POT-Creation-Date: 2011-07-29 21:37+0200\n"
+"PO-Revision-Date: 2011-10-25 11:44+0200\n"
 "Last-Translator: Sergio Zanchetta <address@hidden>\n"
 "Language-Team: Italian <address@hidden>\n"
+"Language: it\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural= (n != 1)\n"
 
-#: gnutls_errors.c:51
+#: lib/gnutls_errors.c:52
 msgid "Success."
 msgstr "Successo."
 
-#: gnutls_errors.c:52
+#: lib/gnutls_errors.c:53
 msgid "Could not negotiate a supported cipher suite."
 msgstr "Impossibile negoziare una suite supportata di cifrari."
 
-#: gnutls_errors.c:54
+#: lib/gnutls_errors.c:55
 msgid "The cipher type is unsupported."
 msgstr "Il tipo di cifrario non è supportato."
 
-#: gnutls_errors.c:56
+#: lib/gnutls_errors.c:57
 msgid "The certificate and the given key do not match."
 msgstr "Il certificato e la chiave fornita non corrispondono."
 
-#: gnutls_errors.c:58
+#: lib/gnutls_errors.c:59
 msgid "Could not negotiate a supported compression method."
 msgstr "Impossibile negoziare un metodo di compressione supportato."
 
-#: gnutls_errors.c:60
+#: lib/gnutls_errors.c:61
 msgid "An unknown public key algorithm was encountered."
 msgstr "È stato trovato un algoritmo a chiave pubblica sconosciuto."
 
-#: gnutls_errors.c:63
+#: lib/gnutls_errors.c:64
 msgid "An algorithm that is not enabled was negotiated."
 msgstr "È stato negoziato un algoritmo non abilitato."
 
-#: gnutls_errors.c:65
+#: lib/gnutls_errors.c:66
 msgid "A large TLS record packet was received."
 msgstr "È stato ricevuto un grande pacchetto di record TLS."
 
-#: gnutls_errors.c:67
+#: lib/gnutls_errors.c:68
 msgid "A record packet with illegal version was received."
 msgstr "È stato ricevuto un pacchetto di record con versione non valida."
 
-#: gnutls_errors.c:70
+#: lib/gnutls_errors.c:71
 msgid "The Diffie-Hellman prime sent by the server is not acceptable (not long 
enough)."
 msgstr "Il numero primo di Diffie-Hellman inviato dal server non è 
accettabile (non è abbastanza lungo)."
 
-#: gnutls_errors.c:72
+#: lib/gnutls_errors.c:73
 msgid "A TLS packet with unexpected length was received."
 msgstr "È stato ricevuto un pacchetto TLS di lunghezza inattesa."
 
-#: gnutls_errors.c:75
+#: lib/gnutls_errors.c:75
+msgid "The TLS connection was non-properly terminated."
+msgstr "La connessione TLS non è stata terminata in modo corretto."
+
+#: lib/gnutls_errors.c:78
 msgid "The specified session has been invalidated for some reason."
 msgstr "La sessione specificata è stata invalidata per qualche motivo."
 
-#: gnutls_errors.c:78
+#: lib/gnutls_errors.c:81
 msgid "GnuTLS internal error."
 msgstr "Errore interno di GnuTLS."
 
-#: gnutls_errors.c:79
+#: lib/gnutls_errors.c:82
 msgid "An illegal TLS extension was received."
 msgstr "È stata ricevuta una estensione TLS non lecita."
 
-#: gnutls_errors.c:81
+#: lib/gnutls_errors.c:84
 msgid "A TLS fatal alert has been received."
 msgstr "È stato ricevuto un segnale di allarme critico TLS."
 
-#: gnutls_errors.c:83
+#: lib/gnutls_errors.c:86
 msgid "An unexpected TLS packet was received."
 msgstr "È stato ricevuto un pacchetto TLS inatteso."
 
-#: gnutls_errors.c:85
+#: lib/gnutls_errors.c:88
 msgid "A TLS warning alert has been received."
 msgstr "È stato ricevuto un segnale di avviso TLS."
 
-#: gnutls_errors.c:88
+#: lib/gnutls_errors.c:91
 msgid "An error was encountered at the TLS Finished packet calculation."
 msgstr "È stato rilevato un errore nel calcolo del pacchetto TLS Finished."
 
-#: gnutls_errors.c:90
+#: lib/gnutls_errors.c:93
 msgid "The peer did not send any certificate."
 msgstr "Il peer non ha inviato alcun certificato."
 
-#: gnutls_errors.c:93
+#: lib/gnutls_errors.c:95
+msgid "The given DSA key is incompatible with the selected TLS protocol."
+msgstr "La chiave DSA fornita non è compatibile con il protocollo TLS 
selezionato."
+
+#: lib/gnutls_errors.c:98
 msgid "There is already a crypto algorithm with lower priority."
 msgstr "Esiste già un algoritmo di cifratura con priorità più bassa."
 
-#: gnutls_errors.c:96
+#: lib/gnutls_errors.c:101
 msgid "No temporary RSA parameters were found."
 msgstr "Non è stato trovato alcun parametro RSA temporaneo."
 
-#: gnutls_errors.c:98
+#: lib/gnutls_errors.c:103
 msgid "No temporary DH parameters were found."
 msgstr "Non è stato trovato alcun parametro DH temporaneo."
 
-#: gnutls_errors.c:100
+#: lib/gnutls_errors.c:105
 msgid "An unexpected TLS handshake packet was received."
 msgstr "È stato ricevuto un pacchetto di handshake TLS inatteso."
 
-#: gnutls_errors.c:102
+#: lib/gnutls_errors.c:107
 msgid "The scanning of a large integer has failed."
 msgstr "La scansione di un intero large non è riuscita."
 
-#: gnutls_errors.c:104
+#: lib/gnutls_errors.c:109
 msgid "Could not export a large integer."
 msgstr "Impossibile esportare un intero large."
 
-#: gnutls_errors.c:106
+#: lib/gnutls_errors.c:111
 msgid "Decryption has failed."
 msgstr "Decifrazione non riuscita."
 
-#: gnutls_errors.c:107
+#: lib/gnutls_errors.c:112
 msgid "Encryption has failed."
 msgstr "Cifratura non riuscita."
 
-#: gnutls_errors.c:108
+#: lib/gnutls_errors.c:113
 msgid "Public key decryption has failed."
 msgstr "Decifrazione della chiave pubblica non riuscita."
 
-#: gnutls_errors.c:110
+#: lib/gnutls_errors.c:115
 msgid "Public key encryption has failed."
 msgstr "Cifratura della chiave pubblica non riuscita."
 
-#: gnutls_errors.c:112
+#: lib/gnutls_errors.c:117
 msgid "Public key signing has failed."
 msgstr "Firma della chiave pubblica non riuscita."
 
-#: gnutls_errors.c:114
+#: lib/gnutls_errors.c:119
 msgid "Public key signature verification has failed."
 msgstr "Verifica della firma della chiave pubblica non riuscita."
 
-#: gnutls_errors.c:116
+#: lib/gnutls_errors.c:121
 msgid "Decompression of the TLS record packet has failed."
 msgstr "Decompressione del pacchetto di record TLS non riuscita."
 
-#: gnutls_errors.c:118
+#: lib/gnutls_errors.c:123
 msgid "Compression of the TLS record packet has failed."
 msgstr "Compressione del pacchetto di record TLS non riuscita."
 
-#: gnutls_errors.c:121
+#: lib/gnutls_errors.c:126
 msgid "Internal error in memory allocation."
 msgstr "Errore interno nell'allocazione di memoria."
 
-#: gnutls_errors.c:123
+#: lib/gnutls_errors.c:128
 msgid "An unimplemented or disabled feature has been requested."
 msgstr "È stata richiesta una funzione non implementata o disabilitata."
 
-#: gnutls_errors.c:125
+#: lib/gnutls_errors.c:130
 msgid "Insufficient credentials for that request."
 msgstr "Credenziali non sufficienti per quella richiesta."
 
-#: gnutls_errors.c:127
+#: lib/gnutls_errors.c:132
 msgid "Error in password file."
 msgstr "Errore nel file di password."
 
-#: gnutls_errors.c:128
+#: lib/gnutls_errors.c:133
 msgid "Wrong padding in PKCS1 packet."
 msgstr "Riempimento non corretto nel pacchetto PKCS1."
 
-#: gnutls_errors.c:130
+#: lib/gnutls_errors.c:135
 msgid "The requested session has expired."
 msgstr "La sessione richiesta è scaduta."
 
-#: gnutls_errors.c:131
+#: lib/gnutls_errors.c:136
 msgid "Hashing has failed."
 msgstr "L'hash non è riuscito."
 
-#: gnutls_errors.c:132
+#: lib/gnutls_errors.c:137
 msgid "Base64 decoding error."
 msgstr "Errore nella decodifica base64."
 
-#: gnutls_errors.c:134
+#: lib/gnutls_errors.c:139
 msgid "Base64 unexpected header error."
 msgstr "Errore inatteso nell'header base64."
 
-#: gnutls_errors.c:137
+#: lib/gnutls_errors.c:142
 msgid "Base64 encoding error."
 msgstr "Errore nella codifica base64."
 
-#: gnutls_errors.c:139
+#: lib/gnutls_errors.c:144
 msgid "Parsing error in password file."
 msgstr "Errore di analisi nel file di password."
 
-#: gnutls_errors.c:141
+#: lib/gnutls_errors.c:146
 msgid "The requested data were not available."
 msgstr "I dati richiesti non erano disponibili."
 
-#: gnutls_errors.c:143
+#: lib/gnutls_errors.c:148
 msgid "Error in the pull function."
 msgstr "Errore nella funzione pull."
 
-#: gnutls_errors.c:144
+#: lib/gnutls_errors.c:149
 msgid "Error in the push function."
 msgstr "Errore nella funzione push."
 
-#: gnutls_errors.c:146
+#: lib/gnutls_errors.c:151
 msgid "The upper limit of record packet sequence numbers has been reached. 
Wow!"
 msgstr "È stato raggiunto il limite superiore nel numero di pacchetti di 
record sequenziali."
 
-#: gnutls_errors.c:148
+#: lib/gnutls_errors.c:153
 msgid "Error in the certificate."
 msgstr "Errore nel certificato."
 
-#: gnutls_errors.c:150
+#: lib/gnutls_errors.c:155
 msgid "Unknown Subject Alternative name in X.509 certificate."
 msgstr "Nome alternativo del soggetto sconosciuto nel certificato X.509."
 
-#: gnutls_errors.c:153
+#: lib/gnutls_errors.c:158
 msgid "Unsupported critical extension in X.509 certificate."
 msgstr "Estensione critica non supportata nel certificato X.509."
 
-#: gnutls_errors.c:155
+#: lib/gnutls_errors.c:160
 msgid "Key usage violation in certificate has been detected."
 msgstr "È stata rilevata una violazione nell'utilizzo della chiave nel 
certificato."
 
-#: gnutls_errors.c:157
+#: lib/gnutls_errors.c:162
 msgid "Resource temporarily unavailable, try again."
 msgstr "Risorsa temporaneamente non disponibile, riprovare."
 
-#: gnutls_errors.c:159
+#: lib/gnutls_errors.c:164
 msgid "Function was interrupted."
 msgstr "La funzione è stata interrotta."
 
-#: gnutls_errors.c:160
+#: lib/gnutls_errors.c:165
 msgid "Rehandshake was requested by the peer."
 msgstr "Il peer ha richiesto nuovamente l'handshake."
 
-#: gnutls_errors.c:163
+#: lib/gnutls_errors.c:168
 msgid "TLS Application data were received, while expecting handshake data."
 msgstr "Sono stati ricevuti dati TLS Application, mentre erano attesi dati 
handshake."
 
-#: gnutls_errors.c:165
+#: lib/gnutls_errors.c:170
 msgid "Error in Database backend."
 msgstr "Errore nel backend del database."
 
-#: gnutls_errors.c:166
+#: lib/gnutls_errors.c:171
 msgid "The certificate type is not supported."
 msgstr "Il tipo di certificato non è supportato."
 
-#: gnutls_errors.c:168
+#: lib/gnutls_errors.c:173
 msgid "The given memory buffer is too short to hold parameters."
 msgstr "Il buffer di memoria fornito è troppo corto per contenere i 
parametri."
 
-#: gnutls_errors.c:170
+#: lib/gnutls_errors.c:175
 msgid "The request is invalid."
 msgstr "La richiesta non è valida."
 
-#: gnutls_errors.c:171
+#: lib/gnutls_errors.c:176
+msgid "The cookie was bad."
+msgstr "Il cookie non era valido."
+
+#: lib/gnutls_errors.c:177
 msgid "An illegal parameter has been received."
 msgstr "È stato ricevuto un parametro non lecito."
 
-#: gnutls_errors.c:173
+#: lib/gnutls_errors.c:179
 msgid "Error while reading file."
 msgstr "Errore nella lettura del file."
 
-#: gnutls_errors.c:175
+#: lib/gnutls_errors.c:181
 msgid "ASN1 parser: Element was not found."
 msgstr "Analizzatore ASN1: elemento non trovato."
 
-#: gnutls_errors.c:177
+#: lib/gnutls_errors.c:183
 msgid "ASN1 parser: Identifier was not found"
 msgstr "Analizzatore ASN1: l'identificativo non è stato trovato."
 
-#: gnutls_errors.c:179
+#: lib/gnutls_errors.c:185
 msgid "ASN1 parser: Error in DER parsing."
 msgstr "Analizzatore ASN1: errore nell'analisi DER."
 
-#: gnutls_errors.c:181
+#: lib/gnutls_errors.c:187
 msgid "ASN1 parser: Value was not found."
 msgstr "Analizzatore ASN1: valore non trovato."
 
-#: gnutls_errors.c:183
+#: lib/gnutls_errors.c:189
 msgid "ASN1 parser: Generic parsing error."
 msgstr "Analizzatore ASN1: errore generico di analisi."
 
-#: gnutls_errors.c:185
+#: lib/gnutls_errors.c:191
 msgid "ASN1 parser: Value is not valid."
 msgstr "Analizzatore ASN1: valore non valido."
 
-#: gnutls_errors.c:187
+#: lib/gnutls_errors.c:193
 msgid "ASN1 parser: Error in TAG."
 msgstr "Analizzatore ASN1: errore nel TAG."
 
-#: gnutls_errors.c:188
+#: lib/gnutls_errors.c:194
 msgid "ASN1 parser: error in implicit tag"
 msgstr "Analizzatore ASN1: errore nel tag implicito."
 
-#: gnutls_errors.c:190
+#: lib/gnutls_errors.c:196
 msgid "ASN1 parser: Error in type 'ANY'."
 msgstr "Analizzatore ASN1: errore nel tipo \"ANY\"."
 
-#: gnutls_errors.c:192
+#: lib/gnutls_errors.c:198
 msgid "ASN1 parser: Syntax error."
 msgstr "Analizzatore ASN1: errore di sintassi."
 
-#: gnutls_errors.c:194
+#: lib/gnutls_errors.c:200
 msgid "ASN1 parser: Overflow in DER parsing."
 msgstr "Analizzatore ASN1: overflow nell'analisi DER."
 
-#: gnutls_errors.c:197
+#: lib/gnutls_errors.c:203
 msgid "Too many empty record packets have been received."
 msgstr "Sono stati ricevuti troppi pacchetti di record vuoti."
 
-#: gnutls_errors.c:199
+#: lib/gnutls_errors.c:205
+msgid "Too many handshake packets have been received."
+msgstr "Sono stati ricevuti troppi pacchetti di handshake."
+
+#: lib/gnutls_errors.c:207
 msgid "The initialization of GnuTLS-extra has failed."
 msgstr "L'inizializzazione di GnuTLS-extra non è riuscita."
 
-#: gnutls_errors.c:202
+#: lib/gnutls_errors.c:210
 msgid "The GnuTLS library version does not match the GnuTLS-extra library 
version."
 msgstr "La versione della libreria GnuTLS non corrisponde a quella della 
libreria GnuTLS-extra."
 
-#: gnutls_errors.c:204
-msgid "The gcrypt library version is too old."
-msgstr "Versione troppo vecchia della libreria gcrypt."
+#: lib/gnutls_errors.c:212
+msgid "The crypto library version is too old."
+msgstr "Versione troppo vecchia della libreria crypto."
 
-#: gnutls_errors.c:207
+#: lib/gnutls_errors.c:215
 msgid "The tasn1 library version is too old."
 msgstr "Versione troppo vecchia della libreria tasn1."
 
-#: gnutls_errors.c:209
+#: lib/gnutls_errors.c:217
 msgid "The OpenPGP User ID is revoked."
 msgstr "L'ID utente OpenPGP è revocato."
 
-#: gnutls_errors.c:211
+#: lib/gnutls_errors.c:219
+msgid "The OpenPGP key has not a preferred key set."
+msgstr "La chiave OpenPGP non ha un set di chiavi preferito."
+
+#: lib/gnutls_errors.c:221
 msgid "Error loading the keyring."
 msgstr "Errore nel caricare il portachiavi."
 
-#: gnutls_errors.c:213
-msgid "The initialization of LZO has failed."
-msgstr "L'inizializzazione di LZO non è riuscita."
+#: lib/gnutls_errors.c:223
+msgid "The initialization of crypto backend has failed."
+msgstr "Inizializzazione non riuscita del backend crypto."
 
-#: gnutls_errors.c:215
+#: lib/gnutls_errors.c:225
 msgid "No supported compression algorithms have been found."
 msgstr "Non è stato trovato alcun algoritmo di compressione supportato."
 
-#: gnutls_errors.c:217
+#: lib/gnutls_errors.c:227
 msgid "No supported cipher suites have been found."
 msgstr "Non è stata trovata alcuna suite di cifratura supportata."
 
-#: gnutls_errors.c:219
+#: lib/gnutls_errors.c:229
 msgid "Could not get OpenPGP key."
 msgstr "Impossibile ottenere la chiave OpenPGP."
 
-#: gnutls_errors.c:221
+#: lib/gnutls_errors.c:231
 msgid "Could not find OpenPGP subkey."
 msgstr "Impossibile trovare la sottochiave OpenPGP."
 
-#: gnutls_errors.c:224
+#: lib/gnutls_errors.c:233
+msgid "Safe renegotiation failed."
+msgstr "Rinegoziazione sicura non riuscita."
+
+#: lib/gnutls_errors.c:235
+msgid "Unsafe renegotiation denied."
+msgstr "Rinegoziazione non sicura negata."
+
+#: lib/gnutls_errors.c:238
 msgid "The SRP username supplied is illegal."
 msgstr "Il nome utente SRP fornito non è lecito."
 
-#: gnutls_errors.c:227
+#: lib/gnutls_errors.c:240
+msgid "The SRP username supplied is unknown."
+msgstr "Il nome utente SRP fornito è sconosciuto."
+
+#: lib/gnutls_errors.c:243
 msgid "The OpenPGP fingerprint is not supported."
 msgstr "L'impronta digitale OpenPGP non è supportata."
 
-#: gnutls_errors.c:229
+#: lib/gnutls_errors.c:245
+msgid "The signature algorithm is not supported."
+msgstr "L'algoritmo di firma non è supportato."
+
+#: lib/gnutls_errors.c:247
 msgid "The certificate has unsupported attributes."
 msgstr "Il certificato contiene attributi non supportati."
 
-#: gnutls_errors.c:231
+#: lib/gnutls_errors.c:249
 msgid "The OID is not supported."
 msgstr "L'OID non è supportato."
 
-#: gnutls_errors.c:233
+#: lib/gnutls_errors.c:251
 msgid "The hash algorithm is unknown."
 msgstr "L'algoritmo di hash è sconosciuto."
 
-#: gnutls_errors.c:235
+#: lib/gnutls_errors.c:253
 msgid "The PKCS structure's content type is unknown."
 msgstr "Il tipo di contenuto della struttura PKCS è sconosciuto."
 
-#: gnutls_errors.c:237
+#: lib/gnutls_errors.c:255
 msgid "The PKCS structure's bag type is unknown."
 msgstr "Il tipo di contenitore della struttura PKCS è sconosciuto."
 
-#: gnutls_errors.c:239
+#: lib/gnutls_errors.c:257
 msgid "The given password contains invalid characters."
 msgstr "La password fornita contiene caratteri non validi."
 
-#: gnutls_errors.c:241
+#: lib/gnutls_errors.c:259
 msgid "The Message Authentication Code verification failed."
 msgstr "La verifica del codice di autenticazione dei messaggi (MAC) non è 
riuscita."
 
-#: gnutls_errors.c:243
+#: lib/gnutls_errors.c:261
 msgid "Some constraint limits were reached."
 msgstr "Sono stati raggiunti alcuni valori limite sui vincoli."
 
-#: gnutls_errors.c:245
+#: lib/gnutls_errors.c:263
 msgid "Failed to acquire random data."
 msgstr "Acquisizione di dati casuali non riuscita."
 
-#: gnutls_errors.c:248
+#: lib/gnutls_errors.c:266
 msgid "Received a TLS/IA Intermediate Phase Finished message"
 msgstr "Ricevuto un messaggio di fine della fase intermedia TLS/IA"
 
-#: gnutls_errors.c:250
+#: lib/gnutls_errors.c:268
 msgid "Received a TLS/IA Final Phase Finished message"
 msgstr "Ricevuto un messaggio di fine della fase finale TLS/IA"
 
-#: gnutls_errors.c:252
+#: lib/gnutls_errors.c:270
 msgid "Verifying TLS/IA phase checksum failed"
 msgstr "Verifica del codice di controllo nella fase TLS/IA non riuscita"
 
-#: gnutls_errors.c:255
+#: lib/gnutls_errors.c:273
 msgid "The specified algorithm or protocol is unknown."
 msgstr "L'algoritmo o il protocollo specificato è sconosciuto."
 
-#: gnutls_errors.c:258
-msgid "The handshake data size is too large (DoS?), check 
gnutls_handshake_set_max_packet_length()."
-msgstr "La dimensione dei dati di handshake è troppo grande (DoS?), 
controllare gnutls_handshake_set_max_packet_length()."
+#: lib/gnutls_errors.c:276
+msgid "The handshake data size is too large."
+msgstr "La dimensione dei dati di handshake è troppo grande."
+
+#: lib/gnutls_errors.c:279
+msgid "Error opening /dev/crypto"
+msgstr "Errore nell'apertura di /dev/crypto"
+
+#: lib/gnutls_errors.c:282
+msgid "Error interfacing with /dev/crypto"
+msgstr "Errore nell'interfacciamento con /dev/crypto"
+
+#: lib/gnutls_errors.c:285
+msgid "Channel binding data not available"
+msgstr "Dati dell'associazione di canale non disponibili"
+
+#: lib/gnutls_errors.c:288
+msgid "PKCS #11 error."
+msgstr "Errore PKCS #11."
+
+#: lib/gnutls_errors.c:290
+msgid "PKCS #11 initialization error."
+msgstr "Errore PKCS #11 di inizializzazione."
+
+#: lib/gnutls_errors.c:292
+msgid "Error in parsing."
+msgstr "Errore nell'analisi."
+
+#: lib/gnutls_errors.c:294
+msgid "PKCS #11 error in PIN."
+msgstr "Errore nel PIN PKCS #11."
+
+#: lib/gnutls_errors.c:296
+msgid "PKCS #11 PIN should be saved."
+msgstr "Il PIN PKCS #11 dovrebbe essere salvato."
+
+#: lib/gnutls_errors.c:298
+msgid "PKCS #11 error in slot"
+msgstr "Errore PKCS #11 nello slot"
+
+#: lib/gnutls_errors.c:300
+msgid "Thread locking error"
+msgstr "Errore nel blocco del thread"
+
+#: lib/gnutls_errors.c:302
+msgid "PKCS #11 error in attribute"
+msgstr "Errore PKCS #11 nell'attributo"
+
+#: lib/gnutls_errors.c:304
+msgid "PKCS #11 error in device"
+msgstr "Errore PKCS #11 nel dispositivo"
+
+#: lib/gnutls_errors.c:306
+msgid "PKCS #11 error in data"
+msgstr "Errore PKCS #11 nei dati"
+
+#: lib/gnutls_errors.c:308
+msgid "PKCS #11 unsupported feature"
+msgstr "Funzionalità PKCS #11 non supportata"
+
+#: lib/gnutls_errors.c:310
+msgid "PKCS #11 error in key"
+msgstr "Errore PKCS #11 nella chiave"
+
+#: lib/gnutls_errors.c:312
+msgid "PKCS #11 PIN expired"
+msgstr "PIN PKCS #11 scaduto"
 
-#: gnutls_errors.c:347
+#: lib/gnutls_errors.c:314
+msgid "PKCS #11 PIN locked"
+msgstr "PIN PKCS #11 bloccato"
+
+#: lib/gnutls_errors.c:316
+msgid "PKCS #11 error in session"
+msgstr "Errore PKCS #11 nella sessione"
+
+#: lib/gnutls_errors.c:318
+msgid "PKCS #11 error in signature"
+msgstr "Errore PKCS #11 nella firma"
+
+#: lib/gnutls_errors.c:320
+msgid "PKCS #11 error in token"
+msgstr "Errore PKCS #11 nel token"
+
+#: lib/gnutls_errors.c:322
+msgid "PKCS #11 user error"
+msgstr "Errore PKCS #11 dell'utente"
+
+#: lib/gnutls_errors.c:324
+msgid "The operation timed out"
+msgstr "L'operazione è scaduta"
+
+#: lib/gnutls_errors.c:326
+msgid "The operation was cancelled due to user error"
+msgstr "L'operazione è stata annullata a causa di un errore utente"
+
+#: lib/gnutls_errors.c:328
+msgid "No supported ECC curves were found"
+msgstr "Non è stata trovata alcuna curva ECC supportata"
+
+#: lib/gnutls_errors.c:330
+msgid "The curve is unsupported"
+msgstr "La curva non è supportata."
+
+#: lib/gnutls_errors.c:332
+msgid "The requested PKCS #11 object is not available"
+msgstr "L'oggetto PKCS #11 richiesto non è disponibile"
+
+#: lib/gnutls_errors.c:419
 msgid "(unknown error code)"
 msgstr "(codice di errore sconosciuto)"
 
-#: gnutls_alert.c:42
+#: lib/gnutls_alert.c:45
 msgid "Close notify"
 msgstr "Notifica di chiusura"
 
-#: gnutls_alert.c:43
+#: lib/gnutls_alert.c:46
 msgid "Unexpected message"
 msgstr "Messaggio inatteso"
 
-#: gnutls_alert.c:44
+#: lib/gnutls_alert.c:47
 msgid "Bad record MAC"
 msgstr "Record con MAC errato"
 
-#: gnutls_alert.c:45
+#: lib/gnutls_alert.c:48
 msgid "Decryption failed"
 msgstr "Decifrazione non riuscita"
 
-#: gnutls_alert.c:46
+#: lib/gnutls_alert.c:49
 msgid "Record overflow"
 msgstr "Overflow del record"
 
-#: gnutls_alert.c:47
+#: lib/gnutls_alert.c:50
 msgid "Decompression failed"
 msgstr "Decompressione non riuscita"
 
-#: gnutls_alert.c:48
+#: lib/gnutls_alert.c:51
 msgid "Handshake failed"
 msgstr "Handshake non riuscito"
 
-#: gnutls_alert.c:49
+#: lib/gnutls_alert.c:52
 msgid "Certificate is bad"
 msgstr "Il certificato non è valido"
 
-#: gnutls_alert.c:50
+#: lib/gnutls_alert.c:53
 msgid "Certificate is not supported"
 msgstr "Il certificato non è supportato"
 
-#: gnutls_alert.c:51
+#: lib/gnutls_alert.c:54
 msgid "Certificate was revoked"
 msgstr "Il certificato è stato revocato"
 
-#: gnutls_alert.c:52
+#: lib/gnutls_alert.c:55
 msgid "Certificate is expired"
 msgstr "Il certificato è scaduto"
 
-#: gnutls_alert.c:53
+#: lib/gnutls_alert.c:56
 msgid "Unknown certificate"
 msgstr "Certificato sconosciuto"
 
-#: gnutls_alert.c:54
+#: lib/gnutls_alert.c:57
 msgid "Illegal parameter"
 msgstr "Parametro non lecito"
 
-#: gnutls_alert.c:55
+#: lib/gnutls_alert.c:58
 msgid "CA is unknown"
 msgstr "La CA è sconosciuta"
 
-#: gnutls_alert.c:56
+#: lib/gnutls_alert.c:59
 msgid "Access was denied"
 msgstr "L'accesso è stato negato"
 
-#: gnutls_alert.c:57
+#: lib/gnutls_alert.c:60
 msgid "Decode error"
 msgstr "Errore di decodifica"
 
-#: gnutls_alert.c:58
+#: lib/gnutls_alert.c:61
 msgid "Decrypt error"
 msgstr "Errore di decifrazione"
 
-#: gnutls_alert.c:59
+#: lib/gnutls_alert.c:62
 msgid "Export restriction"
 msgstr "Limite all'esportazione"
 
-#: gnutls_alert.c:60
+#: lib/gnutls_alert.c:63
 msgid "Error in protocol version"
 msgstr "Errore nella versione del protocollo"
 
-#: gnutls_alert.c:61
+#: lib/gnutls_alert.c:64
 msgid "Insufficient security"
 msgstr "Sicurezza insufficiente"
 
-#: gnutls_alert.c:62
+#: lib/gnutls_alert.c:65
 msgid "User canceled"
 msgstr "Annullato dall'utente"
 
-#: gnutls_alert.c:63
+#: lib/gnutls_alert.c:66
+msgid "No certificate (SSL 3.0)"
+msgstr "No certificate (SSL 3.0)"
+
+#: lib/gnutls_alert.c:67
 msgid "Internal error"
 msgstr "Errore interno"
 
-#: gnutls_alert.c:64
+#: lib/gnutls_alert.c:68
 msgid "No renegotiation is allowed"
 msgstr "Non è permessa alcuna rinegoziazione"
 
-#: gnutls_alert.c:66
+#: lib/gnutls_alert.c:70
 msgid "Could not retrieve the specified certificate"
 msgstr "Impossibile recuperare il certificato specificato"
 
-#: gnutls_alert.c:67
+#: lib/gnutls_alert.c:71
 msgid "An unsupported extension was sent"
 msgstr "È stata inviata una estensione non supportata"
 
-#: gnutls_alert.c:69
+#: lib/gnutls_alert.c:73
 msgid "The server name sent was not recognized"
 msgstr "Il nome server inviato non è stato riconosciuto"
 
-#: gnutls_alert.c:71
+#: lib/gnutls_alert.c:75
 msgid "The SRP/PSK username is missing or not known"
 msgstr "Il nome utente SRP/PSK è mancante o sconosciuto"
 
-#: gnutls_alert.c:73
-msgid "Inner application negotiation failed"
-msgstr "Negoziazione dell'applicazione interna non riuscita"
-
-#: gnutls_alert.c:75
-msgid "Inner application verification failed"
-msgstr "Verifica dell'applicazione interna non riuscita"
-
-#: x509/output.c:156
+#: lib/x509/output.c:155
 #, c-format
 msgid "\t\t\tPath Length Constraint: %d\n"
 msgstr "\t\t\tVincolo sulla lunghezza del percorso: %d\n"
 
-#: x509/output.c:157
+#: lib/x509/output.c:156
 #, c-format
 msgid "\t\t\tPolicy Language: %s"
 msgstr "\t\t\tLingua della politica: %s"
 
-#: x509/output.c:166
+#: lib/x509/output.c:165
 msgid ""
 "\t\t\tPolicy:\n"
 "\t\t\t\tASCII: "
@@ -556,7 +695,7 @@ msgstr ""
 "\t\t\tPolitica:\n"
 "\t\t\t\tASCII: "
 
-#: x509/output.c:168
+#: lib/x509/output.c:167
 msgid ""
 "\n"
 "\t\t\t\tHexdump: "
@@ -564,125 +703,130 @@ msgstr ""
 "\n"
 "\t\t\t\tDump esadecimale: "
 
-#: x509/output.c:295
+#: lib/x509/output.c:300
 #, c-format
 msgid "%s\t\t\tDigital signature.\n"
 msgstr "%s\t\t\tFirma digitale.\n"
 
-#: x509/output.c:297
+#: lib/x509/output.c:302
 #, c-format
 msgid "%s\t\t\tNon repudiation.\n"
 msgstr "%s\t\t\tNon ripudio.\n"
 
-#: x509/output.c:299
+#: lib/x509/output.c:304
 #, c-format
 msgid "%s\t\t\tKey encipherment.\n"
 msgstr "%s\t\t\tCifratura della chiave.\n"
 
-#: x509/output.c:301
+#: lib/x509/output.c:306
 #, c-format
 msgid "%s\t\t\tData encipherment.\n"
 msgstr "%s\t\t\tCifratura dei dati.\n"
 
-#: x509/output.c:303
+#: lib/x509/output.c:308
 #, c-format
 msgid "%s\t\t\tKey agreement.\n"
 msgstr "%s\t\t\tAccordo sulla chiave.\n"
 
-#: x509/output.c:305
+#: lib/x509/output.c:310
 #, c-format
 msgid "%s\t\t\tCertificate signing.\n"
 msgstr "%s\t\t\tFirma del certificato.\n"
 
-#: x509/output.c:307
+#: lib/x509/output.c:312
 #, c-format
 msgid "%s\t\t\tCRL signing.\n"
 msgstr "%s\t\t\tFirma della CRL.\n"
 
-#: x509/output.c:309
+#: lib/x509/output.c:314
 #, c-format
 msgid "%s\t\t\tKey encipher only.\n"
 msgstr "%s\t\t\tSolo cifratura della chiave.\n"
 
-#: x509/output.c:311
+#: lib/x509/output.c:316
 #, c-format
 msgid "%s\t\t\tKey decipher only.\n"
 msgstr "%s\t\t\tSolo decifratura della chiave.\n"
 
-#: x509/output.c:362
+#: lib/x509/output.c:367
 msgid "warning: distributionPoint contains an embedded NUL, replacing with 
'!'\n"
-msgstr "attenzione: distributionPoint contiene un NUL incorporato, 
sostituzione con \"!\"\n"
+msgstr "attenzione: distributionPoint contiene un NUL incorporato, viene 
sostituito con \"!\"\n"
 
-#: x509/output.c:454
+#: lib/x509/output.c:460
 #, c-format
 msgid "%s\t\t\tTLS WWW Server.\n"
 msgstr "%s\t\t\tServer WWW TLS.\n"
 
-#: x509/output.c:456
+#: lib/x509/output.c:462
 #, c-format
 msgid "%s\t\t\tTLS WWW Client.\n"
 msgstr "%s\t\t\tClient WWW TLS.\n"
 
-#: x509/output.c:458
+#: lib/x509/output.c:464
 #, c-format
 msgid "%s\t\t\tCode signing.\n"
 msgstr "%s\t\t\tFirma del codice.\n"
 
-#: x509/output.c:460
+#: lib/x509/output.c:466
 #, c-format
 msgid "%s\t\t\tEmail protection.\n"
 msgstr "%s\t\t\tProtezione email.\n"
 
-#: x509/output.c:462
+#: lib/x509/output.c:468
 #, c-format
 msgid "%s\t\t\tTime stamping.\n"
 msgstr "%s\t\t\tMarcatura temporale.\n"
 
-#: x509/output.c:464
+#: lib/x509/output.c:470
 #, c-format
 msgid "%s\t\t\tOCSP signing.\n"
 msgstr "%s\t\t\tFirma OCSP.\n"
 
-#: x509/output.c:466
+#: lib/x509/output.c:472
+#, c-format
+msgid "%s\t\t\tIpsec IKE.\n"
+msgstr "%s\t\t\tIKE ipsec.\n"
+
+#: lib/x509/output.c:474
 #, c-format
 msgid "%s\t\t\tAny purpose.\n"
 msgstr "%s\t\t\tQualsiasi scopo.\n"
 
-#: x509/output.c:499
+#: lib/x509/output.c:507
 #, c-format
 msgid "%s\t\t\tCertificate Authority (CA): FALSE\n"
 msgstr "%s\t\t\tAutorità di certificazione (CA): FALSO\n"
 
-#: x509/output.c:501
+#: lib/x509/output.c:509
 #, c-format
 msgid "%s\t\t\tCertificate Authority (CA): TRUE\n"
 msgstr "%s\t\t\tAutorità di certificazione (CA): VERO\n"
 
-#: x509/output.c:504
+#: lib/x509/output.c:512
 #, c-format
 msgid "%s\t\t\tPath Length Constraint: %d\n"
 msgstr "%s\t\t\tVincolo sulla lunghezza del percorso: %d\n"
 
-#: x509/output.c:571 x509/output.c:651
-msgid "warning: SAN contains an embedded NUL, replacing with '!'\n"
-msgstr "attenzione: SAN contiene un NUL incorporato, sostituzione con \"!\"\n"
+#: lib/x509/output.c:586 lib/x509/output.c:676
+msgid "warning: altname contains an embedded NUL, replacing with '!'\n"
+msgstr "attenzione: altname contiene un NUL incorporato, viene sostituito con 
\"!\"\n"
 
-#: x509/output.c:657
+#: lib/x509/output.c:682
 #, c-format
 msgid "%s\t\t\tXMPP Address: %.*s\n"
 msgstr "%s\t\t\tIndirizzo XMPP: %.*s\n"
 
-#: x509/output.c:662
+#: lib/x509/output.c:687
 #, c-format
 msgid "%s\t\t\totherName OID: %.*s\n"
 msgstr "%s\t\t\tOID di otherName: %.*s\n"
 
-#: x509/output.c:664
+#: lib/x509/output.c:689
 #, c-format
 msgid "%s\t\t\totherName DER: "
 msgstr "%s\t\t\tDER di otherName: "
 
-#: x509/output.c:666
+#: lib/x509/output.c:691
 #, c-format
 msgid ""
 "\n"
@@ -691,163 +835,190 @@ msgstr ""
 "\n"
 "%s\t\t\tASCII di otherName: "
 
-#: x509/output.c:728
+#: lib/x509/output.c:815
 #, c-format
 msgid "%s\tExtensions:\n"
 msgstr "%s\tEstensioni:\n"
 
-#: x509/output.c:738
+#: lib/x509/output.c:825
 #, c-format
 msgid "%s\t\tBasic Constraints (%s):\n"
 msgstr "%s\t\tVincoli di base (%s):\n"
 
-#: x509/output.c:739 x509/output.c:754 x509/output.c:771 x509/output.c:787
-#: x509/output.c:802 x509/output.c:819 x509/output.c:834 x509/output.c:852
-#: x509/output.c:865 x509/output.c:1514 x509/output.c:1537 x509/output.c:1550
+#: lib/x509/output.c:826 lib/x509/output.c:841 lib/x509/output.c:858
+#: lib/x509/output.c:874 lib/x509/output.c:889 lib/x509/output.c:906
+#: lib/x509/output.c:921 lib/x509/output.c:936 lib/x509/output.c:954
+#: lib/x509/output.c:967 lib/x509/output.c:1735 lib/x509/output.c:1758
+#: lib/x509/output.c:1771
 msgid "critical"
 msgstr "critico"
 
-#: x509/output.c:739 x509/output.c:754 x509/output.c:771 x509/output.c:787
-#: x509/output.c:802 x509/output.c:819 x509/output.c:834 x509/output.c:852
-#: x509/output.c:865 x509/output.c:1514 x509/output.c:1537 x509/output.c:1550
+#: lib/x509/output.c:826 lib/x509/output.c:841 lib/x509/output.c:858
+#: lib/x509/output.c:874 lib/x509/output.c:889 lib/x509/output.c:906
+#: lib/x509/output.c:921 lib/x509/output.c:936 lib/x509/output.c:954
+#: lib/x509/output.c:967 lib/x509/output.c:1735 lib/x509/output.c:1758
+#: lib/x509/output.c:1771
 msgid "not critical"
 msgstr "non critico"
 
-#: x509/output.c:753
+#: lib/x509/output.c:840
 #, c-format
 msgid "%s\t\tSubject Key Identifier (%s):\n"
 msgstr "%s\t\tIdentificativo di chiave del soggetto (SKI) (%s):\n"
 
-#: x509/output.c:770
+#: lib/x509/output.c:857
 #, c-format
 msgid "%s\t\tAuthority Key Identifier (%s):\n"
 msgstr "%s\t\tIdentificativo di chiave dell'autorità (AKI) (%s):\n"
 
-#: x509/output.c:786
+#: lib/x509/output.c:873
 #, c-format
 msgid "%s\t\tKey Usage (%s):\n"
 msgstr "%s\t\tUso della chiave (%s):\n"
 
-#: x509/output.c:801
+#: lib/x509/output.c:888
 #, c-format
 msgid "%s\t\tKey Purpose (%s):\n"
 msgstr "%s\t\tScopo della chiave (%s):\n"
 
-#: x509/output.c:818
+#: lib/x509/output.c:905
 #, c-format
 msgid "%s\t\tSubject Alternative Name (%s):\n"
 msgstr "%s\t\tNome alternativo del soggetto (SAN) (%s):\n"
 
-#: x509/output.c:833
+#: lib/x509/output.c:920
+#, c-format
+msgid "%s\t\tIssuer Alternative Name (%s):\n"
+msgstr "%s\t\tNome alternativo dell'emittente (%s):\n"
+
+#: lib/x509/output.c:935
 #, c-format
 msgid "%s\t\tCRL Distribution points (%s):\n"
 msgstr "%s\t\tPunti di distribuzione CRL (%s):\n"
 
-#: x509/output.c:851
+#: lib/x509/output.c:953
 #, c-format
 msgid "%s\t\tProxy Certificate Information (%s):\n"
 msgstr "%s\t\tInformazioni sul certificato proxy (PC) (%s):\n"
 
-#: x509/output.c:864
+#: lib/x509/output.c:966
 #, c-format
 msgid "%s\t\tUnknown extension %s (%s):\n"
 msgstr "%s\t\tEstensione sconosciuta %s (%s):\n"
 
-#: x509/output.c:910
+#: lib/x509/output.c:1013
 #, c-format
 msgid "%s\t\t\tASCII: "
 msgstr "%s\t\t\tASCII: "
 
-#: x509/output.c:914
+#: lib/x509/output.c:1017
 #, c-format
 msgid "%s\t\t\tHexdump: "
 msgstr "%s\t\t\tDump esadecimale: "
 
-#: x509/output.c:932 x509/output.c:1417 x509/output.c:1730
-#: openpgp/output.c:323
+#: lib/x509/output.c:1035 lib/x509/output.c:1623 lib/x509/output.c:1953
+#: lib/openpgp/output.c:324
 #, c-format
 msgid "\tVersion: %d\n"
 msgstr "\tVersione: %d\n"
 
-#: x509/output.c:946
+#: lib/x509/output.c:1049
 msgid "\tSerial Number (hex): "
 msgstr "\tNumero seriale (hex): "
 
-#: x509/output.c:963 x509/output.c:1431
+#: lib/x509/output.c:1078 lib/x509/output.c:1649
 #, c-format
 msgid "\tIssuer: %s\n"
 msgstr "\tEmittente: %s\n"
 
-#: x509/output.c:970
+#: lib/x509/output.c:1088
 msgid "\tValidity:\n"
 msgstr "\tValidità:\n"
 
-#: x509/output.c:983
+#: lib/x509/output.c:1101
 #, c-format
 msgid "\t\tNot Before: %s\n"
 msgstr "\t\tNon prima: %s\n"
 
-#: x509/output.c:997
+#: lib/x509/output.c:1115
 #, c-format
 msgid "\t\tNot After: %s\n"
 msgstr "\t\tNon dopo: %s\n"
 
-#: x509/output.c:1011 x509/output.c:1743
+#: lib/x509/output.c:1140 lib/x509/output.c:1977
 #, c-format
 msgid "\tSubject: %s\n"
 msgstr "\tSoggetto: %s\n"
 
-#: x509/output.c:1026 x509/output.c:1113 x509/output.c:1256 x509/output.c:1648
-#: x509/output.c:1758 openpgp/output.c:237
+#: lib/x509/output.c:1159 lib/x509/output.c:1292 lib/x509/output.c:1462
+#: lib/x509/output.c:1870 lib/x509/output.c:1995 lib/openpgp/output.c:236
 msgid "unknown"
 msgstr "sconosciuto"
 
-#: x509/output.c:1028 x509/output.c:1760
+#: lib/x509/output.c:1163 lib/x509/output.c:1997
 #, c-format
 msgid "\tSubject Public Key Algorithm: %s\n"
 msgstr "\tAlgoritmo a chiave pubblica del soggetto (SPK): %s\n"
 
-#: x509/output.c:1042 x509/output.c:1773 openpgp/output.c:257
+#: lib/x509/output.c:1164
+#, c-format
+msgid "\tCertificate Security Level: %s (%d bits)\n"
+msgstr "\tLivello di sicurezza del certificato: %s (%d bit)\n"
+
+#: lib/x509/output.c:1194 lib/x509/output.c:2010 lib/openpgp/output.c:260
 #, c-format
 msgid "\t\tModulus (bits %d):\n"
 msgstr "\t\tModulo (bit %d):\n"
 
-#: x509/output.c:1044
+#: lib/x509/output.c:1196
 #, c-format
 msgid "\t\tExponent (bits %d):\n"
 msgstr "\t\tEsponente (bit %d):\n"
 
-#: x509/output.c:1064 x509/output.c:1795 openpgp/output.c:284
+#: lib/x509/output.c:1217
+#, c-format
+msgid "\t\tCurve:\t%s\n"
+msgstr "\t\tCurva:\t%s\n"
+
+#: lib/x509/output.c:1218
+msgid "\t\tX:\n"
+msgstr "\t\tX:\n"
+
+#: lib/x509/output.c:1220
+msgid "\t\tY:\n"
+msgstr "\t\tY:\n"
+
+#: lib/x509/output.c:1239 lib/x509/output.c:2032 lib/openpgp/output.c:287
 #, c-format
 msgid "\t\tPublic key (bits %d):\n"
 msgstr "\t\tChiave pubblica (bit %d):\n"
 
-#: x509/output.c:1066 x509/output.c:1797 openpgp/output.c:286
+#: lib/x509/output.c:1241 lib/x509/output.c:2034 lib/openpgp/output.c:289
 msgid "\t\tP:\n"
 msgstr "\t\tP:\n"
 
-#: x509/output.c:1068 x509/output.c:1799 openpgp/output.c:288
+#: lib/x509/output.c:1243 lib/x509/output.c:2036 lib/openpgp/output.c:291
 msgid "\t\tQ:\n"
 msgstr "\t\tQ:\n"
 
-#: x509/output.c:1070 x509/output.c:1801 openpgp/output.c:290
+#: lib/x509/output.c:1245 lib/x509/output.c:2038 lib/openpgp/output.c:293
 msgid "\t\tG:\n"
 msgstr "\t\tG:\n"
 
-#: x509/output.c:1114 x509/output.c:1649
+#: lib/x509/output.c:1293 lib/x509/output.c:1871
 #, c-format
 msgid "\tSignature Algorithm: %s\n"
 msgstr "\tAlgoritmo di firma: %s\n"
 
-#: x509/output.c:1118 x509/output.c:1653
+#: lib/x509/output.c:1297 lib/x509/output.c:1875
 msgid "warning: signed using a broken signature algorithm that can be 
forged.\n"
 msgstr "attenzione: è stato firmato usando un algoritmo di firma difettoso 
che può essere contraffatto.\n"
 
-#: x509/output.c:1144 x509/output.c:1679
+#: lib/x509/output.c:1324 lib/x509/output.c:1902
 msgid "\tSignature:\n"
 msgstr "\tFirma:\n"
 
-#: x509/output.c:1167
+#: lib/x509/output.c:1347
 msgid ""
 "\tMD5 fingerprint:\n"
 "\t\t"
@@ -855,7 +1026,7 @@ msgstr ""
 "\tImpronta digitale MD5:\n"
 "\t\t"
 
-#: x509/output.c:1169
+#: lib/x509/output.c:1349
 msgid ""
 "\tSHA-1 fingerprint:\n"
 "\t\t"
@@ -863,7 +1034,7 @@ msgstr ""
 "\tImpronta digitale SHA-1:\n"
 "\t\t"
 
-#: x509/output.c:1188 x509/output.c:1956
+#: lib/x509/output.c:1368 lib/x509/output.c:2214
 msgid ""
 "\tPublic Key Id:\n"
 "\t\t"
@@ -871,192 +1042,197 @@ msgstr ""
 "\tId della chiave pubblica:\n"
 "\t\t"
 
-#: x509/output.c:1258
+#: lib/x509/output.c:1464
 #, c-format
 msgid "signed using %s (broken!), "
 msgstr "firmato usando %s (difettoso), "
 
-#: x509/output.c:1260
+#: lib/x509/output.c:1466
 #, c-format
 msgid "signed using %s, "
 msgstr "firmato usando %s, "
 
-#: x509/output.c:1373
+#: lib/x509/output.c:1579
 msgid "X.509 Certificate Information:\n"
 msgstr "Informazioni sul certificato X.509:\n"
 
-#: x509/output.c:1377 x509/output.c:1993
+#: lib/x509/output.c:1583 lib/x509/output.c:2251
 msgid "Other Information:\n"
 msgstr "Altre informazioni:\n"
 
-#: x509/output.c:1413
+#: lib/x509/output.c:1619
 msgid "\tVersion: 1 (default)\n"
 msgstr "\tVersione: 1 (predefinita)\n"
 
-#: x509/output.c:1438
+#: lib/x509/output.c:1659
 msgid "\tUpdate dates:\n"
 msgstr "\tDate di aggiornamento:\n"
 
-#: x509/output.c:1451
+#: lib/x509/output.c:1672
 #, c-format
 msgid "\t\tIssued: %s\n"
 msgstr "\t\tRilasciato il: %s\n"
 
-#: x509/output.c:1467
+#: lib/x509/output.c:1688
 #, c-format
 msgid "\t\tNext at: %s\n"
 msgstr "\t\tProssimo il: %s\n"
 
-#: x509/output.c:1498
+#: lib/x509/output.c:1719
 msgid "\tExtensions:\n"
 msgstr "\tEstensioni:\n"
 
-#: x509/output.c:1513
+#: lib/x509/output.c:1734
 #, c-format
 msgid "\t\tCRL Number (%s): "
 msgstr "\t\tNumero CRL (%s): "
 
-#: x509/output.c:1536
+#: lib/x509/output.c:1757
 #, c-format
 msgid "\t\tAuthority Key Identifier (%s):\n"
 msgstr "\t\tIdentificativo di chiave dell'autorità (AKI) (%s):\n"
 
-#: x509/output.c:1549
+#: lib/x509/output.c:1770
 #, c-format
 msgid "\t\tUnknown extension %s (%s):\n"
 msgstr "\t\tEstensione sconosciuta %s (%s):\n"
 
-#: x509/output.c:1578 x509/output.c:1913
+#: lib/x509/output.c:1800 lib/x509/output.c:2170
 msgid "\t\t\tASCII: "
 msgstr "\t\t\tASCII: "
 
-#: x509/output.c:1582 x509/output.c:1917
+#: lib/x509/output.c:1804 lib/x509/output.c:2174
 msgid "\t\t\tHexdump: "
 msgstr "\t\t\tDump esadecimale: "
 
-#: x509/output.c:1598
+#: lib/x509/output.c:1820
 #, c-format
 msgid "\tRevoked certificates (%d):\n"
 msgstr "\tCertificati revocati (%d):\n"
 
-#: x509/output.c:1600
+#: lib/x509/output.c:1822
 msgid "\tNo revoked certificates.\n"
 msgstr "\tNessun certificato revocato.\n"
 
-#: x509/output.c:1619
+#: lib/x509/output.c:1841
 msgid "\t\tSerial Number (hex): "
 msgstr "\t\tNumero seriale (hex): "
 
-#: x509/output.c:1628
+#: lib/x509/output.c:1850
 #, c-format
 msgid "\t\tRevoked at: %s\n"
-msgstr "\t\tRevocato a: %s\n"
+msgstr "\t\tRevocato: %s\n"
 
-#: x509/output.c:1710
+#: lib/x509/output.c:1933
 msgid "X.509 Certificate Revocation List Information:\n"
 msgstr "Informazioni sull'elenco di revoca del certificato (CRL) X.509:\n"
 
-#: x509/output.c:1775 openpgp/output.c:259
+#: lib/x509/output.c:2012 lib/openpgp/output.c:262
 msgid "\t\tExponent:\n"
 msgstr "\t\tEsponente:\n"
 
-#: x509/output.c:1842
+#: lib/x509/output.c:2079
 msgid "\tAttributes:\n"
 msgstr "\tAttributi:\n"
 
-#: x509/output.c:1877
+#: lib/x509/output.c:2131
 #, c-format
 msgid "\t\tChallenge password: %s\n"
 msgstr "\t\tChallenge password: %s\n"
 
-#: x509/output.c:1886
+#: lib/x509/output.c:2142
 #, c-format
 msgid "\t\tUnknown attribute %s:\n"
 msgstr "\t\tAttributo sconosciuto %s:\n"
 
-#: x509/output.c:1989
+#: lib/x509/output.c:2247
 msgid "PKCS #10 Certificate Request Information:\n"
 msgstr "Informazioni sulla richiesta di certificato (CR) PKCS #10:\n"
 
-#: openpgp/output.c:84
+#: lib/openpgp/output.c:83
 msgid "\t\tKey Usage:\n"
 msgstr "\t\tUso della chiave:\n"
 
-#: openpgp/output.c:93
+#: lib/openpgp/output.c:92
 #, c-format
 msgid "error: get_key_usage: %s\n"
 msgstr "errore: get_key_usage: %s\n"
 
-#: openpgp/output.c:98
+#: lib/openpgp/output.c:97
 msgid "\t\t\tDigital signatures.\n"
 msgstr "\t\t\tFirma digitale.\n"
 
-#: openpgp/output.c:100
+#: lib/openpgp/output.c:99
 msgid "\t\t\tCommunications encipherment.\n"
 msgstr "\t\t\tCifratura delle comunicazioni.\n"
 
-#: openpgp/output.c:102
+#: lib/openpgp/output.c:101
 msgid "\t\t\tStorage data encipherment.\n"
 msgstr "\t\t\tCifratura dei dati di memorizzazione.\n"
 
-#: openpgp/output.c:104
+#: lib/openpgp/output.c:103
 msgid "\t\t\tAuthentication.\n"
 msgstr "\t\t\tAutenticazione.\n"
 
-#: openpgp/output.c:106
+#: lib/openpgp/output.c:105
 msgid "\t\t\tCertificate signing.\n"
 msgstr "\t\t\tFirma del certificato.\n"
 
-#: openpgp/output.c:127
+#: lib/openpgp/output.c:126
 msgid "\tID (hex): "
 msgstr "\tID (hex): "
 
-#: openpgp/output.c:148
+#: lib/openpgp/output.c:147
 msgid "\tFingerprint (hex): "
 msgstr "\tImpronta digitale (hex): "
 
-#: openpgp/output.c:165
+#: lib/openpgp/output.c:164
 msgid "\tRevoked: True\n"
 msgstr "\tRevocato: vero\n"
 
-#: openpgp/output.c:167
+#: lib/openpgp/output.c:166
 msgid "\tRevoked: False\n"
 msgstr "\tRevocato: falso\n"
 
-#: openpgp/output.c:175
+#: lib/openpgp/output.c:174
 msgid "\tTime stamps:\n"
 msgstr "\tMarche temporali:\n"
 
-#: openpgp/output.c:192
+#: lib/openpgp/output.c:191
 #, c-format
 msgid "\t\tCreation: %s\n"
 msgstr "\t\tCreazione: %s\n"
 
-#: openpgp/output.c:206
+#: lib/openpgp/output.c:205
 msgid "\t\tExpiration: Never\n"
 msgstr "\t\tScadenza: mai\n"
 
-#: openpgp/output.c:215
+#: lib/openpgp/output.c:214
 #, c-format
 msgid "\t\tExpiration: %s\n"
 msgstr "\t\tScadenza: %s\n"
 
-#: openpgp/output.c:239
+#: lib/openpgp/output.c:238
 #, c-format
 msgid "\tPublic Key Algorithm: %s\n"
 msgstr "\tAlgoritmo di chiave pubblica: %s\n"
 
-#: openpgp/output.c:346
+#: lib/openpgp/output.c:239
+#, c-format
+msgid "\tKey Security Level: %s\n"
+msgstr "\tLivello di sicurezza della chiave: %s\n"
+
+#: lib/openpgp/output.c:357
 #, c-format
 msgid "\tName[%d]: %s\n"
 msgstr "\tNome[%d]: %s\n"
 
-#: openpgp/output.c:349
+#: lib/openpgp/output.c:359
 #, c-format
 msgid "\tRevoked Name[%d]: %s\n"
 msgstr "\tNome revocato[%d]: %s\n"
 
-#: openpgp/output.c:366
+#: lib/openpgp/output.c:380
 #, c-format
 msgid ""
 "\n"
@@ -1065,44 +1241,44 @@ msgstr ""
 "\n"
 "\tSottochiave[%d]:\n"
 
-#: openpgp/output.c:399
+#: lib/openpgp/output.c:420
 #, c-format
 msgid "name[%d]: %s, "
 msgstr "nome[%d]: %s, "
 
-#: openpgp/output.c:401
+#: lib/openpgp/output.c:422
 #, c-format
 msgid "revoked name[%d]: %s, "
 msgstr "nome revocato[%d]: %s, "
 
-#: openpgp/output.c:415
+#: lib/openpgp/output.c:442
 msgid "fingerprint: "
 msgstr "impronta digitale: "
 
-#: openpgp/output.c:435
+#: lib/openpgp/output.c:462
 #, c-format
 msgid "created: %s, "
 msgstr "creata il: %s, "
 
-#: openpgp/output.c:445
+#: lib/openpgp/output.c:472
 msgid "never expires, "
 msgstr "senza scadenza,"
 
-#: openpgp/output.c:453
+#: lib/openpgp/output.c:480
 #, c-format
 msgid "expires: %s, "
 msgstr "scade il: %s, "
 
-#: openpgp/output.c:465
+#: lib/openpgp/output.c:492
 #, c-format
 msgid "key algorithm %s (%d bits)"
 msgstr "algoritmo della chiave %s (%d bit)"
 
-#: openpgp/output.c:467
+#: lib/openpgp/output.c:494
 #, c-format
 msgid "unknown key algorithm (%d)"
 msgstr "algoritmo di chiave sconosciuto (%d)"
 
-#: openpgp/output.c:499
+#: lib/openpgp/output.c:527
 msgid "OpenPGP Certificate Information:\n"
 msgstr "Informazioni sul certificato OpenPGP:\n"
diff --git a/src/Makefile.am b/src/Makefile.am
index 0059710..1aca848 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,9 +27,10 @@ endif
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
 AM_CPPFLAGS = \
        -I$(srcdir)/../gl                       \
+       -I$(builddir)/../gl                     \
        -I$(builddir)/../lib/includes           \
        -I$(srcdir)/../lib/includes             \
-       -I$(srcdir)/../libextra/includes        \
+       -I$(srcdir)/../extra/includes   \
        -I$(srcdir)/cfg
 
 bin_PROGRAMS = gnutls-serv gnutls-cli psktool gnutls-cli-debug
@@ -58,7 +59,7 @@ gnutls_serv_SOURCES =                         \
   common.h common.c                            \
   certtool-common.h \
   $(PKCS11_SRCS)
-gnutls_serv_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la
+gnutls_serv_LDADD = ../lib/libgnutls.la
 gnutls_serv_LDADD += libcmd-serv.la ../gl/libgnu.la
 gnutls_serv_LDADD += $(LTLIBGCRYPT) $(LIBSOCKET) $(GETADDRINFO_LIB)
 noinst_LTLIBRARIES += libcmd-serv.la
@@ -90,7 +91,7 @@ libcmd_psk_la_SOURCES = psk.gaa psk-gaa.h psk-gaa.c
 BENCHMARK_SRCS = benchmark-cipher.c benchmark.c benchmark.h benchmark-tls.c
 
 gnutls_cli_SOURCES = cli.c common.h common.c $(PKCS11_SRCS) $(BENCHMARK_SRCS)
-gnutls_cli_LDADD = ../lib/libgnutls.la ../libextra/libgnutls-extra.la
+gnutls_cli_LDADD = ../lib/libgnutls.la
 gnutls_cli_LDADD += libcmd-cli.la ../gl/libgnu.la
 gnutls_cli_LDADD += $(LTLIBGCRYPT) $(LIBSOCKET) $(GETADDRINFO_LIB) 
$(LIB_CLOCK_GETTIME)
 noinst_LTLIBRARIES += libcmd-cli.la
diff --git a/src/benchmark-cipher.c b/src/benchmark-cipher.c
index d43bc0c..e9b82e8 100644
--- a/src/benchmark-cipher.c
+++ b/src/benchmark-cipher.c
@@ -202,21 +202,23 @@ mac_bench (int algo, int size)
   free (_key);
 }
 
-void benchmark_cipher (int debug_level)
+void benchmark_cipher (int init, int debug_level)
 {
   gnutls_global_set_log_function (tls_log_func);
   gnutls_global_set_log_level (debug_level);
-  gnutls_global_init ();
-
-  gnutls_rnd( GNUTLS_RND_NONCE, data, sizeof(data));
+  if (init)
+    {
+      gnutls_global_init ();
+      gnutls_rnd( GNUTLS_RND_NONCE, data, sizeof(data));
+    }
 
-  cipher_bench ( GNUTLS_CIPHER_AES_128_GCM, 16, 1);
-  cipher_mac_bench ( GNUTLS_CIPHER_AES_128_CBC, GNUTLS_MAC_SHA256, 16);
   cipher_mac_bench ( GNUTLS_CIPHER_AES_128_CBC, GNUTLS_MAC_SHA1, 16);
+  cipher_mac_bench ( GNUTLS_CIPHER_AES_128_CBC, GNUTLS_MAC_SHA256, 16);
+  cipher_bench ( GNUTLS_CIPHER_AES_128_GCM, 16, 1);
 
   mac_bench (GNUTLS_MAC_SHA1, 16);
-
   mac_bench (GNUTLS_MAC_SHA256, 16);
+  mac_bench (GNUTLS_MAC_SHA512, 16);
 
   cipher_bench (GNUTLS_CIPHER_3DES_CBC, 16, 0);
 
diff --git a/src/benchmark.c b/src/benchmark.c
index 134c2a1..42f821c 100644
--- a/src/benchmark.c
+++ b/src/benchmark.c
@@ -1,3 +1,23 @@
+/*
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuTLS.
+ *
+ * GnuTLS is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuTLS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
 #include <stdio.h>
 #include <string.h>
 #include <signal.h>
@@ -63,7 +83,9 @@ value2human (unsigned long bytes, double time, double *data, 
double *speed,
 void start_benchmark(struct benchmark_st * st)
 {
   memset(st, 0, sizeof(*st));
+#ifndef _WIN32
   st->old_handler = signal (SIGALRM, alarm_handler);
+#endif
   gettime (&st->start);
   benchmark_must_finish = 0;
 
@@ -80,13 +102,12 @@ void start_benchmark(struct benchmark_st * st)
       fprintf (stderr, "error: CreateThread %u\n", GetLastError ());
       exit(1);
     }
-  alarm_timeout.QuadPart = (5) * 10000000;
-  if (SetWaitableTimer (st->wtimer, &alarm_timeout, 0, NULL, NULL, FALSE) == 0)
+  st->alarm_timeout.QuadPart = (5) * 10000000;
+  if (SetWaitableTimer (st->wtimer, &st->alarm_timeout, 0, NULL, NULL, FALSE) 
== 0)
     {
       fprintf (stderr, "error: SetWaitableTimer %u\n", GetLastError ());
       exit(1);
     }
-  }
 #else
   alarm (5);
 #endif
@@ -97,6 +118,7 @@ void start_benchmark(struct benchmark_st * st)
 double stop_benchmark(struct benchmark_st * st, const char* metric)
 {
   double secs;
+  unsigned long lsecs;
   struct timespec stop;
   double dspeed, ddata;
   char imetric[16];
@@ -112,8 +134,9 @@ double stop_benchmark(struct benchmark_st * st, const char* 
metric)
 
   gettime (&stop);
 
-  secs = (stop.tv_sec * 1000 + stop.tv_nsec / (1000 * 1000) -
+  lsecs = (stop.tv_sec * 1000 + stop.tv_nsec / (1000 * 1000) -
           (st->start.tv_sec * 1000 + st->start.tv_nsec / (1000 * 1000)));
+  secs = lsecs;
   secs /= 1000;
 
   if (metric == NULL)
diff --git a/src/benchmark.h b/src/benchmark.h
index 1485a03..4f916a8 100644
--- a/src/benchmark.h
+++ b/src/benchmark.h
@@ -1,11 +1,14 @@
 #include <sys/time.h>
 #include <time.h>
 #include <signal.h>
+#if defined(_WIN32)
+# include <windows.h>
+#endif
 #include "timespec.h"           /* gnulib gettime */
 
 typedef void (*sighandler_t)(int);
 
-void benchmark_cipher (int debug_level);
+void benchmark_cipher (int init, int debug_level);
 void benchmark_tls (int debug_level);
 
 struct benchmark_st
diff --git a/src/certtool-cfg.c b/src/certtool-cfg.c
index 69c54be..eda7391 100644
--- a/src/certtool-cfg.c
+++ b/src/certtool-cfg.c
@@ -35,7 +35,12 @@
 
 /* for inet_pton */
 #include <sys/types.h>
-#include <sys/socket.h>
+
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#elif HAVE_WS2TCPIP_H
+# include <ws2tcpip.h>
+#endif
 #include <arpa/inet.h>
 
 /* Gnulib portability files. */
diff --git a/src/certtool-common.c b/src/certtool-common.c
index 5ad9934..9f87ae8 100644
--- a/src/certtool-common.c
+++ b/src/certtool-common.c
@@ -22,7 +22,6 @@
 #include <config.h>
 
 #include <gnutls/gnutls.h>
-#include <gnutls/extra.h>
 #include <gnutls/x509.h>
 #include <gnutls/openpgp.h>
 #include <gnutls/pkcs12.h>
diff --git a/src/certtool.c b/src/certtool.c
index 5362871..824165a 100644
--- a/src/certtool.c
+++ b/src/certtool.c
@@ -2348,7 +2348,7 @@ generate_pkcs12 (common_info_st * cinfo)
   const char *name;
   unsigned int flags, i;
   gnutls_datum_t key_id;
-  unsigned char _key_id[20];
+  unsigned char _key_id[32];
   int indx;
   size_t ncrts;
 
diff --git a/src/cli-gaa.c b/src/cli-gaa.c
index 7c86e2b..8959237 100644
--- a/src/cli-gaa.c
+++ b/src/cli-gaa.c
@@ -158,6 +158,7 @@ void gaa_help(void)
        __gaa_helpsingle('p', "port", "PORT ", "The port to connect to.");
        __gaa_helpsingle(0, "insecure", "", "Don't abort program if server 
certificate can't be validated.");
        __gaa_helpsingle(0, "benchmark-ciphers", "", "Benchmark individual 
ciphers.");
+       __gaa_helpsingle(0, "benchmark-soft-ciphers", "", "Benchmark individual 
software ciphers.");
        __gaa_helpsingle(0, "benchmark-tls", "", "Benchmark ciphers and key 
exchange methods in TLS.");
        __gaa_helpsingle('l', "list", "", "Print a list of the supported 
algorithms and modes.");
        __gaa_helpsingle('h', "help", "", "prints this help");
@@ -176,7 +177,7 @@ typedef struct _gaainfo gaainfo;
 
 struct _gaainfo
 {
-#line 110 "cli.gaa"
+#line 111 "cli.gaa"
        char *rest_args;
 #line 99 "cli.gaa"
        int insecure;
@@ -290,41 +291,42 @@ static int gaa_error = 0;
 #define GAA_MULTIPLE_OPTION     3
 
 #define GAA_REST                0
-#define GAA_NB_OPTION           34
+#define GAA_NB_OPTION           35
 #define GAAOPTID_version       1
 #define GAAOPTID_help  2
 #define GAAOPTID_list  3
 #define GAAOPTID_benchmark_tls 4
-#define GAAOPTID_benchmark_ciphers     5
-#define GAAOPTID_insecure      6
-#define GAAOPTID_port  7
-#define GAAOPTID_pskkey        8
-#define GAAOPTID_pskusername   9
-#define GAAOPTID_srppasswd     10
-#define GAAOPTID_srpusername   11
-#define GAAOPTID_x509certfile  12
-#define GAAOPTID_x509keyfile   13
-#define GAAOPTID_pgpsubkey     14
-#define GAAOPTID_pgpcertfile   15
-#define GAAOPTID_pgpkeyring    16
-#define GAAOPTID_pgpkeyfile    17
-#define GAAOPTID_x509crlfile   18
-#define GAAOPTID_x509cafile    19
-#define GAAOPTID_priority      20
-#define GAAOPTID_verbose       21
-#define GAAOPTID_recordsize    22
-#define GAAOPTID_print_cert    23
-#define GAAOPTID_disable_extensions    24
-#define GAAOPTID_fingerprint   25
-#define GAAOPTID_x509fmtder    26
-#define GAAOPTID_crlf  27
-#define GAAOPTID_mtu   28
-#define GAAOPTID_udp   29
-#define GAAOPTID_starttls      30
-#define GAAOPTID_noticket      31
-#define GAAOPTID_rehandshake   32
-#define GAAOPTID_resume        33
-#define GAAOPTID_debug 34
+#define GAAOPTID_benchmark_soft_ciphers        5
+#define GAAOPTID_benchmark_ciphers     6
+#define GAAOPTID_insecure      7
+#define GAAOPTID_port  8
+#define GAAOPTID_pskkey        9
+#define GAAOPTID_pskusername   10
+#define GAAOPTID_srppasswd     11
+#define GAAOPTID_srpusername   12
+#define GAAOPTID_x509certfile  13
+#define GAAOPTID_x509keyfile   14
+#define GAAOPTID_pgpsubkey     15
+#define GAAOPTID_pgpcertfile   16
+#define GAAOPTID_pgpkeyring    17
+#define GAAOPTID_pgpkeyfile    18
+#define GAAOPTID_x509crlfile   19
+#define GAAOPTID_x509cafile    20
+#define GAAOPTID_priority      21
+#define GAAOPTID_verbose       22
+#define GAAOPTID_recordsize    23
+#define GAAOPTID_print_cert    24
+#define GAAOPTID_disable_extensions    25
+#define GAAOPTID_fingerprint   26
+#define GAAOPTID_x509fmtder    27
+#define GAAOPTID_crlf  28
+#define GAAOPTID_mtu   29
+#define GAAOPTID_udp   30
+#define GAAOPTID_starttls      31
+#define GAAOPTID_noticket      32
+#define GAAOPTID_rehandshake   33
+#define GAAOPTID_resume        34
+#define GAAOPTID_debug 35
 
 #line 168 "gaa.skel"
 
@@ -672,6 +674,7 @@ static int gaa_get_option_num(char *str, int status)
                        GAA_CHECK1STR("h", GAAOPTID_help);
                        GAA_CHECK1STR("l", GAAOPTID_list);
                        GAA_CHECK1STR("", GAAOPTID_benchmark_tls);
+                       GAA_CHECK1STR("", GAAOPTID_benchmark_soft_ciphers);
                        GAA_CHECK1STR("", GAAOPTID_benchmark_ciphers);
                        GAA_CHECK1STR("", GAAOPTID_insecure);
                        GAA_CHECK1STR("V", GAAOPTID_verbose);
@@ -693,6 +696,7 @@ static int gaa_get_option_num(char *str, int status)
                        GAA_CHECKSTR("help", GAAOPTID_help);
                        GAA_CHECKSTR("list", GAAOPTID_list);
                        GAA_CHECKSTR("benchmark-tls", GAAOPTID_benchmark_tls);
+                       GAA_CHECKSTR("benchmark-soft-ciphers", 
GAAOPTID_benchmark_soft_ciphers);
                        GAA_CHECKSTR("benchmark-ciphers", 
GAAOPTID_benchmark_ciphers);
                        GAA_CHECKSTR("insecure", GAAOPTID_insecure);
                        GAA_CHECKSTR("port", GAAOPTID_port);
@@ -774,36 +778,43 @@ static int gaa_try(int gaa_num, int gaa_index, gaainfo 
*gaaval, char *opt_list)
     {
        case GAAOPTID_version:
        OK = 0;
-#line 108 "cli.gaa"
+#line 109 "cli.gaa"
 { cli_version(); exit(0); ;};
 
                return GAA_OK;
                break;
        case GAAOPTID_help:
        OK = 0;
-#line 106 "cli.gaa"
+#line 107 "cli.gaa"
 { gaa_help(); exit(0); ;};
 
                return GAA_OK;
                break;
        case GAAOPTID_list:
        OK = 0;
-#line 105 "cli.gaa"
+#line 106 "cli.gaa"
 { print_list(gaaval->verbose); exit(0); ;};
 
                return GAA_OK;
                break;
        case GAAOPTID_benchmark_tls:
        OK = 0;
-#line 103 "cli.gaa"
+#line 104 "cli.gaa"
 { benchmark_tls(gaaval->debug); exit(0) ;};
 
                return GAA_OK;
                break;
+       case GAAOPTID_benchmark_soft_ciphers:
+       OK = 0;
+#line 103 "cli.gaa"
+{ benchmark_cipher(0, gaaval->debug); exit(0) ;};
+
+               return GAA_OK;
+               break;
        case GAAOPTID_benchmark_ciphers:
        OK = 0;
 #line 102 "cli.gaa"
-{ benchmark_cipher(gaaval->debug); exit(0) ;};
+{ benchmark_cipher(1, gaaval->debug); exit(0) ;};
 
                return GAA_OK;
                break;
@@ -1065,7 +1076,7 @@ static int gaa_try(int gaa_num, int gaa_index, gaainfo 
*gaaval, char *opt_list)
                GAA_TESTMOREARGS;
                GAA_FILL(GAAREST_tmp.arg1, gaa_getstr, GAAREST_tmp.size1);
                gaa_index++;
-#line 111 "cli.gaa"
+#line 112 "cli.gaa"
 { gaaval->rest_args = GAAREST_tmp.arg1; ;};
 
                return GAA_OK;
@@ -1094,7 +1105,7 @@ int gaa(int argc, char **argv, gaainfo *gaaval)
     if(inited == 0)
     {
 
-#line 113 "cli.gaa"
+#line 114 "cli.gaa"
 { gaaval->resume=0; gaaval->noticket=0; gaaval->port="443"; 
gaaval->rest_args=NULL; 
        gaaval->record_size=0; 
        gaaval->fingerprint=0; gaaval->pgp_keyring=NULL; gaaval->x509_crlfile = 
NULL;
diff --git a/src/cli-gaa.h b/src/cli-gaa.h
index d4a5188..2a44d2d 100644
--- a/src/cli-gaa.h
+++ b/src/cli-gaa.h
@@ -8,7 +8,7 @@ typedef struct _gaainfo gaainfo;
 
 struct _gaainfo
 {
-#line 110 "cli.gaa"
+#line 111 "cli.gaa"
        char *rest_args;
 #line 99 "cli.gaa"
        int insecure;
diff --git a/src/cli.c b/src/cli.c
index ae665c2..946dc85 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -26,9 +26,14 @@
 #include <string.h>
 #include <sys/time.h>
 #include <sys/stat.h>
-#include <sys/socket.h>
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#elif HAVE_WS2TCPIP_H
+# include <ws2tcpip.h>
+#endif
 #include <sys/select.h>
 #include <unistd.h>
+#include <stdint.h>
 #include <fcntl.h>
 
 #include <gnutls/gnutls.h>
@@ -173,7 +178,7 @@ load_keys (void)
   gnutls_pkcs11_privkey_t pkcs11_key;
 #endif
   gnutls_x509_privkey_t tmp_key;
-  uint8_t keyid[GNUTLS_OPENPGP_KEYID_SIZE];
+  unsigned char keyid[GNUTLS_OPENPGP_KEYID_SIZE];
 
   if (x509_certfile != NULL && x509_keyfile != NULL)
     {
diff --git a/src/cli.gaa b/src/cli.gaa
index 1d1c74f..b06d336 100644
--- a/src/cli.gaa
+++ b/src/cli.gaa
@@ -99,7 +99,8 @@ option (p, port) STR "PORT" { $port = $1 } "The port to 
connect to."
 #int insecure;
 option (insecure) { $insecure = 1 } "Don't abort program if server certificate 
can't be validated."
 
-option ( benchmark-ciphers) { benchmark_cipher($debug); exit(0) } "Benchmark 
individual ciphers."
+option ( benchmark-ciphers) { benchmark_cipher(1, $debug); exit(0) } 
"Benchmark individual ciphers."
+option ( benchmark-soft-ciphers) { benchmark_cipher(0, $debug); exit(0) } 
"Benchmark individual software ciphers."
 option ( benchmark-tls) { benchmark_tls($debug); exit(0) } "Benchmark ciphers 
and key exchange methods in TLS."
 
 option (l, list) { print_list($verbose); exit(0); } "Print a list of the 
supported algorithms and modes."
diff --git a/src/common.h b/src/common.h
index 6fa5ab7..5d0757b 100644
--- a/src/common.h
+++ b/src/common.h
@@ -1,13 +1,17 @@
 #define PORT 5556
 #define SERVER "127.0.0.1"
 
+#include <config.h>
 #include <gnutls/gnutls.h>
 
 #include <sys/socket.h>
 #include <netdb.h>
 #include <unistd.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
+#ifndef _WIN32
+# include <netinet/in.h>
+# include <netinet/ip.h>
+#endif
+
 #include <signal.h>
 #ifdef _WIN32
 #include <io.h>
diff --git a/src/p11common.c b/src/p11common.c
index 0a8cf85..8deda79 100644
--- a/src/p11common.c
+++ b/src/p11common.c
@@ -28,6 +28,8 @@
 #include <gnutls/pkcs11.h>
 #include <p11common.h>
 
+#ifdef ENABLE_PKCS11
+
 #define MIN(x,y) ((x)<(y))?(x):(y)
 
 #define MAX_CACHE_TRIES 5
@@ -130,3 +132,4 @@ pkcs11_common (void)
 
 }
 
+#endif
diff --git a/src/pkcs11.c b/src/pkcs11.c
index 251f79f..adde2c9 100644
--- a/src/pkcs11.c
+++ b/src/pkcs11.c
@@ -22,7 +22,6 @@
 #include <getpass.h>
 
 #include <gnutls/gnutls.h>
-#include <gnutls/extra.h>
 #include <gnutls/pkcs11.h>
 #include <gnutls/abstract.h>
 #include <stdio.h>
diff --git a/src/prime.c b/src/prime.c
index f53b31e..1113375 100644
--- a/src/prime.c
+++ b/src/prime.c
@@ -92,12 +92,24 @@ generate_prime (int how, common_info_st * info)
           g = gnutls_srp_1536_group_generator;
           bits = 1536;
         }
-      else
+      else if (bits <= 2048)
         {
           p = gnutls_srp_2048_group_prime;
           g = gnutls_srp_2048_group_generator;
           bits = 2048;
         }
+      else if (bits <=3072)
+        {
+          p = gnutls_srp_3072_group_prime;
+          g = gnutls_srp_3072_group_generator;
+          bits = 3072;
+        }
+      else
+        {
+          p = gnutls_srp_4096_group_prime;
+          g = gnutls_srp_4096_group_generator;
+          bits = 4096;
+        }
 
       ret = gnutls_dh_params_import_raw (dh_params, &p, &g);
       if (ret < 0)
diff --git a/src/psk.c b/src/psk.c
index 5488d61..85011be 100644
--- a/src/psk.c
+++ b/src/psk.c
@@ -41,7 +41,6 @@ main (int argc, char **argv)
 #include <string.h>
 #include <stdlib.h>
 #include <gnutls/gnutls.h>
-#include <gnutls/extra.h>
 #include <psk-gaa.h>
 
 #include <gnutls/crypto.h>      /* for random */
diff --git a/src/serv.c b/src/serv.c
index 1fcda5c..9a5c486 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -33,13 +33,13 @@
 #include <sys/types.h>
 #include <string.h>
 #include <gnutls/gnutls.h>
-#include <gnutls/extra.h>
 #include <gnutls/openpgp.h>
 #include <sys/time.h>
 #include <sys/select.h>
 #include <fcntl.h>
 #include <list.h>
 #include <netdb.h>
+#include <unistd.h>
 
 /* Gnulib portability files. */
 #include "progname.h"
@@ -935,12 +935,6 @@ main (int argc, char **argv)
       exit (1);
     }
 
-  if ((ret = gnutls_global_init_extra ()) < 0)
-    {
-      fprintf (stderr, "global_init_extra: %s\n", gnutls_strerror (ret));
-      exit (1);
-    }
-
 #ifdef ENABLE_PKCS11
   pkcs11_common ();
 #endif
diff --git a/src/srptool.c b/src/srptool.c
index 5c25c85..8575046 100644
--- a/src/srptool.c
+++ b/src/srptool.c
@@ -25,7 +25,6 @@
 #include <string.h>
 #include <stdlib.h>
 #include <gnutls/gnutls.h>
-#include <gnutls/extra.h>
 #include <srptool-gaa.h>
 #include <gnutls/crypto.h>      /* for random */
 
@@ -93,7 +92,7 @@ generate_create_conf (char *tpasswd_conf)
       return -1;
     }
 
-  for (index = 1; index <= 3; index++)
+  for (index = 1; index <= 5; index++)
     {
 
       if (index == 1)
@@ -106,11 +105,26 @@ generate_create_conf (char *tpasswd_conf)
           n = gnutls_srp_1536_group_prime;
           g = gnutls_srp_1536_group_generator;
         }
-      else
+      else if (index == 3)
         {
           n = gnutls_srp_2048_group_prime;
           g = gnutls_srp_2048_group_generator;
         }
+      else if (index == 4)
+        {
+          n = gnutls_srp_3072_group_prime;
+          g = gnutls_srp_3072_group_generator;
+        }
+      else if (index == 5)
+        {
+          n = gnutls_srp_4096_group_prime;
+          g = gnutls_srp_4096_group_generator;
+        }
+      else
+        {
+          fprintf(stderr, "Unknown index: %d\n", index);
+          return -1;
+        }
 
       printf ("\nGroup %d, of %d bits:\n", index, n.size * 8);
       print_num ("Generator", &g);
diff --git a/src/tests.c b/src/tests.c
index aecad73..616053d 100644
--- a/src/tests.c
+++ b/src/tests.c
@@ -21,7 +21,6 @@
 
 #include <config.h>
 #include <gnutls/gnutls.h>
-#include <gnutls/extra.h>
 #include <gnutls/x509.h>
 
 #ifndef _WIN32
@@ -106,16 +105,17 @@ do_handshake (gnutls_session_t session)
 }
 
 char protocol_str[] = "+VERS-TLS1.0:+VERS-SSL3.0";
-char prio_str[256] = "";
+char protocol_all_str[] = 
"+VERS-TLS1.2:+VERS-TLS1.1:+VERS-TLS1.0:+VERS-SSL3.0";
+char prio_str[512] = "";
 
 #define ALL_CIPHERS "+3DES-CBC:+ARCFOUR-128:+ARCFOUR-40"
 #define BLOCK_CIPHERS "+3DES-CBC:+AES-128-CBC"
 #define ALL_COMP "+COMP-NULL"
 #define ALL_MACS "+SHA1:+MD5"
 #define ALL_CERTTYPES "+CTYPE-X509"
-#define ALL_KX "+RSA:+DHE-RSA:+DHE-DSS:+ANON-DH:+RSA-EXPORT"
+#define ALL_KX 
"+RSA:+DHE-RSA:+DHE-DSS:+ANON-DH:+RSA-EXPORT:+ECDHE-RSA:+ECDHE-ECDSA:+ANON-ECDH"
 #define INIT_STR "NONE:"
-char rest[128] = "%UNSAFE_RENEGOTIATION";
+char rest[128] = "%UNSAFE_RENEGOTIATION:+SIGN-ALL:+CURVE-ALL";
 
 static inline void
 _gnutls_priority_set_direct (gnutls_session_t session, const char *str)
@@ -258,6 +258,7 @@ test_export_info (gnutls_session_t session)
 }
 
 static gnutls_datum_t pubkey = { NULL, 0 };
+static gnutls_ecc_curve_t curve = GNUTLS_ECC_CURVE_INVALID;
 
 test_code_t
 test_dhe (gnutls_session_t session)
@@ -278,6 +279,24 @@ test_dhe (gnutls_session_t session)
   return ret;
 }
 
+test_code_t test_ecdhe (gnutls_session_t session)
+{
+  int ret;
+
+  sprintf (prio_str, INIT_STR
+           ALL_CIPHERS ":" ALL_COMP ":" ALL_CERTTYPES ":%s:" ALL_MACS
+           ":+ECDHE-RSA:+ECDHE-ECDSA:+CURVE-ALL:%s", protocol_all_str, rest);
+  _gnutls_priority_set_direct (session, prio_str);
+
+  gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
+
+  ret = do_handshake (session);
+
+  curve = gnutls_ecc_curve_get(session);
+
+  return ret;
+}
+
 
 test_code_t
 test_safe_renegotiation (gnutls_session_t session)
@@ -359,6 +378,17 @@ test_dhe_group (gnutls_session_t session)
 }
 
 test_code_t
+test_ecdhe_curve (gnutls_session_t session)
+{
+  if (curve == GNUTLS_ECC_CURVE_INVALID)
+    return TEST_IGNORE;
+
+  printf ("\n Curve %s", gnutls_ecc_curve_get_name(curve));
+
+  return TEST_SUCCEED;
+}
+
+test_code_t
 test_ssl3 (gnutls_session_t session)
 {
   int ret;
@@ -458,7 +488,21 @@ test_aes (gnutls_session_t session)
   return ret;
 }
 
-#ifdef ENABLE_CAMELLIA
+test_code_t test_aes_gcm (gnutls_session_t session)
+{
+  int ret;
+
+  sprintf (prio_str, INIT_STR
+           "+AES-128-GCM:+AES-256-GCM:+AEAD:" ALL_COMP ":" ALL_CERTTYPES 
":%s:" ALL_MACS
+           ":" ALL_KX ":%s", protocol_all_str, rest);
+  _gnutls_priority_set_direct (session, prio_str);
+
+  gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
+
+  ret = do_handshake (session);
+  return ret;
+}
+
 test_code_t
 test_camellia (gnutls_session_t session)
 {
@@ -474,7 +518,6 @@ test_camellia (gnutls_session_t session)
   ret = do_handshake (session);
   return ret;
 }
-#endif
 
 test_code_t
 test_openpgp1 (gnutls_session_t session)
@@ -503,18 +546,10 @@ test_unknown_ciphersuites (gnutls_session_t session)
 {
   int ret;
 
-
-#ifdef ENABLE_CAMELLIA
-  sprintf (prio_str,
-           INIT_STR ALL_CIPHERS ":" ALL_COMP ":" ALL_CERTTYPES ":%s:" ALL_MACS
-           ":" ALL_KX ":%s", protocol_str, rest);
-  _gnutls_priority_set_direct (session, prio_str);
-#else
   sprintf (prio_str,
            INIT_STR "+AES-128-CBC:" ALL_CIPHERS ":" ALL_COMP ":" ALL_CERTTYPES
            ":%s:" ALL_MACS ":" ALL_KX ":%s", protocol_str, rest);
   _gnutls_priority_set_direct (session, prio_str);
-#endif
 
   gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
 
@@ -572,6 +607,21 @@ test_sha (gnutls_session_t session)
 }
 
 test_code_t
+test_sha256 (gnutls_session_t session)
+{
+  int ret;
+
+  sprintf (prio_str,
+           INIT_STR "+AES-128-CBC:" ALL_CIPHERS ":" ALL_COMP ":" ALL_CERTTYPES
+           ":%s:+SHA256:" ALL_KX ":%s", protocol_all_str, rest);
+  _gnutls_priority_set_direct (session, prio_str);
+  gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
+
+  ret = do_handshake (session);
+  return ret;
+}
+
+test_code_t
 test_3des (gnutls_session_t session)
 {
   int ret;
@@ -816,6 +866,22 @@ test_hello_extension (gnutls_session_t session)
            ":" ALL_KX ":%s", protocol_str, rest);
   _gnutls_priority_set_direct (session, prio_str);
   gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
+  gnutls_record_set_max_size (session, 4096);
+
+  ret = do_handshake (session);
+  return ret;
+}
+
+test_code_t
+test_small_records (gnutls_session_t session)
+{
+  int ret;
+
+  sprintf (prio_str,
+           INIT_STR ALL_CIPHERS ":" ALL_COMP ":" ALL_CERTTYPES ":%s:" ALL_MACS
+           ":" ALL_KX ":%s", protocol_str, rest);
+  _gnutls_priority_set_direct (session, prio_str);
+  gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
   gnutls_record_set_max_size (session, 512);
 
   ret = do_handshake (session);
@@ -911,7 +977,7 @@ test_anonymous (gnutls_session_t session)
 
   sprintf (prio_str,
            INIT_STR ALL_CIPHERS ":" ALL_COMP ":" ALL_CERTTYPES ":%s:" ALL_MACS
-           ":+ANON-DH:%s", protocol_str, rest);
+           ":+ANON-DH:+ANON-ECDH:+CURVE-ALL:%s", protocol_str, rest);
   _gnutls_priority_set_direct (session, prio_str);
   gnutls_credentials_set (session, GNUTLS_CRD_ANON, anon_cred);
 
diff --git a/src/tests.h b/src/tests.h
index 5961a71..41dd35e 100644
--- a/src/tests.h
+++ b/src/tests.h
@@ -8,13 +8,12 @@ test_code_t test_record_padding (gnutls_session_t state);
 test_code_t test_export (gnutls_session_t state);
 test_code_t test_export_info (gnutls_session_t state);
 test_code_t test_hello_extension (gnutls_session_t state);
+test_code_t test_small_records (gnutls_session_t state);
 test_code_t test_dhe (gnutls_session_t state);
 test_code_t test_dhe_group (gnutls_session_t state);
 test_code_t test_ssl3 (gnutls_session_t state);
 test_code_t test_aes (gnutls_session_t state);
-#ifdef ENABLE_CAMELLIA
 test_code_t test_camellia (gnutls_session_t state);
-#endif
 test_code_t test_md5 (gnutls_session_t state);
 test_code_t test_sha (gnutls_session_t state);
 test_code_t test_3des (gnutls_session_t state);
@@ -42,3 +41,8 @@ test_code_t test_version_oob (gnutls_session_t session);
 test_code_t test_zlib (gnutls_session_t session);
 int _test_srp_username_callback (gnutls_session_t session,
                                  char **username, char **password);
+
+test_code_t test_ecdhe_curve (gnutls_session_t session);
+test_code_t test_ecdhe (gnutls_session_t session);
+test_code_t test_aes_gcm (gnutls_session_t session);
+test_code_t test_sha256 (gnutls_session_t session);
diff --git a/src/tls_test.c b/src/tls_test.c
index 46f5561..0c9cfd7 100644
--- a/src/tls_test.c
+++ b/src/tls_test.c
@@ -26,9 +26,12 @@
 #include <sys/types.h>
 #include <string.h>
 #include <gnutls/gnutls.h>
-#include <gnutls/extra.h>
 #include <sys/time.h>
-#include <sys/socket.h>
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#elif HAVE_WS2TCPIP_H
+# include <ws2tcpip.h>
+#endif
 #include <tests.h>
 #include <common.h>
 #include <tls_test-gaa.h>
@@ -106,6 +109,8 @@ static const TLS_TEST tls_tests[] = {
    test_rsa_pms_version_check, "yes", "no", "dunno"},
   {"whether the server can accept Hello Extensions",
    test_hello_extension, "yes", "no", "dunno"},
+  {"whether the server can accept small records (512 bytes)",
+   test_small_records, "yes", "no", "dunno"},
   {"whether the server can accept cipher suites not in SSL 3.0 spec",
    test_unknown_ciphersuites, "yes", "no", "dunno"},
   {"whether the server can accept a bogus TLS record version in the client 
hello", test_version_oob, "yes", "no", "dunno"},
@@ -130,25 +135,30 @@ static const TLS_TEST tls_tests[] = {
    "dunno"},
   {"ephemeral Diffie-Hellman group info", test_dhe_group, "", "N/A",
    "N/A"},
-  {"for AES cipher support (TLS extension)", test_aes, "yes", "no",
+  {"for ephemeral EC Diffie-Hellman support", test_ecdhe, "yes", "no",
    "dunno"},
-#ifdef ENABLE_CAMELLIA
-  {"for CAMELLIA cipher support (TLS extension)", test_camellia, "yes", "no",
+  {"ephemeral EC Diffie-Hellman group info", test_ecdhe_curve, "", "N/A",
+   "N/A"},
+  {"for AES-GCM cipher support", test_aes_gcm, "yes", "no",
    "dunno"},
-#endif
-  {"for 3DES cipher support", test_3des, "yes", "no", "dunno"},
+  {"for AES-CBC cipher support", test_aes, "yes", "no",
+   "dunno"},
+  {"for CAMELLIA cipher support", test_camellia, "yes", "no",
+   "dunno"},
+  {"for 3DES-CBC cipher support", test_3des, "yes", "no", "dunno"},
   {"for ARCFOUR 128 cipher support", test_arcfour, "yes", "no", "dunno"},
   {"for ARCFOUR 40 cipher support", test_arcfour_40, "yes", "no",
    "dunno"},
   {"for MD5 MAC support", test_md5, "yes", "no", "dunno"},
   {"for SHA1 MAC support", test_sha, "yes", "no", "dunno"},
+  {"for SHA256 MAC support", test_sha256, "yes", "no", "dunno"},
 #ifdef HAVE_LIBZ
-  {"for ZLIB compression support (TLS extension)", test_zlib, "yes",
+  {"for ZLIB compression support", test_zlib, "yes",
    "no", "dunno"},
 #endif
-  {"for max record size (TLS extension)", test_max_record_size, "yes",
+  {"for max record size", test_max_record_size, "yes",
    "no", "dunno"},
-  {"for OpenPGP authentication support (TLS extension)", test_openpgp1,
+  {"for OpenPGP authentication support", test_openpgp1,
    "yes", "no", "dunno"},
   {NULL, NULL, NULL, NULL, NULL}
 };
diff --git a/src/udp-serv.c b/src/udp-serv.c
index 79066d9..b41b1ea 100644
--- a/src/udp-serv.c
+++ b/src/udp-serv.c
@@ -1,7 +1,35 @@
+/*
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * This file is part of GnuTLS.
+ *
+ * GnuTLS is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuTLS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
 #include <stdio.h>
-#include <sys/socket.h>
+#if HAVE_SYS_SOCKET_H
+# include <sys/socket.h>
+#elif HAVE_WS2TCPIP_H
+# include <ws2tcpip.h>
+#endif
 #include <arpa/inet.h>
-#include <netinet/in.h>
+#ifndef _WIN32
+# include <netinet/in.h>
+#endif
+#include <sys/select.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1ae1e14..aed9ab0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -30,7 +30,7 @@ if WANT_TEST_SUITE
 SUBDIRS += suite
 endif
 
-EXTRA_DIST = libgcrypt.supp eagain-common.h
+EXTRA_DIST = suppressions.valgrind eagain-common.h
 
 AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
 AM_CPPFLAGS = \
@@ -38,8 +38,8 @@ AM_CPPFLAGS = \
        -I$(top_builddir)/gl                    \
        -I$(top_srcdir)/lib/includes            \
        -I$(top_builddir)/lib/includes          \
-       -I$(top_srcdir)/libextra/includes       \
-       -I$(top_builddir)/libextra/includes     \
+       -I$(top_srcdir)/extra/includes  \
+       -I$(top_builddir)/extra/includes        \
        -I$(top_srcdir)/lib                     \
        -I$(top_srcdir)/doc/examples
 
@@ -57,16 +57,15 @@ endif
 noinst_LTLIBRARIES = libutils.la
 libutils_la_SOURCES = utils.h utils.c
 
-ctests = simple gc set_pkcs12_cred certder certuniqueid mpi            \
-       certificate_set_x509_crl dn parse_ca moredn mini        \
-       hostname-check cve-2008-4989 pkcs12_s2k chainverify crq_key_id  \
-       x509sign-verify cve-2009-1415 cve-2009-1416 crq_apis            \
-       init_roundtrip pkcs12_s2k_pem dn2 mini-eagain                   \
-       nul-in-x509-names x509_altname pkcs12_encode mini-x509          \
-       mini-x509-rehandshake rng-fork mini-eagain-dtls cipher-test     \
-       x509cert x509cert-tl infoaccess #gendh mini-deflate
-#gendh is out because it is too slow in valgrind and
-#mini-deflate is out because zlib has warnings in valgrind
+ctests = mini-deflate simple gc set_pkcs12_cred certder certuniqueid   \
+        mpi certificate_set_x509_crl dn parse_ca moredn mini           \
+        hostname-check cve-2008-4989 pkcs12_s2k chainverify            \
+        crq_key_id x509sign-verify cve-2009-1415 cve-2009-1416         \
+        crq_apis init_roundtrip pkcs12_s2k_pem dn2 mini-eagain         \
+        nul-in-x509-names x509_altname pkcs12_encode mini-x509         \
+        mini-x509-rehandshake rng-fork mini-eagain-dtls cipher-test    \
+        x509cert x509cert-tl infoaccess #gendh
+#gendh is out because it is too slow in valgrind
 
 if ENABLE_OCSP
 ctests += ocsp
@@ -74,12 +73,11 @@ endif
 
 if ENABLE_OPENSSL
 ctests +=  openssl
-openssl_LDADD = $(LDADD) ../libextra/libgnutls-openssl.la
+openssl_LDADD = $(LDADD) ../extra/libgnutls-openssl.la
 endif
 
 if ENABLE_OPENPGP
 ctests += openpgp-auth openpgp-auth2 openpgp-keyring pgps2kgnu
-openpgp_keyring_LDADD = $(LDADD) ../libextra/libgnutls-extra.la
 endif
 
 if HAVE_FORK
diff --git a/tests/cipher-test.c b/tests/cipher-test.c
index c14813f..dfb7ae7 100644
--- a/tests/cipher-test.c
+++ b/tests/cipher-test.c
@@ -13,375 +13,465 @@
 
 struct aes_vectors_st
 {
-  const uint8_t *key;
-  const uint8_t *plaintext;
-  const uint8_t *ciphertext;
+    const uint8_t *key;
+    const uint8_t *plaintext;
+    const uint8_t *ciphertext;
 };
 
 struct aes_gcm_vectors_st
 {
-  const uint8_t *key;
-  const uint8_t *auth;
-  int auth_size;
-  const uint8_t *plaintext;
-  int plaintext_size;
-  const uint8_t *iv;
-  const uint8_t *ciphertext;
-  const uint8_t *tag;
+    const uint8_t *key;
+    const uint8_t *auth;
+    int auth_size;
+    const uint8_t *plaintext;
+    int plaintext_size;
+    const uint8_t *iv;
+    const uint8_t *ciphertext;
+    const uint8_t *tag;
 };
 
 struct aes_gcm_vectors_st aes_gcm_vectors[] = {
-  {
-   .key = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
-   .auth = NULL,
-   .auth_size = 0,
-   .plaintext = NULL,
-   .plaintext_size = 0,
-   .ciphertext = NULL,
-   .iv = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
-   .tag = "\x58\xe2\xfc\xce\xfa\x7e\x30\x61\x36\x7f\x1d\x57\xa4\xe7\x45\x5a"},
-  {
-   .key = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
-   .auth = NULL,
-   .auth_size = 0,
-   .plaintext =
-   "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
-   .plaintext_size = 16,
-   .ciphertext =
-   "\x03\x88\xda\xce\x60\xb6\xa3\x92\xf3\x28\xc2\xb9\x71\xb2\xfe\x78",
-   .iv = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
-   .tag = "\xab\x6e\x47\xd4\x2c\xec\x13\xbd\xf5\x3a\x67\xb2\x12\x57\xbd\xdf"},
-  {
-   .key = "\xfe\xff\xe9\x92\x86\x65\x73\x1c\x6d\x6a\x8f\x94\x67\x30\x83\x08",
-   .auth =
-   
"\xfe\xed\xfa\xce\xde\xad\xbe\xef\xfe\xed\xfa\xce\xde\xad\xbe\xef\xab\xad\xda\xd2",
-   .auth_size = 20,
-   .plaintext =
-   
"\xd9\x31\x32\x25\xf8\x84\x06\xe5\xa5\x59\x09\xc5\xaf\xf5\x26\x9a\x86\xa7\xa9\x53\x15\x34\xf7\xda\x2e\x4c\x30\x3d\x8a\x31\x8a\x72\x1c\x3c\x0c\x95\x95\x68\x09\x53\x2f\xcf\x0e\x24\x49\xa6\xb5\x25\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57\xba\x63\x7b\x39",
-   .plaintext_size = 60,
-   .ciphertext =
-   
"\x42\x83\x1e\xc2\x21\x77\x74\x24\x4b\x72\x21\xb7\x84\xd0\xd4\x9c\xe3\xaa\x21\x2f\x2c\x02\xa4\xe0\x35\xc1\x7e\x23\x29\xac\xa1\x2e\x21\xd5\x14\xb2\x54\x66\x93\x1c\x7d\x8f\x6a\x5a\xac\x84\xaa\x05\x1b\xa3\x0b\x39\x6a\x0a\xac\x97\x3d\x58\xe0\x91",
-   .iv = "\xca\xfe\xba\xbe\xfa\xce\xdb\xad\xde\xca\xf8\x88",
-   .tag = "\x5b\xc9\x4f\xbc\x32\x21\xa5\xdb\x94\xfa\xe9\x5a\xe7\x12\x1a\x47"}
+    {
+     .key =
+     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+     .auth = NULL,
+     .auth_size = 0,
+     .plaintext = NULL,
+     .plaintext_size = 0,
+     .ciphertext = NULL,
+     .iv = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+     .tag =
+     "\x58\xe2\xfc\xce\xfa\x7e\x30\x61\x36\x7f\x1d\x57\xa4\xe7\x45\x5a"},
+    {
+     .key =
+     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+     .auth = NULL,
+     .auth_size = 0,
+     .plaintext =
+     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+     .plaintext_size = 16,
+     .ciphertext =
+     "\x03\x88\xda\xce\x60\xb6\xa3\x92\xf3\x28\xc2\xb9\x71\xb2\xfe\x78",
+     .iv = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+     .tag =
+     "\xab\x6e\x47\xd4\x2c\xec\x13\xbd\xf5\x3a\x67\xb2\x12\x57\xbd\xdf"},
+    {
+     .key =
+     "\xfe\xff\xe9\x92\x86\x65\x73\x1c\x6d\x6a\x8f\x94\x67\x30\x83\x08",
+     .auth =
+     
"\xfe\xed\xfa\xce\xde\xad\xbe\xef\xfe\xed\xfa\xce\xde\xad\xbe\xef\xab\xad\xda\xd2",
+     .auth_size = 20,
+     .plaintext =
+     
"\xd9\x31\x32\x25\xf8\x84\x06\xe5\xa5\x59\x09\xc5\xaf\xf5\x26\x9a\x86\xa7\xa9\x53\x15\x34\xf7\xda\x2e\x4c\x30\x3d\x8a\x31\x8a\x72\x1c\x3c\x0c\x95\x95\x68\x09\x53\x2f\xcf\x0e\x24\x49\xa6\xb5\x25\xb1\x6a\xed\xf5\xaa\x0d\xe6\x57\xba\x63\x7b\x39",
+     .plaintext_size = 60,
+     .ciphertext =
+     
"\x42\x83\x1e\xc2\x21\x77\x74\x24\x4b\x72\x21\xb7\x84\xd0\xd4\x9c\xe3\xaa\x21\x2f\x2c\x02\xa4\xe0\x35\xc1\x7e\x23\x29\xac\xa1\x2e\x21\xd5\x14\xb2\x54\x66\x93\x1c\x7d\x8f\x6a\x5a\xac\x84\xaa\x05\x1b\xa3\x0b\x39\x6a\x0a\xac\x97\x3d\x58\xe0\x91",
+     .iv = "\xca\xfe\xba\xbe\xfa\xce\xdb\xad\xde\xca\xf8\x88",
+     .tag =
+     "\x5b\xc9\x4f\xbc\x32\x21\xa5\xdb\x94\xfa\xe9\x5a\xe7\x12\x1a\x47"}
 };
 
 
 struct aes_vectors_st aes_vectors[] = {
-  {
-   .key =
-   (uint8_t *)
-   "\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
-   .plaintext = (uint8_t *)
-   "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
-   .ciphertext = (uint8_t *)
-   "\x4b\xc3\xf8\x83\x45\x0c\x11\x3c\x64\xca\x42\xe1\x11\x2a\x9e\x87",
-  },
-  {
-   .key = (uint8_t *)
-   "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
-   .plaintext = (uint8_t *)
-   "\xf3\x44\x81\xec\x3c\xc6\x27\xba\xcd\x5d\xc3\xfb\x08\xf2\x73\xe6",
-   .ciphertext = (uint8_t *)
-   "\x03\x36\x76\x3e\x96\x6d\x92\x59\x5a\x56\x7c\xc9\xce\x53\x7f\x5e",
-  },
-  {
-   .key = (uint8_t *)
-   "\x10\xa5\x88\x69\xd7\x4b\xe5\xa3\x74\xcf\x86\x7c\xfb\x47\x38\x59",
-   .plaintext = (uint8_t *)
-   "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
-   .ciphertext = (uint8_t *)
-   "\x6d\x25\x1e\x69\x44\xb0\x51\xe0\x4e\xaa\x6f\xb4\xdb\xf7\x84\x65",
-  },
-  {
-   .key = (uint8_t *)
-   "\xca\xea\x65\xcd\xbb\x75\xe9\x16\x9e\xcd\x22\xeb\xe6\xe5\x46\x75",
-   .plaintext = (uint8_t *)
-   "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
-   .ciphertext = (uint8_t *)
-   "\x6e\x29\x20\x11\x90\x15\x2d\xf4\xee\x05\x81\x39\xde\xf6\x10\xbb",
-  },
-  {
-   .key = (uint8_t *)
-   "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe",
-   .plaintext = (uint8_t *)
-   "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
-   .ciphertext = (uint8_t *)
-   "\x9b\xa4\xa9\x14\x3f\x4e\x5d\x40\x48\x52\x1c\x4f\x88\x77\xd8\x8e",
-  },
+    {
+     .key =
+     (uint8_t *)
+     "\xc0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+     .plaintext = (uint8_t *)
+     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+     .ciphertext = (uint8_t *)
+     "\x4b\xc3\xf8\x83\x45\x0c\x11\x3c\x64\xca\x42\xe1\x11\x2a\x9e\x87",
+     },
+    {
+     .key = (uint8_t *)
+     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+     .plaintext = (uint8_t *)
+     "\xf3\x44\x81\xec\x3c\xc6\x27\xba\xcd\x5d\xc3\xfb\x08\xf2\x73\xe6",
+     .ciphertext = (uint8_t *)
+     "\x03\x36\x76\x3e\x96\x6d\x92\x59\x5a\x56\x7c\xc9\xce\x53\x7f\x5e",
+     },
+    {
+     .key = (uint8_t *)
+     "\x10\xa5\x88\x69\xd7\x4b\xe5\xa3\x74\xcf\x86\x7c\xfb\x47\x38\x59",
+     .plaintext = (uint8_t *)
+     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+     .ciphertext = (uint8_t *)
+     "\x6d\x25\x1e\x69\x44\xb0\x51\xe0\x4e\xaa\x6f\xb4\xdb\xf7\x84\x65",
+     },
+    {
+     .key = (uint8_t *)
+     "\xca\xea\x65\xcd\xbb\x75\xe9\x16\x9e\xcd\x22\xeb\xe6\xe5\x46\x75",
+     .plaintext = (uint8_t *)
+     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+     .ciphertext = (uint8_t *)
+     "\x6e\x29\x20\x11\x90\x15\x2d\xf4\xee\x05\x81\x39\xde\xf6\x10\xbb",
+     },
+    {
+     .key = (uint8_t *)
+     "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe",
+     .plaintext = (uint8_t *)
+     "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+     .ciphertext = (uint8_t *)
+     "\x9b\xa4\xa9\x14\x3f\x4e\x5d\x40\x48\x52\x1c\x4f\x88\x77\xd8\x8e",
+     },
 };
 
 /* AES cipher */
 static int
 test_aes (void)
 {
-  gnutls_cipher_hd_t hd;
-  int ret, i, j;
-  uint8_t _iv[16];
-  uint8_t tmp[128];
-  gnutls_datum_t key, iv;
-
-  fprintf (stdout, "Tests on AES Encryption: ");
-  fflush (stdout);
-  for (i = 0; i < sizeof (aes_vectors) / sizeof (aes_vectors[0]); i++)
-    {
-      memset (_iv, 0, sizeof (_iv));
-      memset (tmp, 0, sizeof (tmp));
-      key.data = (void *) aes_vectors[i].key;
-      key.size = 16;
-
-      iv.data = _iv;
-      iv.size = 16;
-
-      ret = gnutls_cipher_init (&hd, GNUTLS_CIPHER_AES_128_CBC, &key, &iv);
-      if (ret < 0)
-        {
-          fprintf (stderr, "%d: AES test %d failed\n", __LINE__, i);
-          return 1;
-        }
-
-      ret = gnutls_cipher_encrypt2 (hd, aes_vectors[i].plaintext, 16,
-                                    tmp, 16);
-      if (ret < 0)
-        {
-          fprintf (stderr, "%d: AES test %d failed\n", __LINE__, i);
-          return 1;
-        }
-
-      gnutls_cipher_deinit (hd);
-
-      if (memcmp (tmp, aes_vectors[i].ciphertext, 16) != 0)
-        {
-          fprintf (stderr, "AES test vector %d failed!\n", i);
-
-          fprintf (stderr, "Cipher[%d]: ", 16);
-          for (j = 0; j < 16; j++)
-            fprintf (stderr, "%.2x:", (int) tmp[j]);
-          fprintf (stderr, "\n");
-
-          fprintf (stderr, "Expected[%d]: ", 16);
-          for (j = 0; j < 16; j++)
-            fprintf (stderr, "%.2x:", (int) aes_vectors[i].ciphertext[j]);
-          fprintf (stderr, "\n");
-          return 1;
-        }
-    }
-  fprintf (stdout, "ok\n");
-
-  fprintf (stdout, "Tests on AES Decryption: ");
-  fflush (stdout);
-  for (i = 0; i < sizeof (aes_vectors) / sizeof (aes_vectors[0]); i++)
-    {
+    gnutls_cipher_hd_t hd;
+    int ret, i, j;
+    uint8_t _iv[16];
+    uint8_t tmp[128];
+    gnutls_datum_t key, iv;
+
+    fprintf (stdout, "Tests on AES Encryption: ");
+    fflush (stdout);
+    for (i = 0; i < sizeof (aes_vectors) / sizeof (aes_vectors[0]); i++)
+      {
+          memset (_iv, 0, sizeof (_iv));
+          memset (tmp, 0, sizeof (tmp));
+          key.data = (void *) aes_vectors[i].key;
+          key.size = 16;
+
+          iv.data = _iv;
+          iv.size = 16;
 
-      memset (_iv, 0, sizeof (_iv));
-      memset (tmp, 0x33, sizeof (tmp));
-
-      key.data = (void *) aes_vectors[i].key;
-      key.size = 16;
-
-      iv.data = _iv;
-      iv.size = 16;
-
-      ret = gnutls_cipher_init (&hd, GNUTLS_CIPHER_AES_128_CBC, &key, &iv);
-      if (ret < 0)
-        {
-          fprintf (stderr, "%d: AES test %d failed\n", __LINE__, i);
-          return 1;
-        }
-
-      ret = gnutls_cipher_decrypt2 (hd, aes_vectors[i].ciphertext, 16,
-                                    tmp, 16);
-      if (ret < 0)
-        {
-          fprintf (stderr, "%d: AES test %d failed\n", __LINE__, i);
-          return 1;
-        }
-
-      gnutls_cipher_deinit (hd);
-
-      if (memcmp (tmp, aes_vectors[i].plaintext, 16) != 0)
-        {
-          fprintf (stderr, "AES test vector %d failed!\n", i);
-
-          fprintf (stderr, "Plain[%d]: ", 16);
-          for (j = 0; j < 16; j++)
-            fprintf (stderr, "%.2x:", (int) tmp[j]);
-          fprintf (stderr, "\n");
-
-          fprintf (stderr, "Expected[%d]: ", 16);
-          for (j = 0; j < 16; j++)
-            fprintf (stderr, "%.2x:", (int) aes_vectors[i].plaintext[j]);
-          fprintf (stderr, "\n");
-          return 1;
-        }
-    }
-
-  fprintf (stdout, "ok\n");
-  fprintf (stdout, "\n");
-
-  fprintf (stdout, "Tests on AES-GCM: ");
-  fflush (stdout);
-  for (i = 0; i < sizeof (aes_gcm_vectors) / sizeof (aes_gcm_vectors[0]); i++)
-    {
-      memset (tmp, 0, sizeof (tmp));
-      key.data = (void *) aes_gcm_vectors[i].key;
-      key.size = 16;
-
-      iv.data = (void *) aes_gcm_vectors[i].iv;
-      iv.size = 12;
-
-      ret = gnutls_cipher_init (&hd, GNUTLS_CIPHER_AES_128_GCM, &key, &iv);
-      if (ret < 0)
-        {
-          fprintf (stderr, "%d: AES-GCM test %d failed\n", __LINE__, i);
-          return 1;
-        }
-
-      if (aes_gcm_vectors[i].auth_size > 0)
-        {
           ret =
-            gnutls_cipher_add_auth (hd, aes_gcm_vectors[i].auth,
-                                    aes_gcm_vectors[i].auth_size);
+              gnutls_cipher_init (&hd, GNUTLS_CIPHER_AES_128_CBC, &key,
+                                  &iv);
+          if (ret < 0)
+            {
+                fprintf (stderr, "%d: AES test %d failed\n", __LINE__, i);
+                return 1;
+            }
 
+          ret = gnutls_cipher_encrypt2 (hd, aes_vectors[i].plaintext, 16,
+                                        tmp, 16);
           if (ret < 0)
             {
-              fprintf (stderr, "%d: AES-GCM test %d failed\n", __LINE__, i);
-              return 1;
+                fprintf (stderr, "%d: AES test %d failed\n", __LINE__, i);
+                return 1;
             }
-        }
 
-      if (aes_gcm_vectors[i].plaintext_size > 0)
-        {
+          gnutls_cipher_deinit (hd);
+
+          if (memcmp (tmp, aes_vectors[i].ciphertext, 16) != 0)
+            {
+                fprintf (stderr, "AES test vector %d failed!\n", i);
+
+                fprintf (stderr, "Cipher[%d]: ", 16);
+                for (j = 0; j < 16; j++)
+                    fprintf (stderr, "%.2x:", (int) tmp[j]);
+                fprintf (stderr, "\n");
+
+                fprintf (stderr, "Expected[%d]: ", 16);
+                for (j = 0; j < 16; j++)
+                    fprintf (stderr, "%.2x:",
+                             (int) aes_vectors[i].ciphertext[j]);
+                fprintf (stderr, "\n");
+                return 1;
+            }
+      }
+    fprintf (stdout, "ok\n");
+
+    fprintf (stdout, "Tests on AES Decryption: ");
+    fflush (stdout);
+    for (i = 0; i < sizeof (aes_vectors) / sizeof (aes_vectors[0]); i++)
+      {
+
+          memset (_iv, 0, sizeof (_iv));
+          memset (tmp, 0x33, sizeof (tmp));
+
+          key.data = (void *) aes_vectors[i].key;
+          key.size = 16;
+
+          iv.data = _iv;
+          iv.size = 16;
+
           ret =
-            gnutls_cipher_encrypt2 (hd, aes_gcm_vectors[i].plaintext,
-                                    aes_gcm_vectors[i].plaintext_size, tmp,
-                                    aes_gcm_vectors[i].plaintext_size);
+              gnutls_cipher_init (&hd, GNUTLS_CIPHER_AES_128_CBC, &key,
+                                  &iv);
           if (ret < 0)
             {
-              fprintf (stderr, "%d: AES-GCM test %d failed\n", __LINE__, i);
-              return 1;
+                fprintf (stderr, "%d: AES test %d failed\n", __LINE__, i);
+                return 1;
+            }
+
+          ret = gnutls_cipher_decrypt2 (hd, aes_vectors[i].ciphertext, 16,
+                                        tmp, 16);
+          if (ret < 0)
+            {
+                fprintf (stderr, "%d: AES test %d failed\n", __LINE__, i);
+                return 1;
+            }
+
+          gnutls_cipher_deinit (hd);
+
+          if (memcmp (tmp, aes_vectors[i].plaintext, 16) != 0)
+            {
+                fprintf (stderr, "AES test vector %d failed!\n", i);
+
+                fprintf (stderr, "Plain[%d]: ", 16);
+                for (j = 0; j < 16; j++)
+                    fprintf (stderr, "%.2x:", (int) tmp[j]);
+                fprintf (stderr, "\n");
+
+                fprintf (stderr, "Expected[%d]: ", 16);
+                for (j = 0; j < 16; j++)
+                    fprintf (stderr, "%.2x:",
+                             (int) aes_vectors[i].plaintext[j]);
+                fprintf (stderr, "\n");
+                return 1;
             }
-        }
+      }
 
+    fprintf (stdout, "ok\n");
+    fprintf (stdout, "\n");
 
-      if (aes_gcm_vectors[i].plaintext_size > 0)
-        if (memcmp
-            (tmp, aes_gcm_vectors[i].ciphertext,
-             aes_gcm_vectors[i].plaintext_size) != 0)
-          {
-            fprintf (stderr, "AES-GCM test vector %d failed!\n", i);
+    fprintf (stdout, "Tests on AES-GCM: ");
+    fflush (stdout);
+    for (i = 0; i < sizeof (aes_gcm_vectors) / sizeof (aes_gcm_vectors[0]);
+         i++)
+      {
+          memset (tmp, 0, sizeof (tmp));
+          key.data = (void *) aes_gcm_vectors[i].key;
+          key.size = 16;
 
-            fprintf (stderr, "Cipher[%d]: ",
-                     aes_gcm_vectors[i].plaintext_size);
-            for (j = 0; j < aes_gcm_vectors[i].plaintext_size; j++)
-              fprintf (stderr, "%.2x:", (int) tmp[j]);
-            fprintf (stderr, "\n");
+          iv.data = (void *) aes_gcm_vectors[i].iv;
+          iv.size = 12;
 
-            fprintf (stderr, "Expected[%d]: ",
-                     aes_gcm_vectors[i].plaintext_size);
-            for (j = 0; j < aes_gcm_vectors[i].plaintext_size; j++)
-              fprintf (stderr, "%.2x:",
-                       (int) aes_gcm_vectors[i].ciphertext[j]);
-            fprintf (stderr, "\n");
-            return 1;
-          }
+          ret =
+              gnutls_cipher_init (&hd, GNUTLS_CIPHER_AES_128_GCM, &key,
+                                  &iv);
+          if (ret < 0)
+            {
+                fprintf (stderr, "%d: AES-GCM test %d failed\n", __LINE__,
+                         i);
+                return 1;
+            }
 
-      gnutls_cipher_tag (hd, tmp, 16);
-      if (memcmp (tmp, aes_gcm_vectors[i].tag, 16) != 0)
-        {
-          fprintf (stderr, "AES-GCM test vector %d failed (tag)!\n", i);
+          if (aes_gcm_vectors[i].auth_size > 0)
+            {
+                ret =
+                    gnutls_cipher_add_auth (hd, aes_gcm_vectors[i].auth,
+                                            aes_gcm_vectors[i].auth_size);
+
+                if (ret < 0)
+                  {
+                      fprintf (stderr, "%d: AES-GCM test %d failed\n",
+                               __LINE__, i);
+                      return 1;
+                  }
+            }
+
+          if (aes_gcm_vectors[i].plaintext_size > 0)
+            {
+                ret =
+                    gnutls_cipher_encrypt2 (hd,
+                                            aes_gcm_vectors[i].plaintext,
+                                            aes_gcm_vectors[i].
+                                            plaintext_size, tmp,
+                                            aes_gcm_vectors[i].
+                                            plaintext_size);
+                if (ret < 0)
+                  {
+                      fprintf (stderr, "%d: AES-GCM test %d failed\n",
+                               __LINE__, i);
+                      return 1;
+                  }
+            }
 
-          fprintf (stderr, "Tag[%d]: ", 16);
-          for (j = 0; j < 16; j++)
-            fprintf (stderr, "%.2x:", (int) tmp[j]);
-          fprintf (stderr, "\n");
 
-          fprintf (stderr, "Expected[%d]: ", 16);
-          for (j = 0; j < 16; j++)
-            fprintf (stderr, "%.2x:", (int) aes_gcm_vectors[i].tag[j]);
-          fprintf (stderr, "\n");
-          return 1;
-        }
+          if (aes_gcm_vectors[i].plaintext_size > 0)
+              if (memcmp
+                  (tmp, aes_gcm_vectors[i].ciphertext,
+                   aes_gcm_vectors[i].plaintext_size) != 0)
+                {
+                    fprintf (stderr, "AES-GCM test vector %d failed!\n",
+                             i);
+
+                    fprintf (stderr, "Cipher[%d]: ",
+                             aes_gcm_vectors[i].plaintext_size);
+                    for (j = 0; j < aes_gcm_vectors[i].plaintext_size; j++)
+                        fprintf (stderr, "%.2x:", (int) tmp[j]);
+                    fprintf (stderr, "\n");
+
+                    fprintf (stderr, "Expected[%d]: ",
+                             aes_gcm_vectors[i].plaintext_size);
+                    for (j = 0; j < aes_gcm_vectors[i].plaintext_size; j++)
+                        fprintf (stderr, "%.2x:",
+                                 (int) aes_gcm_vectors[i].ciphertext[j]);
+                    fprintf (stderr, "\n");
+                    return 1;
+                }
+
+          gnutls_cipher_tag (hd, tmp, 16);
+          if (memcmp (tmp, aes_gcm_vectors[i].tag, 16) != 0)
+            {
+                fprintf (stderr, "AES-GCM test vector %d failed (tag)!\n",
+                         i);
+
+                fprintf (stderr, "Tag[%d]: ", 16);
+                for (j = 0; j < 16; j++)
+                    fprintf (stderr, "%.2x:", (int) tmp[j]);
+                fprintf (stderr, "\n");
+
+                fprintf (stderr, "Expected[%d]: ", 16);
+                for (j = 0; j < 16; j++)
+                    fprintf (stderr, "%.2x:",
+                             (int) aes_gcm_vectors[i].tag[j]);
+                fprintf (stderr, "\n");
+                return 1;
+            }
 
-      gnutls_cipher_deinit (hd);
+          gnutls_cipher_deinit (hd);
 
-    }
-  fprintf (stdout, "ok\n");
-  fprintf (stdout, "\n");
+      }
+    fprintf (stdout, "ok\n");
+    fprintf (stdout, "\n");
 
 
-  return 0;
+    return 0;
 
 }
 
 struct hash_vectors_st
 {
-  const char *name;
-  int algorithm;
-  const uint8_t *key;           /* if hmac */
-  int key_size;
-  const uint8_t *plaintext;
-  int plaintext_size;
-  const uint8_t *output;
-  int output_size;
+    const char *name;
+    int algorithm;
+    const uint8_t *key;         /* if hmac */
+    int key_size;
+    const uint8_t *plaintext;
+    int plaintext_size;
+    const uint8_t *output;
+    int output_size;
 } hash_vectors[] =
 {
-  {
-  .name = "SHA1",.algorithm = GNUTLS_MAC_SHA1,.key = NULL,.plaintext =
-      (uint8_t *) "what do ya want for nothing?",.plaintext_size =
-      sizeof ("what do ya want for nothing?") - 1,.output =
-      (uint8_t *)
-      
"\x8f\x82\x03\x94\xf9\x53\x35\x18\x20\x45\xda\x24\xf3\x4d\xe5\x2b\xf8\xbc\x34\x32",.
-      output_size = 20,}
-  ,
-  {
-  .name = "HMAC-MD5",.algorithm = GNUTLS_MAC_MD5,.key =
-      (uint8_t *) "Jefe",.key_size = 4,.plaintext =
-      (uint8_t *) "what do ya want for nothing?",.plaintext_size =
-      sizeof ("what do ya want for nothing?") - 1,.output =
-      (uint8_t *)
-      "\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38",.
-      output_size = 16,}
-  ,
-    /* from rfc4231 */
-  {
-  .name = "HMAC-SHA2-224",.algorithm = GNUTLS_MAC_SHA224,.key =
-      (uint8_t *)
-      
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",.
-      key_size = 20,.plaintext = (uint8_t *) "Hi There",.plaintext_size =
-      sizeof ("Hi There") - 1,.output =
-      (uint8_t *)
-      
"\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22",.
-      output_size = 28,}
-  ,
-  {
-  .name = "HMAC-SHA2-256",.algorithm = GNUTLS_MAC_SHA256,.key =
-      (uint8_t *)
-      
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",.
-      key_size = 20,.plaintext = (uint8_t *) "Hi There",.plaintext_size =
-      sizeof ("Hi There") - 1,.output =
-      (uint8_t *)
-      
"\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32\xcf\xf7",.
-      output_size = 32,}
-  ,
-  {
-  .name = "HMAC-SHA2-384",.algorithm = GNUTLS_MAC_SHA384,.key =
-      (uint8_t *)
-      
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",.
-      key_size = 20,.plaintext = (uint8_t *) "Hi There",.plaintext_size =
-      sizeof ("Hi There") - 1,.output =
-      (uint8_t *)
-      
"\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2\xfa\x9c\xb6",.
-      output_size = 48,}
-  ,
-  {
-  .name = "HMAC-SHA2-512",.algorithm = GNUTLS_MAC_SHA512,.key =
-      (uint8_t *)
-      
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",.
-      key_size = 20,.plaintext = (uint8_t *) "Hi There",.plaintext_size =
-      sizeof ("Hi There") - 1,.output =
-      (uint8_t *)
-      
"\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c\xb0\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1\x7c\xde\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae\xa3\xf4\xe4\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20\x3a\x12\x68\x54",.
-      output_size = 64,}
+    {
+      .name = "SHA1",
+      .algorithm = GNUTLS_MAC_SHA1,
+      .key = NULL,
+      .plaintext =
+            (uint8_t *) "what do ya want for nothing?",
+      .plaintext_size =
+            sizeof ("what do ya want for nothing?") - 1,
+      .output =
+            (uint8_t *)
+            
"\x8f\x82\x03\x94\xf9\x53\x35\x18\x20\x45\xda\x24\xf3\x4d\xe5\x2b\xf8\xbc\x34\x32",
+      .output_size = 20,
+    },
+    {
+      .name = "SHA1",
+      .algorithm = GNUTLS_MAC_SHA1,
+      .key = NULL,
+      .plaintext =
+            (uint8_t *)
+            
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+      .plaintext_size = sizeof
+            
("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
+            - 1,
+      .output =
+            (uint8_t *)
+            
"\xbe\xae\xd1\x6d\x65\x8e\xc7\x92\x9e\xdf\xd6\x2b\xfa\xfe\xac\x29\x9f\x0d\x74\x4d",
+      .output_size = 20,
+    },
+    {
+      .name = "SHA256",
+      .algorithm = GNUTLS_MAC_SHA256,
+      .key = NULL,
+      .plaintext =
+            (uint8_t *)
+            "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+      .plaintext_size = sizeof
+            ("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
+            - 1,
+      .output =
+            (uint8_t *)
+            
"\x24\x8d\x6a\x61\xd2\x06\x38\xb8\xe5\xc0\x26\x93\x0c\x3e\x60\x39\xa3\x3c\xe4\x59\x64\xff\x21\x67\xf6\xec\xed\xd4\x19\xdb\x06\xc1",
+      .output_size = 32,
+    },
+    {
+      .name = "SHA256",
+      .algorithm = GNUTLS_MAC_SHA256,
+      .key = NULL,
+      .plaintext =
+            (uint8_t *)
+            
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
+      .plaintext_size = sizeof
+            
("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq")
+            - 1,
+      .output =
+            (uint8_t *)
+            
"\x50\xea\x82\x5d\x96\x84\xf4\x22\x9c\xa2\x9f\x1f\xec\x51\x15\x93\xe2\x81\xe4\x6a\x14\x0d\x81\xe0\x00\x5f\x8f\x68\x86\x69\xa0\x6c",
+      .output_size = 32,
+    },
+    {
+      .name = "SHA512",
+      .algorithm = GNUTLS_MAC_SHA512,
+      .key = NULL,
+      .plaintext =
+            (uint8_t *)
+            
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu",
+      .plaintext_size = sizeof
+            
("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu")
+            - 1,
+      .output =
+            (uint8_t *)
+            
"\x8e\x95\x9b\x75\xda\xe3\x13\xda\x8c\xf4\xf7\x28\x14\xfc\x14\x3f\x8f\x77\x79\xc6\xeb\x9f\x7f\xa1\x72\x99\xae\xad\xb6\x88\x90\x18\x50\x1d\x28\x9e\x49\x00\xf7\xe4\x33\x1b\x99\xde\xc4\xb5\x43\x3a\xc7\xd3\x29\xee\xb6\xdd\x26\x54\x5e\x96\xe5\x5b\x87\x4b\xe9\x09",
+      .output_size = 64,
+    },
+    {
+    .name = "HMAC-MD5",.algorithm = GNUTLS_MAC_MD5,.key =
+            (uint8_t *) "Jefe",.key_size = 4,.plaintext =
+            (uint8_t *) "what do ya want for nothing?",.
+            plaintext_size =
+            sizeof ("what do ya want for nothing?") - 1,.output =
+            (uint8_t *)
+            
"\x75\x0c\x78\x3e\x6a\xb0\xb5\x03\xea\xa8\x6e\x31\x0a\x5d\xb7\x38",.output_size
+            = 16,}
+    ,
+        /* from rfc4231 */
+    {
+    .name = "HMAC-SHA2-224",.algorithm = GNUTLS_MAC_SHA224,.key =
+            (uint8_t *)
+            
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",.key_size
+            = 20,.plaintext = (uint8_t *) "Hi There",.plaintext_size =
+            sizeof ("Hi There") - 1,.output =
+            (uint8_t *)
+            
"\x89\x6f\xb1\x12\x8a\xbb\xdf\x19\x68\x32\x10\x7c\xd4\x9d\xf3\x3f\x47\xb4\xb1\x16\x99\x12\xba\x4f\x53\x68\x4b\x22",.output_size
+            = 28,}
+    ,
+    {
+    .name = "HMAC-SHA2-256",.algorithm = GNUTLS_MAC_SHA256,.key =
+            (uint8_t *)
+            
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",.key_size
+            = 20,.plaintext = (uint8_t *) "Hi There",.plaintext_size =
+            sizeof ("Hi There") - 1,.output =
+            (uint8_t *)
+            
"\xb0\x34\x4c\x61\xd8\xdb\x38\x53\x5c\xa8\xaf\xce\xaf\x0b\xf1\x2b\x88\x1d\xc2\x00\xc9\x83\x3d\xa7\x26\xe9\x37\x6c\x2e\x32\xcf\xf7",.output_size
+            = 32,}
+    ,
+    {
+    .name = "HMAC-SHA2-384",.algorithm = GNUTLS_MAC_SHA384,.key =
+            (uint8_t *)
+            
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",.key_size
+            = 20,.plaintext = (uint8_t *) "Hi There",.plaintext_size =
+            sizeof ("Hi There") - 1,.output =
+            (uint8_t *)
+            
"\xaf\xd0\x39\x44\xd8\x48\x95\x62\x6b\x08\x25\xf4\xab\x46\x90\x7f\x15\xf9\xda\xdb\xe4\x10\x1e\xc6\x82\xaa\x03\x4c\x7c\xeb\xc5\x9c\xfa\xea\x9e\xa9\x07\x6e\xde\x7f\x4a\xf1\x52\xe8\xb2\xfa\x9c\xb6",.output_size
+            = 48,}
+    ,
+    {
+    .name = "HMAC-SHA2-512",.algorithm = GNUTLS_MAC_SHA512,.key =
+            (uint8_t *)
+            
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b",.key_size
+            = 20,.plaintext = (uint8_t *) "Hi There",.plaintext_size =
+            sizeof ("Hi There") - 1,.output =
+            (uint8_t *)
+            
"\x87\xaa\x7c\xde\xa5\xef\x61\x9d\x4f\xf0\xb4\x24\x1a\x1d\x6c\xb0\x23\x79\xf4\xe2\xce\x4e\xc2\x78\x7a\xd0\xb3\x05\x45\xe1\x7c\xde\xda\xa8\x33\xb7\xd6\xb8\xa7\x02\x03\x8b\x27\x4e\xae\xa3\xf4\xe4\xbe\x9d\x91\x4e\xeb\x61\xf1\x70\x2e\x69\x6c\x20\x3a\x12\x68\x54",.output_size
+            = 64,}
 ,};
 
 #define HASH_DATA_SIZE 64
@@ -390,93 +480,150 @@ struct hash_vectors_st
 static int
 test_hash (void)
 {
-  uint8_t data[HASH_DATA_SIZE];
-  int i, j, ret;
-  size_t data_size;
+    uint8_t data[HASH_DATA_SIZE];
+    int i, j, ret;
+    size_t data_size;
 
-  fprintf (stdout, "Tests on Hashes\n");
-  for (i = 0; i < sizeof (hash_vectors) / sizeof (hash_vectors[0]); i++)
-    {
+    fprintf (stdout, "Tests on Hashes\n");
+    for (i = 0; i < sizeof (hash_vectors) / sizeof (hash_vectors[0]); i++)
+      {
 
-      fprintf (stdout, "\t%s: ", hash_vectors[i].name);
-      /* import key */
-      if (hash_vectors[i].key != NULL)
-        {
-
-          ret = gnutls_hmac_fast (hash_vectors[i].algorithm,
-                                  hash_vectors[i].key,
-                                  hash_vectors[i].key_size,
-                                  hash_vectors[i].plaintext,
-                                  hash_vectors[i].plaintext_size, data);
-          data_size = gnutls_hmac_get_len (hash_vectors[i].algorithm);
-          if (ret < 0)
+          fprintf (stdout, "\t%s: ", hash_vectors[i].name);
+          /* import key */
+          if (hash_vectors[i].key != NULL)
             {
-              fprintf (stderr, "Error: %s:%d\n", __func__, __LINE__);
-              return 1;
+                gnutls_hmac_hd_t hd;
+                ret = gnutls_hmac_init( &hd, hash_vectors[i].algorithm, 
hash_vectors[i].key, hash_vectors[i].key_size);
+                if (ret < 0)
+                  {
+                      fprintf (stderr, "Error: %s:%d\n", __func__,
+                               __LINE__);
+                      return 1;
+                  }
+
+                ret = gnutls_hmac(hd, hash_vectors[i].plaintext, 
hash_vectors[i].plaintext_size-1);
+                if (ret < 0)
+                  {
+                      fprintf (stderr, "Error: %s:%d\n", __func__,
+                               __LINE__);
+                      return 1;
+                  }
+
+                ret = gnutls_hmac(hd, 
&hash_vectors[i].plaintext[hash_vectors[i].plaintext_size-1], 1);
+                if (ret < 0)
+                  {
+                      fprintf (stderr, "Error: %s:%d\n", __func__,
+                               __LINE__);
+                      return 1;
+                  }
+
+                gnutls_hmac_output(hd, data);
+                gnutls_hmac_deinit(hd, NULL);
+
+                data_size =
+                    gnutls_hmac_get_len (hash_vectors[i].algorithm);
+                if (ret < 0)
+                  {
+                      fprintf (stderr, "Error: %s:%d\n", __func__,
+                               __LINE__);
+                      return 1;
+                  }
             }
-        }
-      else
-        {
-          ret = gnutls_hash_fast (hash_vectors[i].algorithm,
-                                  hash_vectors[i].plaintext,
-                                  hash_vectors[i].plaintext_size, data);
-          data_size = gnutls_hash_get_len (hash_vectors[i].algorithm);
-          if (ret < 0)
+          else
             {
-              fprintf (stderr, "Error: %s:%d\n", __func__, __LINE__);
-              return 1;
+                gnutls_hash_hd_t hd;
+                ret = gnutls_hash_init( &hd, hash_vectors[i].algorithm);
+                if (ret < 0)
+                  {
+                      fprintf (stderr, "Error: %s:%d\n", __func__,
+                               __LINE__);
+                      return 1;
+                  }
+                
+                ret = gnutls_hash (hd,
+                                        hash_vectors[i].plaintext,
+                                        1);
+                if (ret < 0)
+                  {
+                      fprintf (stderr, "Error: %s:%d\n", __func__,
+                               __LINE__);
+                      return 1;
+                  }
+
+                ret = gnutls_hash (hd,
+                                        &hash_vectors[i].plaintext[1],
+                                        hash_vectors[i].plaintext_size-1);
+                if (ret < 0)
+                  {
+                      fprintf (stderr, "Error: %s:%d\n", __func__,
+                               __LINE__);
+                      return 1;
+                  }
+
+                gnutls_hash_output(hd, data);
+                gnutls_hash_deinit(hd, NULL);
+                
+                data_size =
+                    gnutls_hash_get_len (hash_vectors[i].algorithm);
+                if (ret < 0)
+                  {
+                      fprintf (stderr, "Error: %s:%d\n", __func__,
+                               __LINE__);
+                      return 1;
+                  }
             }
-        }
-
-      if (data_size != hash_vectors[i].output_size ||
-          memcmp (data, hash_vectors[i].output,
-                  hash_vectors[i].output_size) != 0)
-        {
-          fprintf (stderr, "HASH test vector %d failed!\n", i);
 
-          fprintf (stderr, "Output[%d]: ", (int) data_size);
-          for (j = 0; j < data_size; j++)
-            fprintf (stderr, "%.2x:", (int) data[j]);
-          fprintf (stderr, "\n");
-
-          fprintf (stderr, "Expected[%d]: ", hash_vectors[i].output_size);
-          for (j = 0; j < hash_vectors[i].output_size; j++)
-            fprintf (stderr, "%.2x:", (int) hash_vectors[i].output[j]);
-          fprintf (stderr, "\n");
-          return 1;
-        }
+          if (data_size != hash_vectors[i].output_size ||
+              memcmp (data, hash_vectors[i].output,
+                      hash_vectors[i].output_size) != 0)
+            {
+                fprintf (stderr, "HASH test vector %d failed!\n", i);
+
+                fprintf (stderr, "Output[%d]: ", (int) data_size);
+                for (j = 0; j < data_size; j++)
+                    fprintf (stderr, "%.2x:", (int) data[j]);
+                fprintf (stderr, "\n");
+
+                fprintf (stderr, "Expected[%d]: ",
+                         hash_vectors[i].output_size);
+                for (j = 0; j < hash_vectors[i].output_size; j++)
+                    fprintf (stderr, "%.2x:",
+                             (int) hash_vectors[i].output[j]);
+                fprintf (stderr, "\n");
+                return 1;
+            }
 
-      fprintf (stdout, "ok\n");
-    }
+          fprintf (stdout, "ok\n");
+      }
 
-  fprintf (stdout, "\n");
+    fprintf (stdout, "\n");
 
-  return 0;
+    return 0;
 
 }
 
 static void
 tls_log_func (int level, const char *str)
 {
-  fprintf (stderr, "<%d>| %s", level, str);
+    fprintf (stderr, "<%d>| %s", level, str);
 }
 
 
 int
 main (int argc, char **argv)
 {
-  gnutls_global_set_log_function (tls_log_func);
-  if (argc > 1)
-    gnutls_global_set_log_level (4711);
+    gnutls_global_set_log_function (tls_log_func);
+    if (argc > 1)
+        gnutls_global_set_log_level (4711);
 
-  gnutls_global_init ();
+    gnutls_global_init ();
 
-  if (test_aes ())
-    return 1;
+    if (test_aes ())
+        return 1;
 
-  if (test_hash ())
-    return 1;
+    if (test_hash ())
+        return 1;
 
-  gnutls_global_deinit ();
-  return 0;
+    gnutls_global_deinit ();
+    return 0;
 }
diff --git a/tests/cve-2009-1416.c b/tests/cve-2009-1416.c
index faa5d1d..addc3cb 100644
--- a/tests/cve-2009-1416.c
+++ b/tests/cve-2009-1416.c
@@ -71,8 +71,6 @@ main (void)
       printf ("buggy\n");
       return 1;
     }
-  else
-    printf ("success!\n");
 
   gnutls_free (p.data);
   gnutls_free (q.data);
diff --git a/tests/dsa/testdsa b/tests/dsa/testdsa
index 3d6a2f0..dc485ec 100755
--- a/tests/dsa/testdsa
+++ b/tests/dsa/testdsa
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright (C) 2010 Free Software Foundation, Inc.
+# Copyright (C) 2010-2011 Free Software Foundation, Inc.
 #
 # Author: Nikos Mavrogiannopoulos
 #
@@ -31,7 +31,7 @@ if test "${WINDIR}" != "";then
   exit 77
 fi 
 
-. ../scripts/common.sh
+. $srcdir/../scripts/common.sh
 
 echo "Checking various DSA key sizes"
 
diff --git a/tests/libgcrypt.supp b/tests/libgcrypt.supp
deleted file mode 100644
index 3766b25..0000000
--- a/tests/libgcrypt.supp
+++ /dev/null
@@ -1,187 +0,0 @@
-# libgcrypt.supp -- Valgrind suppresion file for libgcrypt
-
-# Copyright (C) 2008, 2009, 2010  Free Software Foundation, Inc.
-
-# Copying and distribution of this file, with or without modification,
-# are permitted in any medium without royalty provided the copyright
-# notice and this notice are preserved.
-
-{
-   libgcrypt1
-   Memcheck:Leak
-   fun:malloc
-   fun:_gcry_private_malloc
-   fun:do_malloc
-   fun:_gcry_malloc
-   fun:_gcry_module_add
-   fun:gcry_pk_register_default
-   fun:_gcry_pk_init
-   fun:global_init
-   fun:_gcry_check_version
-   fun:gcry_check_version
-   fun:gnutls_global_init
-}
-
-{
-   libgcrypt1-new
-   Memcheck:Leak
-   fun:malloc
-   fun:_gcry_private_malloc
-   fun:do_malloc
-   fun:_gcry_malloc
-   fun:_gcry_module_add
-   fun:pk_register_default
-   fun:_gcry_pk_init
-   fun:global_init
-   fun:_gcry_check_version
-   fun:gcry_check_version
-   fun:gnutls_global_init
-}
-
-{
-   libgcrypt2
-   Memcheck:Leak
-   fun:malloc
-   fun:_gcry_private_malloc
-   fun:do_malloc
-   fun:_gcry_malloc
-   fun:_gcry_module_add
-   fun:gcry_md_register_default
-   fun:_gcry_md_init
-   fun:global_init
-   fun:_gcry_check_version
-   fun:gcry_check_version
-   fun:gnutls_global_init
-}
-
-{
-   libgcrypt2-new
-   Memcheck:Leak
-   fun:malloc
-   fun:_gcry_private_malloc
-   fun:do_malloc
-   fun:_gcry_malloc
-   fun:_gcry_module_add
-   fun:md_register_default
-   fun:_gcry_md_init
-   fun:global_init
-   fun:_gcry_check_version
-   fun:gcry_check_version
-   fun:gnutls_global_init
-}
-
-{
-   libgcrypt3
-   Memcheck:Leak
-   fun:malloc
-   fun:_gcry_private_malloc
-   fun:do_malloc
-   fun:_gcry_malloc
-   fun:_gcry_module_add
-   fun:gcry_cipher_register_default
-   fun:_gcry_cipher_init
-   fun:global_init
-   fun:_gcry_check_version
-   fun:gcry_check_version
-   fun:gnutls_global_init
-}
-
-{
-   libgcrypt3-new
-   Memcheck:Leak
-   fun:malloc
-   fun:_gcry_private_malloc
-   fun:do_malloc
-   fun:_gcry_malloc
-   fun:_gcry_module_add
-   fun:cipher_register_default
-   fun:_gcry_cipher_init
-   fun:global_init
-   fun:_gcry_check_version
-   fun:gcry_check_version
-   fun:gnutls_global_init
-}
-
-{
-   libgcrypt4
-   Memcheck:Leak
-   fun:malloc
-   fun:do_malloc
-   fun:_gcry_malloc
-   fun:_gcry_xmalloc
-   fun:_gcry_xcalloc
-   fun:initialize
-   fun:_gcry_randomize
-   fun:gcry_randomize
-   fun:gc_pseudo_random
-   fun:_gnutls_rnd_init
-   fun:gnutls_global_init
-}
-
-{
-   libgcrypt5
-   Memcheck:Leak
-   fun:malloc
-   fun:_gcry_private_malloc
-   fun:do_malloc
-   fun:_gcry_malloc
-   fun:_gcry_xmalloc
-   fun:_gcry_xcalloc
-   fun:initialize
-   fun:_gcry_randomize
-   fun:gcry_randomize
-   fun:gc_pseudo_random
-   fun:_gnutls_rnd_init
-   fun:gnutls_global_init
-}
-
-{
-   libgcrypt6
-   Memcheck:Leak
-   fun:malloc
-   fun:do_malloc
-   fun:_gcry_malloc
-   fun:_gcry_xmalloc
-   fun:_gcry_xcalloc
-   fun:initialize
-   fun:_gcry_create_nonce
-   fun:gcry_create_nonce
-   fun:wrap_gcry_rnd_init
-   fun:_gnutls_rnd_init
-   fun:gnutls_global_init
-}
-
-{
-   libgcrypt7
-   Memcheck:Leak
-   fun:malloc
-   fun:_gcry_private_malloc
-   fun:do_malloc
-   fun:_gcry_malloc
-   fun:_gcry_xmalloc
-   fun:_gcry_xcalloc
-   fun:initialize
-   fun:_gcry_create_nonce
-   fun:gcry_create_nonce
-   fun:wrap_gcry_rnd_init
-   fun:_gnutls_rnd_init
-   fun:gnutls_global_init
-}
-
-{
-   libgcrypt7-new
-   Memcheck:Leak
-   fun:malloc
-   fun:_gcry_private_malloc
-   fun:do_malloc
-   fun:_gcry_malloc
-   fun:_gcry_xmalloc
-   fun:_gcry_xcalloc
-   fun:initialize
-   fun:_gcry_rngcsprng_create_nonce
-   fun:_gcry_create_nonce
-   fun:gcry_create_nonce
-   fun:wrap_gcry_rnd_init
-   fun:_gnutls_rnd_init
-   fun:gnutls_global_init
-}
diff --git a/tests/mpi.c b/tests/mpi.c
index 23289de..fdef519 100644
--- a/tests/mpi.c
+++ b/tests/mpi.c
@@ -83,5 +83,5 @@ doit (void)
   _gnutls_mpi_release (&n3);
   _gnutls_mpi_release (&n4);
 
-  success ("mpi ops ok\n");
+  if (debug) success ("mpi ops ok\n");
 }
diff --git a/tests/nist-pkits/build-chain b/tests/nist-pkits/build-chain
index 6a125ca..e625a8c 100755
--- a/tests/nist-pkits/build-chain
+++ b/tests/nist-pkits/build-chain
@@ -1,4 +1,6 @@
-#!/usr/bin/perl
+eval '(exit $?0)' && eval 'exec perl -wST "$0" ${1+"$@"}'
+  & eval 'exec perl -wST "$0" $argv:q'
+    if 0;
 
 use strict;
 
diff --git a/tests/openpgp-certs/testcerts b/tests/openpgp-certs/testcerts
index 3a3afad..d9cb2f6 100755
--- a/tests/openpgp-certs/testcerts
+++ b/tests/openpgp-certs/testcerts
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright (C) 2010 Free Software Foundation, Inc.
+# Copyright (C) 2010-2011 Free Software Foundation, Inc.
 #
 # Author: Nikos Mavrogiannopoulos
 #
@@ -31,7 +31,7 @@ if test "${WINDIR}" != "";then
   exit 77
 fi 
 
-. ../scripts/common.sh
+. $srcdir/../scripts/common.sh
 
 echo "Checking OpenPGP certificate verification"
 
diff --git a/tests/openpgp-keyring.c b/tests/openpgp-keyring.c
index 9095ed8..f3cf1f2 100644
--- a/tests/openpgp-keyring.c
+++ b/tests/openpgp-keyring.c
@@ -26,7 +26,6 @@
 #include <stdio.h>
 
 #include <gnutls/gnutls.h>
-#include <gnutls/extra.h>
 #include <gnutls/openpgp.h>
 
 #include "utils.h"
@@ -202,10 +201,6 @@ doit (void)
   if (debug)
     gnutls_global_set_log_level (2);
 
-  ret = gnutls_global_init_extra ();
-  if (ret < 0)
-    fail ("extra-init %d\n", ret);
-
   ret = gnutls_openpgp_keyring_init (&keyring);
   if (ret < 0)
     fail ("keyring-init %d\n", ret);
diff --git a/tests/pathlen/ca-no-pathlen.pem b/tests/pathlen/ca-no-pathlen.pem
index 9d39578..bbc0494 100644
--- a/tests/pathlen/ca-no-pathlen.pem
+++ b/tests/pathlen/ca-no-pathlen.pem
@@ -33,7 +33,7 @@ Other Information:
        SHA-1 fingerprint:
                f3ddd5478b80b142200b50c9eb2ee37061b09ed6
        Public Key Id:
-               5699601fb02430e8c247b86e4ef997e0915e131b
+               f268df0e814c0302ed338e146f57421dba44f06c
 
 -----BEGIN CERTIFICATE-----
 MIIBYDCCAQygAwIBAgIBADALBgkqhkiG9w0BAQUwIjEgMB4GA1UEChMXR251VExT
diff --git a/tests/pathlen/no-ca-or-pathlen.pem 
b/tests/pathlen/no-ca-or-pathlen.pem
index 8e9f682..9581eb2 100644
--- a/tests/pathlen/no-ca-or-pathlen.pem
+++ b/tests/pathlen/no-ca-or-pathlen.pem
@@ -51,7 +51,7 @@ Other Information:
        SHA-1 fingerprint:
                8f735c5ddefd723f59b6a3bb2ac0522470c0182f
        Public Key Id:
-               678c03ba9250a094d1465ae3c90dc605e22110d3
+               1e09d707d4e3651b84dcb6c68a828d2affef7ec3
 
 -----BEGIN CERTIFICATE-----
 MIIEhDCCA+2gAwIBAgIQLhA3A99GhZ16VQ2mWWGFODANBgkqhkiG9w0BAQQFADCB
diff --git a/tests/rng-fork.c b/tests/rng-fork.c
index 5b086b9..7bbb5a4 100644
--- a/tests/rng-fork.c
+++ b/tests/rng-fork.c
@@ -97,8 +97,8 @@ doit (void)
           fail("error in the random generator. Produces same valus after 
fork()");
           return;
         }
-      
-      success("success");
+      if(debug)
+        success("success\n");
     }
 }
 #else
diff --git a/tests/rsa-md5-collision/README b/tests/rsa-md5-collision/README
index 98892d6..be0772a 100644
--- a/tests/rsa-md5-collision/README
+++ b/tests/rsa-md5-collision/README
@@ -1,5 +1,5 @@
 rsa-md5-collision README -- Information about rsa-md5-collision self tests.
-Copyright (C) 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
+Copyright (C) 2006-2011  Free Software Foundation, Inc.
 See the end for copying conditions.
 
 This directory contains colliding X.509 certificates for different
@@ -37,7 +37,7 @@ Xref: localhost.localdomain rsa-md5:1
 Great work, thanks!
 
 I'd like to include your certificates in GnuTLS, a TLS implementation
-that supports X.509, as self-tests of the the certificate verification
+that supports X.509, as self-tests of the certificate verification
 logic.  Is this OK with you?
 
 Btw, Gnutls rejected the certificates, we already disable MD5 for
@@ -152,7 +152,7 @@ identities
 Great work, thanks!
 
 I'd like to include your certificates in GnuTLS, a TLS implementation
-that supports X.509, as self-tests of the the certificate verification
+that supports X.509, as self-tests of the certificate verification
 logic.  Is this OK with you?
 
 Btw, Gnutls rejected the certificates, we already disable MD5 for
@@ -254,7 +254,7 @@ Benne also replied.
 > Great work, thanks!
 >
 > I'd like to include your certificates in GnuTLS, a TLS implementation
-> that supports X.509, as self-tests of the the certificate verification
+> that supports X.509, as self-tests of the certificate verification
 > logic.  Is this OK with you?
 >
 > Btw, Gnutls rejected the certificates, we already disable MD5 for
@@ -402,7 +402,7 @@ identities
 >> Great work, thanks!
 >>
 >> I'd like to include your certificates in GnuTLS, a TLS implementation
->> that supports X.509, as self-tests of the the certificate verification
+>> that supports X.509, as self-tests of the certificate verification
 >> logic.  Is this OK with you?
 >>
 >> Btw, Gnutls rejected the certificates, we already disable MD5 for
@@ -565,7 +565,7 @@ www:    http://www.win.tue.nl/~bdeweger
 > >
 > > I'd like to include your certificates in GnuTLS, a TLS=20
 > implementation
-> > that supports X.509, as self-tests of the the certificate=20
+> > that supports X.509, as self-tests of the certificate=20
 > verification
 > > logic.  Is this OK with you?
 > >
diff --git a/tests/safe-renegotiation/Makefile.am 
b/tests/safe-renegotiation/Makefile.am
index 8b0c658..17d4684 100644
--- a/tests/safe-renegotiation/Makefile.am
+++ b/tests/safe-renegotiation/Makefile.am
@@ -32,4 +32,4 @@ check_PROGRAMS = $(ctests)
 TESTS = $(ctests)
 TESTS_ENVIRONMENT = $(VALGRIND)
 
-EXTRA_DIST = README
+EXTRA_DIST = README suppressions.valgrind
diff --git a/doc/reference/gnutls.types 
b/tests/safe-renegotiation/suppressions.valgrind
similarity index 100%
copy from doc/reference/gnutls.types
copy to tests/safe-renegotiation/suppressions.valgrind
diff --git a/tests/suite/Makefile.am b/tests/suite/Makefile.am
index 6113a70..a88abc6 100644
--- a/tests/suite/Makefile.am
+++ b/tests/suite/Makefile.am
@@ -1,8 +1,5 @@
 ## Process this file with automake to produce Makefile.in
-# Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
-# Foundation, Inc.
-#
-# Author: Simon Josefsson
+# Copyright (C) 2004-2011 Free Software Foundation, Inc.
 #
 # This file is part of GnuTLS.
 #
@@ -26,8 +23,8 @@ AM_CPPFLAGS = \
        -I$(top_builddir)/gl                    \
        -I$(top_srcdir)/lib/includes            \
        -I$(top_builddir)/lib/includes          \
-       -I$(top_srcdir)/libextra/includes       \
-       -I$(top_builddir)/libextra/includes     \
+       -I$(top_srcdir)/extra/includes  \
+       -I$(top_builddir)/extra/includes        \
        -I$(top_srcdir)/lib                     \
        -I$(top_srcdir)/doc/examples    \
        -I$(top_srcdir)/tests/suite/ecore/src/include \
@@ -40,32 +37,49 @@ LDADD = ../../lib/libgnutls.la \
        $(LTLIBGCRYPT)  \
        $(LIBSOCKET) $(INET_NTOP_LIB) $(INET_PTON_LIB)
 
-noinst_LTLIBRARIES = libecore.la                                               
                                                                                
                                                                                
                   
+noinst_LTLIBRARIES = libecore.la
+
+libecore_la_CPPFLAGS = -I$(top_srcdir)/tests/suite/ecore/              \
+       -I$(top_srcdir)/tests/suite/ecore/src/include                   \
+       -I$(top_srcdir)/tests/suite/ecore/src/lib -DHAVE_CONFIG_H       \
+       -D__UNUSED__= -DVMAJ=1 -D VMIC=0 -DVMIN=0 -DVREV=0              \
+       -DEFL_HAVE_POSIX_THREADS=1 -DEFL_HAVE_POSIX_THREADS_SPINLOCK=1  \
+       -DEFL_HAVE_THREADS=1 -DEINA_BUILD_CHAINED_POOL=1                \
+       -DEINA_STATIC_BUILD_CHAINED_POOL=1 -DHAVE_CLOCK_GETTIME         \
+       -DHAVE_GETTIMEOFDAY -DPACKAGE_LIB_DIR=\"/usr/lib\"              \
+       -DMODULE_ARCH=\"unix\" -DSHARED_LIB_SUFFIX=\".so\"
 
-libecore_la_CPPFLAGS = -I$(top_srcdir)/tests/suite/ecore/ 
-I$(top_srcdir)/tests/suite/ecore/src/include \
-       -I$(top_srcdir)/tests/suite/ecore/src/lib -DHAVE_CONFIG_H -D__UNUSED__= 
-DVMAJ=1 \
-       -D VMIC=0 -DVMIN=0 -DVREV=0 -DEFL_HAVE_POSIX_THREADS=1 
-DEFL_HAVE_POSIX_THREADS_SPINLOCK=1 \
-       -DEFL_HAVE_THREADS=1 -DEINA_BUILD_CHAINED_POOL=1 
-DEINA_STATIC_BUILD_CHAINED_POOL=1 \
-       -DHAVE_CLOCK_GETTIME -DHAVE_GETTIMEOFDAY -DPACKAGE_LIB_DIR=\"/usr/lib\" 
-DMODULE_ARCH=\"unix\" \
-       -DSHARED_LIB_SUFFIX=\".so\"
 libecore_la_CFLAGS = -w
-nodist_libecore_la_SOURCES = ecore/src/lib/ecore_anim.c 
ecore/src/lib/ecore_app.c \
-       ecore/src/lib/ecore.c ecore/src/lib/ecore_events.c 
ecore/src/lib/ecore_exe.c \
-       ecore/src/lib/ecore_getopt.c ecore/src/lib/ecore_glib.c 
ecore/src/lib/ecore_idle_enterer.c \
-       ecore/src/lib/ecore_idle_exiter.c ecore/src/lib/ecore_idler.c 
ecore/src/lib/ecore_job.c \
-       ecore/src/lib/ecore_main.c ecore/src/lib/ecore_pipe.c 
ecore/src/lib/ecore_poll.c \
-       ecore/src/lib/ecore_signal.c ecore/src/lib/ecore_thread.c 
ecore/src/lib/ecore_time.c \
-       ecore/src/lib/ecore_timer.c ecore/src/lib/eina_accessor.c 
ecore/src/lib/eina_array.c \
-       ecore/src/lib/eina_benchmark.c ecore/src/lib/eina_binshare.c 
ecore/src/lib/eina_chained_mempool.c \
-       ecore/src/lib/eina_convert.c ecore/src/lib/eina_counter.c 
ecore/src/lib/eina_cpu.c ecore/src/lib/eina_error.c \
-       ecore/src/lib/eina_file.c ecore/src/lib/eina_fp.c 
ecore/src/lib/eina_hamster.c ecore/src/lib/eina_hash.c \
-       ecore/src/lib/eina_inlist.c ecore/src/lib/eina_iterator.c 
ecore/src/lib/eina_lalloc.c ecore/src/lib/eina_list.c \
-       ecore/src/lib/eina_log.c ecore/src/lib/eina_magic.c 
ecore/src/lib/eina_main.c ecore/src/lib/eina_matrixsparse.c \
-       ecore/src/lib/eina_mempool.c ecore/src/lib/eina_module.c 
ecore/src/lib/eina_quadtree.c ecore/src/lib/eina_rbtree.c \
-       ecore/src/lib/eina_rectangle.c ecore/src/lib/eina_safety_checks.c 
ecore/src/lib/eina_sched.c ecore/src/lib/eina_share_common.c \
-       ecore/src/lib/eina_strbuf.c ecore/src/lib/eina_strbuf_common.c 
ecore/src/lib/eina_str.c \
-       ecore/src/lib/eina_stringshare.c ecore/src/lib/eina_tiler.c 
ecore/src/lib/eina_unicode.c \
-       ecore/src/lib/eina_ustrbuf.c ecore/src/lib/eina_ustringshare.c 
ecore/src/lib/eina_value.c
+nodist_libecore_la_SOURCES = ecore/src/lib/ecore_anim.c                        
\
+       ecore/src/lib/ecore_app.c ecore/src/lib/ecore.c                 \
+       ecore/src/lib/ecore_events.c ecore/src/lib/ecore_exe.c          \
+       ecore/src/lib/ecore_getopt.c ecore/src/lib/ecore_glib.c         \
+       ecore/src/lib/ecore_idle_enterer.c                              \
+       ecore/src/lib/ecore_idle_exiter.c ecore/src/lib/ecore_idler.c   \
+       ecore/src/lib/ecore_job.c ecore/src/lib/ecore_main.c            \
+       ecore/src/lib/ecore_pipe.c ecore/src/lib/ecore_poll.c           \
+       ecore/src/lib/ecore_signal.c ecore/src/lib/ecore_thread.c       \
+       ecore/src/lib/ecore_time.c ecore/src/lib/ecore_timer.c          \
+       ecore/src/lib/eina_accessor.c ecore/src/lib/eina_array.c        \
+       ecore/src/lib/eina_benchmark.c ecore/src/lib/eina_binshare.c    \
+       ecore/src/lib/eina_chained_mempool.c                            \
+       ecore/src/lib/eina_convert.c ecore/src/lib/eina_counter.c       \
+       ecore/src/lib/eina_cpu.c ecore/src/lib/eina_error.c             \
+       ecore/src/lib/eina_file.c ecore/src/lib/eina_fp.c               \
+       ecore/src/lib/eina_hamster.c ecore/src/lib/eina_hash.c          \
+       ecore/src/lib/eina_inlist.c ecore/src/lib/eina_iterator.c       \
+       ecore/src/lib/eina_lalloc.c ecore/src/lib/eina_list.c           \
+       ecore/src/lib/eina_log.c ecore/src/lib/eina_magic.c             \
+       ecore/src/lib/eina_main.c ecore/src/lib/eina_matrixsparse.c     \
+       ecore/src/lib/eina_mempool.c ecore/src/lib/eina_module.c        \
+       ecore/src/lib/eina_quadtree.c ecore/src/lib/eina_rbtree.c       \
+       ecore/src/lib/eina_rectangle.c                                  \
+       ecore/src/lib/eina_safety_checks.c ecore/src/lib/eina_sched.c   \
+       ecore/src/lib/eina_share_common.c ecore/src/lib/eina_strbuf.c   \
+       ecore/src/lib/eina_strbuf_common.c ecore/src/lib/eina_str.c     \
+       ecore/src/lib/eina_stringshare.c ecore/src/lib/eina_tiler.c     \
+       ecore/src/lib/eina_unicode.c ecore/src/lib/eina_ustrbuf.c       \
+       ecore/src/lib/eina_ustringshare.c ecore/src/lib/eina_value.c
 
 eagain_cli_LDADD = $(LDADD) libecore.la -lrt -lm -ldl -lpthread
 nodist_eagain_cli_SOURCES = mini-eagain2.c
@@ -75,4 +89,3 @@ noinst_PROGRAMS = eagain-cli
 nodist_check_SCRIPTS = eagain testsrn testcompat chain
 
 TESTS = eagain testsrn testcompat chain
-
diff --git a/tests/suite/testcompat-main b/tests/suite/testcompat-main
index d08e52f..557a39a 100755
--- a/tests/suite/testcompat-main
+++ b/tests/suite/testcompat-main
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright (C) 2010 Free Software Foundation, Inc.
+# Copyright (C) 2010-2011 Free Software Foundation, Inc.
 #
 # Author: Nikos Mavrogiannopoulos
 #
@@ -29,7 +29,7 @@ if test "${WINDIR}" != "";then
   exit 77
 fi 
 
-. ../scripts/common.sh
+. $srcdir/../scripts/common.sh
 
 SERV=openssl
 OPENSSL_CLI="openssl"
@@ -87,6 +87,19 @@ $CLI $DEBUG -p $PORT 127.0.0.1 --priority 
"NONE:+CIPHER-ALL:+SIGN-ALL:+COMP-NULL
 kill $PID
 wait
 
+#-cipher RSA-NULL
+launch_bare_server $$ s_server -cipher NULL -quiet -www -accept $PORT -keyform 
pem -certform pem -tls1 -dhparam params.dh -key $RSA_KEY -cert $RSA_CERT 
-Verify 1 -CAfile $CA_CERT &
+PID=$!
+wait_server $PID
+
+# Test TLS 1.0 with RSA-NULL ciphersuite
+echo "Checking TLS 1.0 with RSA-NULL..." 
+$CLI $DEBUG -p $PORT 127.0.0.1 --priority 
"NONE:+NULL:+SIGN-ALL:+COMP-NULL:+MAC-ALL:+VERS-TLS1.0:+RSA" --insecure 
--x509certfile $CLI_CERT --x509keyfile $CLI_KEY </dev/null >/dev/null || \
+  fail $PID "Failed"
+
+kill $PID
+wait
+
 #-cipher 
RSA-AES128-SHA:DHE-DSS-AES128-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-AES128-SHA 
 launch_bare_server $$ s_server -quiet -www -accept $PORT -keyform pem 
-certform pem -tls1 -dhparam params.dh -key $RSA_KEY -cert $RSA_CERT -dkey 
$DSA_KEY -dcert $DSA_CERT -Verify 1 -CAfile $CA_CERT &
 PID=$!
@@ -136,7 +149,7 @@ wait
 
 fi
 
-launch_bare_server $$ s_server -quiet -accept $PORT -keyform pem -certform pem 
-dtls1 -mtu 1000 -timeout -dhparam params.dh -key $RSA_KEY -cert $RSA_CERT 
-dkey $DSA_KEY -dcert $DSA_CERT -Verify 1 -CAfile $CA_CERT &
+launch_bare_server $$ s_server -quiet -accept $PORT -keyform pem -certform pem 
-dtls1 -timeout -dhparam params.dh -key $RSA_KEY -cert $RSA_CERT -dkey $DSA_KEY 
-dcert $DSA_CERT -Verify 1 -CAfile $CA_CERT &
 PID=$!
 wait_server $PID
 
@@ -150,7 +163,7 @@ $CLI $DEBUG -p $PORT 127.0.0.1 --priority 
"NONE:+CIPHER-ALL:+SIGN-ALL:+COMP-NULL
 kill $PID
 wait
 
-launch_bare_server $$ s_server -quiet -accept $PORT -keyform pem -certform pem 
-dtls1 -mtu 1000 -timeout -dhparam params.dh -key $RSA_KEY -cert $RSA_CERT 
-dkey $DSA_KEY -dcert $DSA_CERT -Verify 1 -CAfile $CA_CERT &
+launch_bare_server $$ s_server -quiet -accept $PORT -keyform pem -certform pem 
-dtls1 -timeout -dhparam params.dh -key $RSA_KEY -cert $RSA_CERT -dkey $DSA_KEY 
-dcert $DSA_CERT -Verify 1 -CAfile $CA_CERT &
 PID=$!
 wait_server $PID
 
@@ -162,7 +175,7 @@ $CLI $DEBUG -p $PORT 127.0.0.1 --priority 
"NONE:+CIPHER-ALL:+SIGN-ALL:+COMP-NULL
 kill $PID
 wait
 
-launch_bare_server $$ s_server -quiet -accept $PORT -keyform pem -certform pem 
-dtls1 -mtu 1000 -timeout -dhparam params.dh -key $RSA_KEY -cert $RSA_CERT 
-dkey $DSA_KEY -dcert $DSA_CERT -Verify 1 -CAfile $CA_CERT &
+launch_bare_server $$ s_server -quiet -accept $PORT -keyform pem -certform pem 
-dtls1 -timeout -dhparam params.dh -key $RSA_KEY -cert $RSA_CERT -dkey $DSA_KEY 
-dcert $DSA_CERT -Verify 1 -CAfile $CA_CERT &
 PID=$!
 wait_server $PID
 
@@ -231,6 +244,16 @@ wait
 #kill $PID
 #wait
 
+echo "Check TLS 1.0 with RSA-NULL ciphersuite"
+launch_server $$  --priority 
"NONE:+NULL:+SIGN-ALL:+COMP-NULL:+MAC-ALL:+VERS-TLS1.0:+RSA:+DHE-RSA" 
--x509certfile $SERV_CERT --x509keyfile $SERV_KEY --x509cafile $CA_CERT 
--dhparams params.dh  & PID=$!
+wait_server $PID
+
+$OPENSSL_CLI s_client -cipher NULL-SHA -host localhost -tls1 -port $PORT -cert 
$CLI_CERT -key $CLI_KEY -CAfile $CA_CERT </dev/null 2>&1 | grep "\:error\:" && \
+  fail $PID "Failed"
+
+kill $PID
+wait
+
 echo "Check TLS 1.0 with DHE-RSA ciphersuite"
 launch_server $$  --priority 
"NONE:+CIPHER-ALL:+SIGN-ALL:+COMP-NULL:+MAC-ALL:+VERS-TLS1.0:+DHE-RSA" 
--x509certfile $SERV_CERT --x509keyfile $SERV_KEY --x509cafile $CA_CERT 
--dhparams params.dh  & PID=$!
 wait_server $PID
diff --git a/tests/suite/testsrn b/tests/suite/testsrn
index f11a89a..7409455 100755
--- a/tests/suite/testsrn
+++ b/tests/suite/testsrn
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-# Copyright (C) 2010 Free Software Foundation, Inc.
+# Copyright (C) 2010-2011 Free Software Foundation, Inc.
 #
 # Author: Nikos Mavrogiannopoulos
 #
@@ -30,7 +30,7 @@ if test "${WINDIR}" != "";then
   exit 77
 fi 
 
-. ../scripts/common.sh
+. $srcdir/../scripts/common.sh
 
 echo "Checking Safe renegotiation"
 
diff --git a/tests/suppressions.valgrind b/tests/suppressions.valgrind
new file mode 100644
index 0000000..57c4222
--- /dev/null
+++ b/tests/suppressions.valgrind
@@ -0,0 +1,203 @@
+# suppressions -- Valgrind suppresion file for libgcrypt
+
+# Copyright (C) 2008-2011  Free Software Foundation, Inc.
+
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+
+{
+   zlib inflateInit
+   Memcheck:Cond
+   fun:inflateReset2
+   fun:inflateInit2_
+   fun:_gnutls_comp_init
+   fun:_gnutls_init_record_state
+   fun:_gnutls_epoch_set_keys
+   fun:_gnutls_write_connection_state_init
+   fun:_gnutls_send_handshake_final
+   fun:_gnutls_handshake_common
+   fun:gnutls_handshake
+   fun:doit
+   fun:main
+}
+
+{
+   libgcrypt1
+   Memcheck:Leak
+   fun:malloc
+   fun:_gcry_private_malloc
+   fun:do_malloc
+   fun:_gcry_malloc
+   fun:_gcry_module_add
+   fun:gcry_pk_register_default
+   fun:_gcry_pk_init
+   fun:global_init
+   fun:_gcry_check_version
+   fun:gcry_check_version
+   fun:gnutls_global_init
+}
+
+{
+   libgcrypt1-new
+   Memcheck:Leak
+   fun:malloc
+   fun:_gcry_private_malloc
+   fun:do_malloc
+   fun:_gcry_malloc
+   fun:_gcry_module_add
+   fun:pk_register_default
+   fun:_gcry_pk_init
+   fun:global_init
+   fun:_gcry_check_version
+   fun:gcry_check_version
+   fun:gnutls_global_init
+}
+
+{
+   libgcrypt2
+   Memcheck:Leak
+   fun:malloc
+   fun:_gcry_private_malloc
+   fun:do_malloc
+   fun:_gcry_malloc
+   fun:_gcry_module_add
+   fun:gcry_md_register_default
+   fun:_gcry_md_init
+   fun:global_init
+   fun:_gcry_check_version
+   fun:gcry_check_version
+   fun:gnutls_global_init
+}
+
+{
+   libgcrypt2-new
+   Memcheck:Leak
+   fun:malloc
+   fun:_gcry_private_malloc
+   fun:do_malloc
+   fun:_gcry_malloc
+   fun:_gcry_module_add
+   fun:md_register_default
+   fun:_gcry_md_init
+   fun:global_init
+   fun:_gcry_check_version
+   fun:gcry_check_version
+   fun:gnutls_global_init
+}
+
+{
+   libgcrypt3
+   Memcheck:Leak
+   fun:malloc
+   fun:_gcry_private_malloc
+   fun:do_malloc
+   fun:_gcry_malloc
+   fun:_gcry_module_add
+   fun:gcry_cipher_register_default
+   fun:_gcry_cipher_init
+   fun:global_init
+   fun:_gcry_check_version
+   fun:gcry_check_version
+   fun:gnutls_global_init
+}
+
+{
+   libgcrypt3-new
+   Memcheck:Leak
+   fun:malloc
+   fun:_gcry_private_malloc
+   fun:do_malloc
+   fun:_gcry_malloc
+   fun:_gcry_module_add
+   fun:cipher_register_default
+   fun:_gcry_cipher_init
+   fun:global_init
+   fun:_gcry_check_version
+   fun:gcry_check_version
+   fun:gnutls_global_init
+}
+
+{
+   libgcrypt4
+   Memcheck:Leak
+   fun:malloc
+   fun:do_malloc
+   fun:_gcry_malloc
+   fun:_gcry_xmalloc
+   fun:_gcry_xcalloc
+   fun:initialize
+   fun:_gcry_randomize
+   fun:gcry_randomize
+   fun:gc_pseudo_random
+   fun:_gnutls_rnd_init
+   fun:gnutls_global_init
+}
+
+{
+   libgcrypt5
+   Memcheck:Leak
+   fun:malloc
+   fun:_gcry_private_malloc
+   fun:do_malloc
+   fun:_gcry_malloc
+   fun:_gcry_xmalloc
+   fun:_gcry_xcalloc
+   fun:initialize
+   fun:_gcry_randomize
+   fun:gcry_randomize
+   fun:gc_pseudo_random
+   fun:_gnutls_rnd_init
+   fun:gnutls_global_init
+}
+
+{
+   libgcrypt6
+   Memcheck:Leak
+   fun:malloc
+   fun:do_malloc
+   fun:_gcry_malloc
+   fun:_gcry_xmalloc
+   fun:_gcry_xcalloc
+   fun:initialize
+   fun:_gcry_create_nonce
+   fun:gcry_create_nonce
+   fun:wrap_gcry_rnd_init
+   fun:_gnutls_rnd_init
+   fun:gnutls_global_init
+}
+
+{
+   libgcrypt7
+   Memcheck:Leak
+   fun:malloc
+   fun:_gcry_private_malloc
+   fun:do_malloc
+   fun:_gcry_malloc
+   fun:_gcry_xmalloc
+   fun:_gcry_xcalloc
+   fun:initialize
+   fun:_gcry_create_nonce
+   fun:gcry_create_nonce
+   fun:wrap_gcry_rnd_init
+   fun:_gnutls_rnd_init
+   fun:gnutls_global_init
+}
+
+{
+   libgcrypt7-new
+   Memcheck:Leak
+   fun:malloc
+   fun:_gcry_private_malloc
+   fun:do_malloc
+   fun:_gcry_malloc
+   fun:_gcry_xmalloc
+   fun:_gcry_xcalloc
+   fun:initialize
+   fun:_gcry_rngcsprng_create_nonce
+   fun:_gcry_create_nonce
+   fun:gcry_create_nonce
+   fun:wrap_gcry_rnd_init
+   fun:_gnutls_rnd_init
+   fun:gnutls_global_init
+}
diff --git a/tests/utils.c b/tests/utils.c
index fd543fe..e101be5 100644
--- a/tests/utils.c
+++ b/tests/utils.c
@@ -26,7 +26,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-
+#include <stdarg.h>
+ 
 #include "utils.h"
 
 int debug = 0;
diff --git a/tests/x509cert-tl.c b/tests/x509cert-tl.c
index f3936f7..a490c27 100644
--- a/tests/x509cert-tl.c
+++ b/tests/x509cert-tl.c
@@ -207,5 +207,5 @@ doit (void)
   
   gnutls_global_deinit();
   
-  success("success");
+  if (debug) success("success");
 }
diff --git a/tests/x509cert.c b/tests/x509cert.c
index 8edd711..78d0049 100644
--- a/tests/x509cert.c
+++ b/tests/x509cert.c
@@ -203,5 +203,5 @@ doit (void)
   
   gnutls_global_deinit();
 
-  success("success");
+  if (debug) success("success");
 }


hooks/post-receive
-- 
GNU gnutls



reply via email to

[Prev in Thread] Current Thread [Next in Thread]