Threema преди 4 години
ревизия
5e11230f55
променени са 100 файла, в които са добавени 5392 реда и са изтрити 0 реда
  1. 31 0
      .gitignore
  2. 153 0
      BUILD_WEBRTC.md
  3. 15 0
      CONTRIBUTING.md
  4. 14 0
      Cartfile
  5. 14 0
      Cartfile.resolved
  6. 661 0
      LICENSE.txt
  7. 55 0
      NaClCrypto/NaClCrypto.h
  8. 484 0
      NaClCrypto/NaClCrypto.m
  9. 22 0
      NaClCrypto/nacl/crypto_box/curve25519xsalsa20poly1305/ref/after.c
  10. 6 0
      NaClCrypto/nacl/crypto_box/curve25519xsalsa20poly1305/ref/api.h
  11. 17 0
      NaClCrypto/nacl/crypto_box/curve25519xsalsa20poly1305/ref/before.c
  12. 27 0
      NaClCrypto/nacl/crypto_box/curve25519xsalsa20poly1305/ref/box.c
  13. 12 0
      NaClCrypto/nacl/crypto_box/curve25519xsalsa20poly1305/ref/keypair.c
  14. 4 0
      NaClCrypto/nacl/crypto_core/hsalsa20/ref/api.h
  15. 135 0
      NaClCrypto/nacl/crypto_core/hsalsa20/ref/core.c
  16. 4 0
      NaClCrypto/nacl/crypto_core/salsa20/ref/api.h
  17. 134 0
      NaClCrypto/nacl/crypto_core/salsa20/ref/core.c
  18. 2 0
      NaClCrypto/nacl/crypto_onetimeauth/poly1305/53/api.h
  19. 1616 0
      NaClCrypto/nacl/crypto_onetimeauth/poly1305/53/auth.c
  20. 9 0
      NaClCrypto/nacl/crypto_onetimeauth/poly1305/53/verify.c
  21. 2 0
      NaClCrypto/nacl/crypto_scalarmult/curve25519/donna/api.h
  22. 8 0
      NaClCrypto/nacl/crypto_scalarmult/curve25519/donna/base.c
  23. 733 0
      NaClCrypto/nacl/crypto_scalarmult/curve25519/donna/smult.c
  24. 4 0
      NaClCrypto/nacl/crypto_secretbox/xsalsa20poly1305/ref/api.h
  25. 35 0
      NaClCrypto/nacl/crypto_secretbox/xsalsa20poly1305/ref/box.c
  26. 2 0
      NaClCrypto/nacl/crypto_stream/salsa20/ref/api.h
  27. 49 0
      NaClCrypto/nacl/crypto_stream/salsa20/ref/stream.c
  28. 52 0
      NaClCrypto/nacl/crypto_stream/salsa20/ref/xor.c
  29. 2 0
      NaClCrypto/nacl/crypto_stream/xsalsa20/ref/api.h
  30. 22 0
      NaClCrypto/nacl/crypto_stream/xsalsa20/ref/stream.c
  31. 23 0
      NaClCrypto/nacl/crypto_stream/xsalsa20/ref/xor.c
  32. 1 0
      NaClCrypto/nacl/crypto_verify/16/ref/api.h
  33. 24 0
      NaClCrypto/nacl/crypto_verify/16/ref/verify.c
  34. 1 0
      NaClCrypto/nacl/crypto_verify/32/ref/api.h
  35. 40 0
      NaClCrypto/nacl/crypto_verify/32/ref/verify.c
  36. 22 0
      NaClCrypto/nacl/include/crypto_box.h
  37. 45 0
      NaClCrypto/nacl/include/crypto_box_curve25519xsalsa20poly1305.h
  38. 28 0
      NaClCrypto/nacl/include/crypto_core.h
  39. 28 0
      NaClCrypto/nacl/include/crypto_core_hsalsa20.h
  40. 28 0
      NaClCrypto/nacl/include/crypto_core_salsa20.h
  41. 14 0
      NaClCrypto/nacl/include/crypto_onetimeauth.h
  42. 28 0
      NaClCrypto/nacl/include/crypto_onetimeauth_poly1305.h
  43. 28 0
      NaClCrypto/nacl/include/crypto_scalarmult.h
  44. 28 0
      NaClCrypto/nacl/include/crypto_scalarmult_curve25519.h
  45. 16 0
      NaClCrypto/nacl/include/crypto_secretbox.h
  46. 32 0
      NaClCrypto/nacl/include/crypto_secretbox_xsalsa20poly1305.h
  47. 18 0
      NaClCrypto/nacl/include/crypto_stream.h
  48. 35 0
      NaClCrypto/nacl/include/crypto_stream_salsa20.h
  49. 35 0
      NaClCrypto/nacl/include/crypto_stream_xsalsa20.h
  50. 22 0
      NaClCrypto/nacl/include/crypto_verify_16.h
  51. 22 0
      NaClCrypto/nacl/include/crypto_verify_32.h
  52. 24 0
      NaClCrypto/nacl/include/randombytes.h
  53. 36 0
      NaClCrypto/nacl/randombytes/devurandom.c
  54. 24 0
      NaClCrypto/nacl/randombytes/devurandom.h
  55. 170 0
      README.md
  56. BIN
      Resources/Images.xcassets/AppIcon.appiconset/100.png
  57. BIN
      Resources/Images.xcassets/AppIcon.appiconset/1024.png
  58. BIN
      Resources/Images.xcassets/AppIcon.appiconset/114.png
  59. BIN
      Resources/Images.xcassets/AppIcon.appiconset/120-1.png
  60. BIN
      Resources/Images.xcassets/AppIcon.appiconset/120.png
  61. BIN
      Resources/Images.xcassets/AppIcon.appiconset/144.png
  62. BIN
      Resources/Images.xcassets/AppIcon.appiconset/152.png
  63. BIN
      Resources/Images.xcassets/AppIcon.appiconset/167.png
  64. BIN
      Resources/Images.xcassets/AppIcon.appiconset/180.png
  65. BIN
      Resources/Images.xcassets/AppIcon.appiconset/20.png
  66. BIN
      Resources/Images.xcassets/AppIcon.appiconset/29-1.png
  67. BIN
      Resources/Images.xcassets/AppIcon.appiconset/29.png
  68. BIN
      Resources/Images.xcassets/AppIcon.appiconset/40-1.png
  69. BIN
      Resources/Images.xcassets/AppIcon.appiconset/40-2.png
  70. BIN
      Resources/Images.xcassets/AppIcon.appiconset/40.png
  71. BIN
      Resources/Images.xcassets/AppIcon.appiconset/50.png
  72. BIN
      Resources/Images.xcassets/AppIcon.appiconset/57.png
  73. BIN
      Resources/Images.xcassets/AppIcon.appiconset/58-1.png
  74. BIN
      Resources/Images.xcassets/AppIcon.appiconset/58.png
  75. BIN
      Resources/Images.xcassets/AppIcon.appiconset/60.png
  76. BIN
      Resources/Images.xcassets/AppIcon.appiconset/72.png
  77. BIN
      Resources/Images.xcassets/AppIcon.appiconset/76.png
  78. BIN
      Resources/Images.xcassets/AppIcon.appiconset/80-1.png
  79. BIN
      Resources/Images.xcassets/AppIcon.appiconset/80.png
  80. BIN
      Resources/Images.xcassets/AppIcon.appiconset/87.png
  81. 158 0
      Resources/Images.xcassets/AppIcon.appiconset/Contents.json
  82. 6 0
      Resources/Images.xcassets/Contents.json
  83. BIN
      Resources/Images/Icons.xcassets/AcceptCall.imageset/AcceptCall.pdf
  84. 15 0
      Resources/Images/Icons.xcassets/AcceptCall.imageset/Contents.json
  85. BIN
      Resources/Images/Icons.xcassets/ActionBallot.imageset/ActionBallot.pdf
  86. 15 0
      Resources/Images/Icons.xcassets/ActionBallot.imageset/Contents.json
  87. BIN
      Resources/Images/Icons.xcassets/ActionCamera.imageset/ActionCamera.pdf
  88. 15 0
      Resources/Images/Icons.xcassets/ActionCamera.imageset/Contents.json
  89. BIN
      Resources/Images/Icons.xcassets/ActionFile.imageset/ActionFile.pdf
  90. 15 0
      Resources/Images/Icons.xcassets/ActionFile.imageset/Contents.json
  91. BIN
      Resources/Images/Icons.xcassets/ActionLocation.imageset/ActionLocation.pdf
  92. 15 0
      Resources/Images/Icons.xcassets/ActionLocation.imageset/Contents.json
  93. BIN
      Resources/Images/Icons.xcassets/ActionMicrophone.imageset/ActionMicrophone.pdf
  94. 15 0
      Resources/Images/Icons.xcassets/ActionMicrophone.imageset/Contents.json
  95. BIN
      Resources/Images/Icons.xcassets/ActionPhoto.imageset/ActionPhoto.pdf
  96. 15 0
      Resources/Images/Icons.xcassets/ActionPhoto.imageset/Contents.json
  97. BIN
      Resources/Images/Icons.xcassets/AddMember.imageset/AddMember.pdf
  98. 15 0
      Resources/Images/Icons.xcassets/AddMember.imageset/Contents.json
  99. BIN
      Resources/Images/Icons.xcassets/AdvancedDark.imageset/AdvancedDark.pdf
  100. 12 0
      Resources/Images/Icons.xcassets/AdvancedDark.imageset/Contents.json

+ 31 - 0
.gitignore

@@ -0,0 +1,31 @@
+## Build generated
+build/
+artifacts/
+DerivedData/
+
+## Various settings
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+xcuserdata/
+
+## Other
+*.moved-aside
+*.xccheckout
+*.xcscmblueprint
+*_old.storyboard
+.DS_Store
+Carthage/Checkouts
+WebRTC*
+SaltyRTC
+fastlane/AppStore/Threema/screenshots
+fastlane/AppStore/ThreemaForWork/screenshots
+fastlane/Preview.html
+fastlane/test_output
+fastlane/report.xml
+export/

+ 153 - 0
BUILD_WEBRTC.md

@@ -0,0 +1,153 @@
+# Build WebRTC
+
+### 1. Prerequisites
+
+- A clone of [depot tools](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up)
+
+  ```sh
+  git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
+  ```
+  
+- At least 30 GB of free disk space
+
+- Matching macOS and Xcode version (see _Versions_)
+
+### 2a. Setup Fresh Build
+
+1. Set path to depot tools (if not in your default path)
+
+   ```sh
+   export PATH=/path/to/depot_tools:$PATH
+   ```
+
+2. Choose and set WebRTC and patch commit to use (see _Versions_ below)
+
+   ```sh
+   export COMMIT=commit_id
+   export PATCH_COMMIT=patch_commit_id
+   
+   # e.g.
+   # export COMMIT=963cc1ef1336b52ca27742beb28bfbc211ed54d0
+   # export PATCH_COMMIT=a57784d2f12b566cd79cd771d65b49a078841cca
+   ```
+
+3. Create a new folder and go into it
+
+   ```sh
+   mkdir WebRTC-build
+   cd WebRTC-build
+   ```
+
+4. Fetch a regular WebRTC checkout with the iOS-specific parts added. (This might take a while...)
+
+   ```sh
+   fetch --nohooks webrtc_ios
+   ```
+
+5. Get patches
+
+   ```sh
+   git clone https://github.com/threema-ch/webrtc-build-docker.git
+   cd webrtc-build-docker
+   ```
+   (The patches are part of our [WebRTC PeerConnection Build Script](https://github.com/threema-ch/webrtc-build-docker).)
+
+### 2b. Setup Rebuild
+
+1. Set path to depot tools (if not in your default path)
+
+   ```sh
+   export PATH=/path/to/depot_tools:$PATH
+   ```
+
+2. Choose and set WebRTC and patch commit to use (see _Versions_ below)
+
+   ```sh
+   export COMMIT=commit_id
+   export PATCH_COMMIT=patch_commit_id
+   ```
+
+3. Reset applied patches
+   
+   ```sh
+   cd WebRTC-build/src
+   git reset --hard
+   ```
+   
+4. Update patches
+
+   ```sh
+   cd ../webrtc-build-docker
+   git checkout master && git pull origin master
+   ```
+
+### 3. Checkout and Apply Patches
+
+1. Check out patch commit
+
+   ```sh
+   git checkout $PATCH_COMMIT
+   ```
+   
+2. Go into src folder and checkout WebRTC. (This might take a while...)
+
+   ```sh
+   cd ../src
+   git checkout master && git pull && git checkout $COMMIT && gclient sync
+   ```
+
+3. Apply patches
+
+   ```sh
+   for i in ../webrtc-build-docker/build/patches/*.patch; do patch -p1 < $i; done
+   ```
+
+
+### 4. Build
+
+You can either build for release or debug. Debug is needed for the simulator.
+
+#### Build for release
+
+1. Build
+
+   ```sh
+   tools_webrtc/ios/build_ios_libs.py --bitcode --arch arm64 arm --output-dir ../out
+   ```
+2. Remove existing framework and move to correct location
+
+   ```sh
+   rm -r ../../WebRTC-release
+   mkdir ../../WebRTC-release
+   mv ../out/WebRTC.framework ../../WebRTC-release
+   ```
+
+#### Build for debug
+
+1. Build
+
+   ```sh
+   tools_webrtc/ios/build_ios_libs.py --bitcode --arch arm64 arm x64 x86 --output-dir ../out
+   ```
+2. Remove existing framework and move to correct location
+
+   ```sh
+   rm -r ../../WebRTC-debug
+   mkdir ../../WebRTC-debug
+   mv ../out/WebRTC.framework ../../WebRTC-debug
+   ```
+
+### 5. Include in App Build
+
+To ensure this version will be used in the app build, remove the existing chosen WebRTC build.
+
+```sh
+rm -r ../../WebRTC
+```
+
+## Versions
+
+| iOS App Version | WebRTC Commit                                                | Patch Commit                                                 | macOS Version    | Xcode Version  | WebRTC Binary Version |
+| --------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ---------------- | -------------- | --------------------- |
+| 4.6.3 (2587)    | [963cc1ef1336b52ca27742beb28bfbc211ed54d0](https://chromium.googlesource.com/external/webrtc/+/963cc1ef1336b52ca27742beb28bfbc211ed54d0) (m84) | [a57784d2f12b566cd79cd771d65b49a078841cca](https://github.com/threema-ch/webrtc-build-docker/commit/a57784d2f12b566cd79cd771d65b49a078841cca) | 10.15.5 (19F101) | 11.5 (11E608c) | 84.1.1 |
+

+ 15 - 0
CONTRIBUTING.md

@@ -0,0 +1,15 @@
+# Contributing to Threema for iOS
+
+## Submitting Patches
+
+At this point, we don’t accept pull requests for the Threema apps via GitHub.
+However, if you would like to provide a code contribution, you can send patches
+via e-mail.
+
+Please refer to <https://threema.ch/open-source/contributions> for more
+information on how to contribute.
+
+## Bug Reports / Feature Requests
+
+To report bugs and request new features, please contact the Threema support
+team through [threema.ch/support](https://threema.ch/support).

+ 14 - 0
Cartfile

@@ -0,0 +1,14 @@
+github "specta/specta" ~> 1.0
+github "specta/expecta" "master"
+github "jonreid/OCMockito" ~> 5.1
+github "hamcrest/OCHamcrest" ~> 7.1
+github "malcommac/SwiftMsgPack" ~> 1.0.0
+github "1024jp/GzipSwift" ~> 5.0.0
+github "gumob/PunycodeSwift" ~> 1.0
+github "CocoaLumberjack/CocoaLumberjack" ~> 3.6
+github "threema-ch/sentry-cocoa" "feature/privatemode"
+github "cbpowell/MarqueeLabel" ~> 4.0.0
+github "SnapKit/SnapKit" ~> 5.0.0
+github "apple/swift-protobuf" ~> 1.8
+github "ZipArchive/ZipArchive" "master"
+github "mxcl/PromiseKit" ~> 6.8

+ 14 - 0
Cartfile.resolved

@@ -0,0 +1,14 @@
+github "1024jp/GzipSwift" "5.1.1"
+github "CocoaLumberjack/CocoaLumberjack" "3.6.1"
+github "SnapKit/SnapKit" "5.0.1"
+github "ZipArchive/ZipArchive" "546b99c5c0f7e0c5761960c8ffd486f2ef7610d7"
+github "apple/swift-protobuf" "1.12.0"
+github "cbpowell/MarqueeLabel" "4.0.2"
+github "gumob/PunycodeSwift" "1.0.1"
+github "hamcrest/OCHamcrest" "v7.1.2"
+github "jonreid/OCMockito" "v5.1.3"
+github "malcommac/SwiftMsgPack" "1.0.0"
+github "mxcl/PromiseKit" "6.13.2"
+github "specta/expecta" "fc2dd8bf29b8e4edbfeb4639a98b5d87bea03e19"
+github "specta/specta" "v1.0.7"
+github "threema-ch/sentry-cocoa" "77f7a364d30f3623f3ddafc264d600f0613a1d8f"

+ 661 - 0
LICENSE.txt

@@ -0,0 +1,661 @@
+                    GNU AFFERO GENERAL PUBLIC LICENSE
+                       Version 3, 19 November 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU Affero General Public License is a free, copyleft license for
+software and other kinds of works, specifically designed to ensure
+cooperation with the community in the case of network server software.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+our General Public Licenses are intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  Developers that use our General Public Licenses protect your rights
+with two steps: (1) assert copyright on the software, and (2) offer
+you this License which gives you legal permission to copy, distribute
+and/or modify the software.
+
+  A secondary benefit of defending all users' freedom is that
+improvements made in alternate versions of the program, if they
+receive widespread use, become available for other developers to
+incorporate.  Many developers of free software are heartened and
+encouraged by the resulting cooperation.  However, in the case of
+software used on network servers, this result may fail to come about.
+The GNU General Public License permits making a modified version and
+letting the public access it on a server without ever releasing its
+source code to the public.
+
+  The GNU Affero General Public License is designed specifically to
+ensure that, in such cases, the modified source code becomes available
+to the community.  It requires the operator of a network server to
+provide the source code of the modified version running there to the
+users of that server.  Therefore, public use of a modified version, on
+a publicly accessible server, gives the public access to the source
+code of the modified version.
+
+  An older license, called the Affero General Public License and
+published by Affero, was designed to accomplish similar goals.  This is
+a different license, not a version of the Affero GPL, but Affero has
+released a new version of the Affero GPL which permits relicensing under
+this license.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU Affero General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Remote Network Interaction; Use with the GNU General Public License.
+
+  Notwithstanding any other provision of this License, if you modify the
+Program, your modified version must prominently offer all users
+interacting with it remotely through a computer network (if your version
+supports such interaction) an opportunity to receive the Corresponding
+Source of your version by providing access to the Corresponding Source
+from a network server at no charge, through some standard or customary
+means of facilitating copying of software.  This Corresponding Source
+shall include the Corresponding Source for any work covered by version 3
+of the GNU General Public License that is incorporated pursuant to the
+following paragraph.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the work with which it is combined will remain governed by version
+3 of the GNU General Public License.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU Affero General Public License from time to time.  Such new versions
+will be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU Affero General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU Affero General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU Affero General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero 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 Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If your software can interact with users remotely through a computer
+network, you should also make sure that it provides a way for users to
+get its source.  For example, if your program is a web application, its
+interface could display a "Source" link that leads users to an archive
+of the code.  There are many ways you could offer source, and different
+solutions will be better for different programs; see section 13 for the
+specific requirements.
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU AGPL, see
+<https://www.gnu.org/licenses/>.

+ 55 - 0
NaClCrypto/NaClCrypto.h

@@ -0,0 +1,55 @@
+//  _____ _
+// |_   _| |_  _ _ ___ ___ _ __  __ _
+//   | | | ' \| '_/ -_) -_) '  \/ _` |_
+//   |_| |_||_|_| \___\___|_|_|_\__,_(_)
+//
+// Threema iOS Client
+// Copyright (c) 2012-2020 Threema GmbH
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License, version 3,
+// as published by the Free Software Foundation.
+//
+// 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 Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+#import <Foundation/Foundation.h>
+
+#define kNaClCryptoPubKeySize 32
+#define kNaClCryptoSecKeySize 32
+#define kNaClCryptoNonceSize 24
+#define kNaClBoxOverhead 16
+#define kNaClCryptoSymmKeySize 32
+#define kNaClCryptoSymmNonceSize 24
+#define kNaClCryptoStreamKeySize 32
+#define kNaClCryptoStreamNonceSize 24
+
+@interface NaClCrypto : NSObject
+
++ (NaClCrypto*)sharedCrypto;
+
+- (void)generateKeyPairPublicKey:(NSData**)publicKey secretKey:(NSData**)secretKey withSeed:(NSData*)seed;
+- (void)generateKeyPairPublicKey:(NSData**)publicKey secretKey:(NSData**)secretKey;
+- (NSData*)derivePublicKeyFromSecretKey:(NSData*)secretKey;
+- (NSData*)encryptData:(NSData*)plaintext withPublicKey:(NSData*)publicKey signKey:(NSData*)signKey nonce:(NSData*)nonce;
+- (NSData*)decryptData:(NSData*)ciphertext withSecretKey:(NSData*)secretKey signKey:(NSData*)signKey nonce:(NSData*)nonce;
+
+- (NSData*)symmetricEncryptData:(NSData*)plaintext withKey:(NSData*)key nonce:(NSData*)nonce;
+- (NSData*)symmetricDecryptData:(NSData*)ciphertext withKey:(NSData*)key nonce:(NSData*)nonce;
+
+- (NSData*)streamXorData:(NSData*)data secretKey:(NSData*)secretKey nonce:(NSData*)nonce;
+
+- (NSData*)randomBytes:(int)len;
+- (NSData*)zeroBytes:(int)len;
+
+- (void)selfTest;
+- (void)longTest;
+- (double)benchmark;
+
+
+@end

+ 484 - 0
NaClCrypto/NaClCrypto.m

@@ -0,0 +1,484 @@
+//  _____ _
+// |_   _| |_  _ _ ___ ___ _ __  __ _
+//   | | | ' \| '_/ -_) -_) '  \/ _` |_
+//   |_| |_||_|_| \___\___|_|_|_\__,_(_)
+//
+// Threema iOS Client
+// Copyright (c) 2012-2020 Threema GmbH
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License, version 3,
+// as published by the Free Software Foundation.
+//
+// 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 Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+#import "NaClCrypto.h"
+#import "crypto_box.h"
+#import "crypto_scalarmult_curve25519.h"
+#import "crypto_secretbox.h"
+#import "crypto_stream.h"
+#import "devurandom.h"
+
+#ifdef DEBUG
+  static const DDLogLevel ddLogLevel = DDLogLevelVerbose;
+#else
+  static const DDLogLevel ddLogLevel = DDLogLevelWarning;
+#endif
+
+@implementation NaClCrypto
+
+#if (kNaClCryptoPubKeySize != crypto_box_PUBLICKEYBYTES)
+#error Bad public key size
+#endif
+
+#if (kNaClCryptoSecKeySize != crypto_box_SECRETKEYBYTES)
+#error Bad secret key size
+#endif
+
+#if (kNaClCryptoNonceSize != crypto_box_NONCEBYTES)
+#error Bad nonce size
+#endif
+
+#if (kNaClBoxOverhead != (crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES))
+#error Bad box overhead size
+#endif
+
+#if (kNaClCryptoSymmKeySize != crypto_secretbox_KEYBYTES)
+#error Bad symmetric key size
+#endif
+
+#if (kNaClCryptoSymmNonceSize != crypto_secretbox_NONCEBYTES)
+#error Bad symmetric nonce size
+#endif
+
+#if (kNaClCryptoStreamKeySize != crypto_stream_KEYBYTES)
+#error Bad stream key size
+#endif
+
+#if (kNaClCryptoStreamNonceSize != crypto_stream_NONCEBYTES)
+#error Bad stream nonce size
+#endif
+
++ (NaClCrypto*)sharedCrypto {
+    static NaClCrypto *instance;
+	
+	@synchronized (self) {
+		if (!instance)
+			instance = [[NaClCrypto alloc] init];
+	}
+	
+	return instance;
+}
+
+- (id)init
+{
+    self = [super init];
+    if (self) {
+        [self selfTest];
+    }
+    
+    return self;
+}
+
+- (void)generateKeyPairPublicKey:(NSData**)publicKey secretKey:(NSData**)secretKey withSeed:(NSData*)seed {
+    
+    if (seed.length != kNaClCryptoSecKeySize)
+        @throw([NSException exceptionWithName:@"BadSeedSizeException" reason:@"Invalid seed size" userInfo:nil]);
+    
+    unsigned char *pk = malloc(kNaClCryptoPubKeySize);
+    if (pk == NULL)
+        @throw([NSException exceptionWithName:@"MemoryAllocationException" reason:@"Cannot allocate memory" userInfo:nil]);
+    
+    unsigned char *sk = malloc(kNaClCryptoSecKeySize);
+    if (sk == NULL) {
+        free(pk);
+        @throw([NSException exceptionWithName:@"MemoryAllocationException" reason:@"Cannot allocate memory" userInfo:nil]);
+    }
+    
+    /* mix seed with random data */
+    randombytes(sk, kNaClCryptoSecKeySize);
+    for (int i = 0; i < kNaClCryptoSecKeySize; i++)
+        sk[i] ^= ((unsigned char*)seed.bytes)[i];
+    
+    /* sidestepping crypto_box_keypair to provide our own secret key */
+    if (crypto_scalarmult_curve25519_base(pk, sk) != 0) {
+        /* shouldn't happen */
+        free(pk);
+        free(sk);
+        @throw([NSException exceptionWithName:@"CryptoException" reason:@"Crypto error" userInfo:nil]);
+    }
+    
+    *publicKey = [NSData dataWithBytesNoCopy:pk length:kNaClCryptoPubKeySize];
+    *secretKey = [NSData dataWithBytesNoCopy:sk length:kNaClCryptoSecKeySize];
+}
+
+- (void)generateKeyPairPublicKey:(NSData**)publicKey secretKey:(NSData**)secretKey {
+    unsigned char *pk = malloc(kNaClCryptoPubKeySize);
+    if (pk == NULL)
+        @throw([NSException exceptionWithName:@"MemoryAllocationException" reason:@"Cannot allocate memory" userInfo:nil]);
+    
+    unsigned char *sk = malloc(kNaClCryptoSecKeySize);
+    if (sk == NULL) {
+        free(pk);
+        @throw([NSException exceptionWithName:@"MemoryAllocationException" reason:@"Cannot allocate memory" userInfo:nil]);
+    }
+    
+    if (crypto_box_keypair(pk, sk) != 0) {
+        /* shouldn't happen */
+        free(pk);
+        free(sk);
+        @throw([NSException exceptionWithName:@"CryptoException" reason:@"Crypto error" userInfo:nil]);
+    }
+    
+    *publicKey = [NSData dataWithBytesNoCopy:pk length:kNaClCryptoPubKeySize];
+    *secretKey = [NSData dataWithBytesNoCopy:sk length:kNaClCryptoSecKeySize];
+}
+
+- (NSData*)derivePublicKeyFromSecretKey:(NSData*)secretKey {
+    if (secretKey.length != kNaClCryptoSecKeySize)
+        @throw([NSException exceptionWithName:@"BadSecKeySizeException" reason:@"Invalid secret key size" userInfo:nil]);
+    
+    unsigned char *pk = malloc(kNaClCryptoPubKeySize);
+    if (pk == NULL)
+        @throw([NSException exceptionWithName:@"MemoryAllocationException" reason:@"Cannot allocate memory" userInfo:nil]);
+    
+    /* sidestepping crypto_box_keypair to provide our own secret key */
+    if (crypto_scalarmult_curve25519_base(pk, secretKey.bytes) != 0) {
+        /* shouldn't happen */
+        free(pk);
+        @throw([NSException exceptionWithName:@"CryptoException" reason:@"Crypto error" userInfo:nil]);
+    }
+    
+    return [NSData dataWithBytesNoCopy:pk length:kNaClCryptoPubKeySize];
+}
+
+- (NSData*)encryptData:(NSData*)plaintext withPublicKey:(NSData*)publicKey signKey:(NSData*)signKey nonce:(NSData*)nonce {
+    
+    /* input sanity checks */
+    if (publicKey.length != kNaClCryptoPubKeySize)
+        @throw([NSException exceptionWithName:@"BadPubKeySizeException" reason:@"Invalid public key size" userInfo:nil]);
+
+    if (signKey.length != kNaClCryptoSecKeySize)
+        @throw([NSException exceptionWithName:@"BadSecKeySizeException" reason:@"Invalid secret key size" userInfo:nil]);
+
+    if (nonce.length != kNaClCryptoNonceSize)
+        @throw([NSException exceptionWithName:@"BadNonceSizeException" reason:@"Invalid nonce size" userInfo:nil]);
+    
+    if (plaintext.length == 0)
+        @throw([NSException exceptionWithName:@"EmptyMessageException" reason:@"Empty message" userInfo:nil]);
+    
+    /* must copy plaintext since we need to zero-pad it */
+    NSUInteger mlen = plaintext.length + crypto_box_ZEROBYTES;
+    char *ctbuf = malloc(mlen);
+    if (ctbuf == NULL) {
+        @throw([NSException exceptionWithName:@"MemoryAllocationException" reason:@"Cannot allocate memory" userInfo:nil]);
+    }
+    bzero(ctbuf, crypto_box_ZEROBYTES);
+    memcpy(&ctbuf[crypto_box_ZEROBYTES], plaintext.bytes, plaintext.length);
+    
+    if (crypto_box((unsigned char *)ctbuf, (unsigned char *)ctbuf, mlen, nonce.bytes,
+                   publicKey.bytes, signKey.bytes) != 0) {
+        
+        /* shouldn't happen */
+        free(ctbuf);
+        @throw([NSException exceptionWithName:@"CryptoException" reason:@"Crypto error" userInfo:nil]);
+    }
+    
+    NSData *ciphertext = [NSData dataWithBytes:&ctbuf[crypto_box_BOXZEROBYTES] length:(mlen - crypto_box_BOXZEROBYTES)];
+    
+    free(ctbuf);
+    
+    return ciphertext;
+}
+
+- (NSData*)decryptData:(NSData*)ciphertext withSecretKey:(NSData*)secretKey signKey:(NSData*)signKey nonce:(NSData*)nonce {
+    
+    /* input sanity checks */
+    if (secretKey.length != kNaClCryptoSecKeySize)
+        @throw([NSException exceptionWithName:@"BadSecKeySizeException" reason:@"Invalid secret key size" userInfo:nil]);
+    
+    if (signKey.length != kNaClCryptoPubKeySize)
+        @throw([NSException exceptionWithName:@"BadPubKeySizeException" reason:@"Invalid public key size" userInfo:nil]);
+    
+    if (nonce.length != kNaClCryptoNonceSize)
+        @throw([NSException exceptionWithName:@"BadNonceSizeException" reason:@"Invalid nonce size" userInfo:nil]);
+    
+    if (ciphertext.length <= crypto_box_BOXZEROBYTES)
+        @throw([NSException exceptionWithName:@"TruncatedMessageException" reason:@"Truncated message" userInfo:nil]);
+    
+    /* must copy ciphertext since we need to zero-pad it */
+    NSUInteger clen = ciphertext.length + crypto_box_BOXZEROBYTES;
+    char *msgbuf = malloc(clen);
+    if (msgbuf == NULL)
+        @throw([NSException exceptionWithName:@"MemoryAllocationException" reason:@"Cannot allocate memory" userInfo:nil]);
+    bzero(msgbuf, crypto_box_BOXZEROBYTES);
+    memcpy(&msgbuf[crypto_box_BOXZEROBYTES], ciphertext.bytes, ciphertext.length);
+    
+    if (crypto_box_open((unsigned char *)msgbuf, (unsigned char *)msgbuf, clen, nonce.bytes,
+                   signKey.bytes, secretKey.bytes) != 0) {
+        
+        /* probably bad signature */
+        free(msgbuf);
+        return nil;
+    }
+    
+    NSData *plaintext = [NSData dataWithBytes:&msgbuf[crypto_box_ZEROBYTES] length:(clen - crypto_box_ZEROBYTES)];
+    
+    free(msgbuf);
+    
+    return plaintext;
+}
+
+- (NSData*)streamXorData:(NSData*)data secretKey:(NSData*)secretKey nonce:(NSData*)nonce {
+    
+    if (secretKey.length != kNaClCryptoStreamKeySize)
+        @throw([NSException exceptionWithName:@"BadStreamKeySizeException" reason:@"Invalid stream key size" userInfo:nil]);
+    
+    if (nonce.length != kNaClCryptoStreamNonceSize)
+        @throw([NSException exceptionWithName:@"BadStreamNonceSizeException" reason:@"Invalid stream nonce size" userInfo:nil]);
+    
+    void *outData = malloc(data.length);
+    if (outData == nil)
+        @throw([NSException exceptionWithName:@"MemoryAllocationException" reason:@"Cannot allocate memory" userInfo:nil]);
+    
+    if (crypto_stream_xor(outData, data.bytes, data.length, nonce.bytes, secretKey.bytes) != 0) {
+        free(outData);
+        @throw([NSException exceptionWithName:@"CryptoException" reason:@"Crypto error" userInfo:nil]);
+    }
+    
+    return [NSData dataWithBytesNoCopy:outData length:data.length];
+}
+
+- (NSData*)symmetricEncryptData:(NSData*)plaintext withKey:(NSData*)key nonce:(NSData*)nonce {
+    
+    if (key.length != kNaClCryptoSymmKeySize)
+        @throw([NSException exceptionWithName:@"BadSymmetricKeySizeException" reason:@"Invalid symmetric key size" userInfo:nil]);
+    
+    if (nonce.length != kNaClCryptoSymmNonceSize)
+        @throw([NSException exceptionWithName:@"BadSymmetricNonceSizeException" reason:@"Invalid symmetric nonce size" userInfo:nil]);
+    
+    NSUInteger mlen = plaintext.length + crypto_secretbox_ZEROBYTES;
+    char *ctbuf = malloc(mlen);
+    if (ctbuf == NULL) {
+        @throw([NSException exceptionWithName:@"MemoryAllocationException" reason:@"Cannot allocate memory" userInfo:nil]);
+    }
+    bzero(ctbuf, crypto_secretbox_ZEROBYTES);
+    memcpy(&ctbuf[crypto_secretbox_ZEROBYTES], plaintext.bytes, plaintext.length);
+
+    if (crypto_secretbox((unsigned char *)ctbuf, (unsigned char *)ctbuf, mlen, nonce.bytes, key.bytes) != 0) {
+        /* shouldn't happen */
+        free(ctbuf);
+        @throw([NSException exceptionWithName:@"CryptoException" reason:@"Crypto error" userInfo:nil]);
+    }
+    
+    NSData *ciphertext = [NSData dataWithBytes:&ctbuf[crypto_secretbox_BOXZEROBYTES] length:(mlen - crypto_secretbox_BOXZEROBYTES)];
+    
+    free(ctbuf);
+    
+    return ciphertext;
+}
+
+- (NSData*)symmetricDecryptData:(NSData*)ciphertext withKey:(NSData*)key nonce:(NSData*)nonce {
+    
+    if (key.length != kNaClCryptoSymmKeySize)
+        @throw([NSException exceptionWithName:@"BadSymmetricKeySizeException" reason:@"Invalid symmetric key size" userInfo:nil]);
+    
+    if (nonce.length != kNaClCryptoSymmNonceSize)
+        @throw([NSException exceptionWithName:@"BadSymmetricNonceSizeException" reason:@"Invalid symmetric nonce size" userInfo:nil]);
+    
+    NSUInteger clen = ciphertext.length + crypto_secretbox_BOXZEROBYTES;
+    char *msgbuf = malloc(clen);
+    if (msgbuf == NULL)
+        @throw([NSException exceptionWithName:@"MemoryAllocationException" reason:@"Cannot allocate memory" userInfo:nil]);
+    bzero(msgbuf, crypto_secretbox_BOXZEROBYTES);
+    memcpy(&msgbuf[crypto_secretbox_BOXZEROBYTES], ciphertext.bytes, ciphertext.length);
+    
+    if (crypto_secretbox_open((unsigned char *)msgbuf, (unsigned char *)msgbuf, clen, nonce.bytes, key.bytes) != 0) {
+        /* probably bad signature */
+        free(msgbuf);
+        return nil;
+    }
+    
+    NSData *plaintext = [NSData dataWithBytes:&msgbuf[crypto_secretbox_ZEROBYTES] length:(clen - crypto_secretbox_ZEROBYTES)];
+    
+    free(msgbuf);
+    
+    return plaintext;
+}
+
+- (void)selfTest {
+    /* test vectors from tests/box.* in nacl distribution */
+    unsigned char _alicepk[] = {
+        0x85,0x20,0xf0,0x09,0x89,0x30,0xa7,0x54
+        ,0x74,0x8b,0x7d,0xdc,0xb4,0x3e,0xf7,0x5a
+        ,0x0d,0xbf,0x3a,0x0d,0x26,0x38,0x1a,0xf4
+        ,0xeb,0xa4,0xa9,0x8e,0xaa,0x9b,0x4e,0x6a
+    };
+    NSData *alicepk = [NSData dataWithBytes:_alicepk length:sizeof(_alicepk)];
+    
+    unsigned char _alicesk[] = {
+        0x77,0x07,0x6d,0x0a,0x73,0x18,0xa5,0x7d
+        ,0x3c,0x16,0xc1,0x72,0x51,0xb2,0x66,0x45
+        ,0xdf,0x4c,0x2f,0x87,0xeb,0xc0,0x99,0x2a
+        ,0xb1,0x77,0xfb,0xa5,0x1d,0xb9,0x2c,0x2a
+    };
+    NSData *alicesk = [NSData dataWithBytes:_alicesk length:sizeof(_alicesk)];
+    
+    unsigned char _bobpk[] = {
+        0xde,0x9e,0xdb,0x7d,0x7b,0x7d,0xc1,0xb4
+        ,0xd3,0x5b,0x61,0xc2,0xec,0xe4,0x35,0x37
+        ,0x3f,0x83,0x43,0xc8,0x5b,0x78,0x67,0x4d
+        ,0xad,0xfc,0x7e,0x14,0x6f,0x88,0x2b,0x4f
+    };
+    NSData *bobpk = [NSData dataWithBytes:_bobpk length:sizeof(_bobpk)];
+    
+    unsigned char _bobsk[] = {
+        0x5d,0xab,0x08,0x7e,0x62,0x4a,0x8a,0x4b
+        ,0x79,0xe1,0x7f,0x8b,0x83,0x80,0x0e,0xe6
+        ,0x6f,0x3b,0xb1,0x29,0x26,0x18,0xb6,0xfd
+        ,0x1c,0x2f,0x8b,0x27,0xff,0x88,0xe0,0xeb
+    };
+    NSData *bobsk = [NSData dataWithBytes:_bobsk length:sizeof(_bobsk)];
+    
+    unsigned char _nonce[] = {
+        0x69,0x69,0x6e,0xe9,0x55,0xb6,0x2b,0x73
+        ,0xcd,0x62,0xbd,0xa8,0x75,0xfc,0x73,0xd6
+        ,0x82,0x19,0xe0,0x03,0x6b,0x7a,0x0b,0x37
+    };
+    NSData *nonce = [NSData dataWithBytes:_nonce length:sizeof(_nonce)];
+    
+    unsigned char _m[] = {
+        0xbe,0x07,0x5f,0xc5,0x3c,0x81,0xf2,0xd5
+        ,0xcf,0x14,0x13,0x16,0xeb,0xeb,0x0c,0x7b
+        ,0x52,0x28,0xc5,0x2a,0x4c,0x62,0xcb,0xd4
+        ,0x4b,0x66,0x84,0x9b,0x64,0x24,0x4f,0xfc
+        ,0xe5,0xec,0xba,0xaf,0x33,0xbd,0x75,0x1a
+        ,0x1a,0xc7,0x28,0xd4,0x5e,0x6c,0x61,0x29
+        ,0x6c,0xdc,0x3c,0x01,0x23,0x35,0x61,0xf4
+        ,0x1d,0xb6,0x6c,0xce,0x31,0x4a,0xdb,0x31
+        ,0x0e,0x3b,0xe8,0x25,0x0c,0x46,0xf0,0x6d
+        ,0xce,0xea,0x3a,0x7f,0xa1,0x34,0x80,0x57
+        ,0xe2,0xf6,0x55,0x6a,0xd6,0xb1,0x31,0x8a
+        ,0x02,0x4a,0x83,0x8f,0x21,0xaf,0x1f,0xde
+        ,0x04,0x89,0x77,0xeb,0x48,0xf5,0x9f,0xfd
+        ,0x49,0x24,0xca,0x1c,0x60,0x90,0x2e,0x52
+        ,0xf0,0xa0,0x89,0xbc,0x76,0x89,0x70,0x40
+        ,0xe0,0x82,0xf9,0x37,0x76,0x38,0x48,0x64
+        ,0x5e,0x07,0x05
+    };
+    NSData *m = [NSData dataWithBytes:_m length:sizeof(_m)];
+    
+    unsigned char _c_expected[] = {
+        0xf3,0xff,0xc7,0x70,0x3f,0x94,0x00,0xe5
+        ,0x2a,0x7d,0xfb,0x4b,0x3d,0x33,0x05,0xd9
+        ,0x8e,0x99,0x3b,0x9f,0x48,0x68,0x12,0x73
+        ,0xc2,0x96,0x50,0xba,0x32,0xfc,0x76,0xce
+        ,0x48,0x33,0x2e,0xa7,0x16,0x4d,0x96,0xa4
+        ,0x47,0x6f,0xb8,0xc5,0x31,0xa1,0x18,0x6a
+        ,0xc0,0xdf,0xc1,0x7c,0x98,0xdc,0xe8,0x7b
+        ,0x4d,0xa7,0xf0,0x11,0xec,0x48,0xc9,0x72
+        ,0x71,0xd2,0xc2,0x0f,0x9b,0x92,0x8f,0xe2
+        ,0x27,0x0d,0x6f,0xb8,0x63,0xd5,0x17,0x38
+        ,0xb4,0x8e,0xee,0xe3,0x14,0xa7,0xcc,0x8a
+        ,0xb9,0x32,0x16,0x45,0x48,0xe5,0x26,0xae
+        ,0x90,0x22,0x43,0x68,0x51,0x7a,0xcf,0xea
+        ,0xbd,0x6b,0xb3,0x73,0x2b,0xc0,0xe9,0xda
+        ,0x99,0x83,0x2b,0x61,0xca,0x01,0xb6,0xde
+        ,0x56,0x24,0x4a,0x9e,0x88,0xd5,0xf9,0xb3
+        ,0x79,0x73,0xf6,0x22,0xa4,0x3d,0x14,0xa6
+        ,0x59,0x9b,0x1f,0x65,0x4c,0xb4,0x5a,0x74
+        ,0xe3,0x55,0xa5
+    };
+    NSData *c_expected = [NSData dataWithBytes:_c_expected length:sizeof(_c_expected)];
+    
+    /* encrypt data and compare with expected result */
+    NSData *c = [self encryptData:m withPublicKey:bobpk signKey:alicesk nonce:nonce];
+    if (![c_expected isEqualToData:c]) {
+        @throw([NSException exceptionWithName:@"CryptoSelfTestFailedException" reason:@"Crypto self-test failed" userInfo:nil]);
+    }
+    
+    /* decrypt data and compare with plaintext */
+    NSData *p_d = [self decryptData:c withSecretKey:bobsk signKey:alicepk nonce:nonce];
+    if (![p_d isEqualToData:m]) {
+        @throw([NSException exceptionWithName:@"CryptoSelfTestFailedException" reason:@"Crypto self-test failed" userInfo:nil]);
+    }
+    
+    DDLogInfo(@"Crypto self-test passed");
+}
+
+- (void)longTest {
+    int i;
+    
+    for (i = 0; i < 1000; i++) {
+        int msglen = i + 1;
+        
+        NSData *pk1, *sk1, *pk2, *sk2;
+        [self generateKeyPairPublicKey:&pk1 secretKey:&sk1];
+        [self generateKeyPairPublicKey:&pk2 secretKey:&sk2];
+        
+        NSData *msg = [self randomBytes:msglen];
+        NSData *nonce = [self randomBytes:kNaClCryptoNonceSize];
+        
+        NSData *c = [self encryptData:msg withPublicKey:pk2 signKey:sk1 nonce:nonce];
+        NSData *newmsg = [self decryptData:c withSecretKey:sk2 signKey:pk1 nonce:nonce];
+        
+        if (![newmsg isEqualToData:msg]) {
+            @throw([NSException exceptionWithName:@"CryptoSelfTestFailedException" reason:@"Crypto self-test failed" userInfo:nil]);
+        }
+    }
+}
+
+- (NSData*)randomBytes:(int)len {
+    unsigned char *random = malloc(len);
+    if (random == NULL) {
+        @throw([NSException exceptionWithName:@"AllocMemoryForRandomBytesFailed" reason:@"Cannot allocate memory for random bytes" userInfo:nil]);
+    }
+    randombytes(random, len);
+    return [NSData dataWithBytesNoCopy:random length:len];
+}
+
+- (NSData*)zeroBytes:(int)len {
+    unsigned char *zero = malloc(len);
+    if (zero == NULL) {
+        @throw([NSException exceptionWithName:@"AllocMemoryForZeroBytesFailed" reason:@"Cannot allocate memory for zero bytes" userInfo:nil]);
+    }
+    bzero(zero, len);
+    return [NSData dataWithBytesNoCopy:zero length:len];
+}
+
+- (double)benchmark {
+    /* run 1000 encryption operations on a 1024 byte message
+       and return the number of encryption operations per second */
+    
+    DDLogInfo(@"Generating key...");
+    int i;
+    NSData *pk, *sk;
+    [self generateKeyPairPublicKey:&pk secretKey:&sk];
+    
+    DDLogInfo(@"Preparing message...");
+    unsigned char _msg[1024];
+    for (i = 0; i < 1024; i++)
+        _msg[i] = (i % 256);
+    NSData *msg = [NSData dataWithBytes:_msg length:1024];
+    
+    unsigned char _nonce[kNaClCryptoNonceSize];
+    for (i = 0; i < kNaClCryptoNonceSize; i++)
+        _nonce[i] = (i % 256);
+    NSData *nonce = [NSData dataWithBytes:_nonce length:kNaClCryptoNonceSize];
+
+    DDLogInfo(@"Benchmarking...");
+    NSDate *start = [NSDate date];
+    for (i = 0; i < 1000; i++) {
+        [self encryptData:msg withPublicKey:pk signKey:sk nonce:nonce];
+    }
+    DDLogInfo(@"Benchmark done.");
+    return (1000 / ([start timeIntervalSinceNow] * -1.0));
+}
+
+@end

+ 22 - 0
NaClCrypto/nacl/crypto_box/curve25519xsalsa20poly1305/ref/after.c

@@ -0,0 +1,22 @@
+#include "crypto_secretbox_xsalsa20poly1305.h"
+#include "crypto_box.h"
+
+int crypto_box_curve25519xsalsa20poly1305_ref_afternm(
+  unsigned char *c,
+  const unsigned char *m,unsigned long long mlen,
+  const unsigned char *n,
+  const unsigned char *k
+)
+{
+  return crypto_secretbox_xsalsa20poly1305(c,m,mlen,n,k);
+}
+
+int crypto_box_curve25519xsalsa20poly1305_ref_open_afternm(
+  unsigned char *m,
+  const unsigned char *c,unsigned long long clen,
+  const unsigned char *n,
+  const unsigned char *k
+)
+{
+  return crypto_secretbox_xsalsa20poly1305_open(m,c,clen,n,k);
+}

+ 6 - 0
NaClCrypto/nacl/crypto_box/curve25519xsalsa20poly1305/ref/api.h

@@ -0,0 +1,6 @@
+#define CRYPTO_PUBLICKEYBYTES 32
+#define CRYPTO_SECRETKEYBYTES 32
+#define CRYPTO_BEFORENMBYTES 32
+#define CRYPTO_NONCEBYTES 24
+#define CRYPTO_ZEROBYTES 32
+#define CRYPTO_BOXZEROBYTES 16

+ 17 - 0
NaClCrypto/nacl/crypto_box/curve25519xsalsa20poly1305/ref/before.c

@@ -0,0 +1,17 @@
+#include "crypto_core_hsalsa20.h"
+#include "crypto_scalarmult_curve25519.h"
+#include "crypto_box.h"
+
+static const unsigned char sigma[16] = "expand 32-byte k";
+static const unsigned char n[16] = {0};
+
+int crypto_box_curve25519xsalsa20poly1305_ref_beforenm(
+  unsigned char *k,
+  const unsigned char *pk,
+  const unsigned char *sk
+)
+{
+  unsigned char s[32];
+  crypto_scalarmult_curve25519(s,sk,pk);
+  return crypto_core_hsalsa20(k,n,s,sigma);
+}

+ 27 - 0
NaClCrypto/nacl/crypto_box/curve25519xsalsa20poly1305/ref/box.c

@@ -0,0 +1,27 @@
+#include "crypto_box.h"
+
+int crypto_box_curve25519xsalsa20poly1305_ref(
+  unsigned char *c,
+  const unsigned char *m,unsigned long long mlen,
+  const unsigned char *n,
+  const unsigned char *pk,
+  const unsigned char *sk
+)
+{
+  unsigned char k[crypto_box_BEFORENMBYTES];
+  crypto_box_beforenm(k,pk,sk);
+  return crypto_box_afternm(c,m,mlen,n,k);
+}
+
+int crypto_box_curve25519xsalsa20poly1305_ref_open(
+  unsigned char *m,
+  const unsigned char *c,unsigned long long clen,
+  const unsigned char *n,
+  const unsigned char *pk,
+  const unsigned char *sk
+)
+{
+  unsigned char k[crypto_box_BEFORENMBYTES];
+  crypto_box_beforenm(k,pk,sk);
+  return crypto_box_open_afternm(m,c,clen,n,k);
+}

+ 12 - 0
NaClCrypto/nacl/crypto_box/curve25519xsalsa20poly1305/ref/keypair.c

@@ -0,0 +1,12 @@
+#include "crypto_scalarmult_curve25519.h"
+#include "crypto_box.h"
+#include "randombytes.h"
+
+int crypto_box_curve25519xsalsa20poly1305_ref_keypair(
+  unsigned char *pk,
+  unsigned char *sk
+)
+{
+  randombytes(sk,32);
+  return crypto_scalarmult_curve25519_base(pk,sk);
+}

+ 4 - 0
NaClCrypto/nacl/crypto_core/hsalsa20/ref/api.h

@@ -0,0 +1,4 @@
+#define CRYPTO_OUTPUTBYTES 32
+#define CRYPTO_INPUTBYTES 16
+#define CRYPTO_KEYBYTES 32
+#define CRYPTO_CONSTBYTES 16

+ 135 - 0
NaClCrypto/nacl/crypto_core/hsalsa20/ref/core.c

@@ -0,0 +1,135 @@
+/*
+version 20080912
+D. J. Bernstein
+Public domain.
+*/
+
+#include "crypto_core_hsalsa20.h"
+
+#define ROUNDS 20
+
+typedef unsigned int uint32;
+
+static uint32 rotate(uint32 u,int c)
+{
+    return (u << c) | (u >> (32 - c));
+}
+
+static uint32 load_littleendian(const unsigned char *x)
+{
+    return
+    (uint32) (x[0]) \
+    | (((uint32) (x[1])) << 8) \
+    | (((uint32) (x[2])) << 16) \
+    | (((uint32) (x[3])) << 24)
+    ;
+}
+
+static void store_littleendian(unsigned char *x,uint32 u)
+{
+    x[0] = u; u >>= 8;
+    x[1] = u; u >>= 8;
+    x[2] = u; u >>= 8;
+    x[3] = u;
+}
+
+int crypto_core_hsalsa20_ref(
+        unsigned char *out,
+  const unsigned char *in,
+  const unsigned char *k,
+  const unsigned char *c
+)
+{
+  uint32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
+  uint32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
+  int i;
+
+  j0 = x0 = load_littleendian(c + 0);
+  j1 = x1 = load_littleendian(k + 0);
+  j2 = x2 = load_littleendian(k + 4);
+  j3 = x3 = load_littleendian(k + 8);
+  j4 = x4 = load_littleendian(k + 12);
+  j5 = x5 = load_littleendian(c + 4);
+  j6 = x6 = load_littleendian(in + 0);
+  j7 = x7 = load_littleendian(in + 4);
+  j8 = x8 = load_littleendian(in + 8);
+  j9 = x9 = load_littleendian(in + 12);
+  j10 = x10 = load_littleendian(c + 8);
+  j11 = x11 = load_littleendian(k + 16);
+  j12 = x12 = load_littleendian(k + 20);
+  j13 = x13 = load_littleendian(k + 24);
+  j14 = x14 = load_littleendian(k + 28);
+  j15 = x15 = load_littleendian(c + 12);
+
+  for (i = ROUNDS;i > 0;i -= 2) {
+     x4 ^= rotate( x0+x12, 7);
+     x8 ^= rotate( x4+ x0, 9);
+    x12 ^= rotate( x8+ x4,13);
+     x0 ^= rotate(x12+ x8,18);
+     x9 ^= rotate( x5+ x1, 7);
+    x13 ^= rotate( x9+ x5, 9);
+     x1 ^= rotate(x13+ x9,13);
+     x5 ^= rotate( x1+x13,18);
+    x14 ^= rotate(x10+ x6, 7);
+     x2 ^= rotate(x14+x10, 9);
+     x6 ^= rotate( x2+x14,13);
+    x10 ^= rotate( x6+ x2,18);
+     x3 ^= rotate(x15+x11, 7);
+     x7 ^= rotate( x3+x15, 9);
+    x11 ^= rotate( x7+ x3,13);
+    x15 ^= rotate(x11+ x7,18);
+     x1 ^= rotate( x0+ x3, 7);
+     x2 ^= rotate( x1+ x0, 9);
+     x3 ^= rotate( x2+ x1,13);
+     x0 ^= rotate( x3+ x2,18);
+     x6 ^= rotate( x5+ x4, 7);
+     x7 ^= rotate( x6+ x5, 9);
+     x4 ^= rotate( x7+ x6,13);
+     x5 ^= rotate( x4+ x7,18);
+    x11 ^= rotate(x10+ x9, 7);
+     x8 ^= rotate(x11+x10, 9);
+     x9 ^= rotate( x8+x11,13);
+    x10 ^= rotate( x9+ x8,18);
+    x12 ^= rotate(x15+x14, 7);
+    x13 ^= rotate(x12+x15, 9);
+    x14 ^= rotate(x13+x12,13);
+    x15 ^= rotate(x14+x13,18);
+  }
+
+  x0 += j0;
+  x1 += j1;
+  x2 += j2;
+  x3 += j3;
+  x4 += j4;
+  x5 += j5;
+  x6 += j6;
+  x7 += j7;
+  x8 += j8;
+  x9 += j9;
+  x10 += j10;
+  x11 += j11;
+  x12 += j12;
+  x13 += j13;
+  x14 += j14;
+  x15 += j15;
+
+  x0 -= load_littleendian(c + 0);
+  x5 -= load_littleendian(c + 4);
+  x10 -= load_littleendian(c + 8);
+  x15 -= load_littleendian(c + 12);
+  x6 -= load_littleendian(in + 0);
+  x7 -= load_littleendian(in + 4);
+  x8 -= load_littleendian(in + 8);
+  x9 -= load_littleendian(in + 12);
+
+  store_littleendian(out + 0,x0);
+  store_littleendian(out + 4,x5);
+  store_littleendian(out + 8,x10);
+  store_littleendian(out + 12,x15);
+  store_littleendian(out + 16,x6);
+  store_littleendian(out + 20,x7);
+  store_littleendian(out + 24,x8);
+  store_littleendian(out + 28,x9);
+
+  return 0;
+}

+ 4 - 0
NaClCrypto/nacl/crypto_core/salsa20/ref/api.h

@@ -0,0 +1,4 @@
+#define CRYPTO_OUTPUTBYTES 64
+#define CRYPTO_INPUTBYTES 16
+#define CRYPTO_KEYBYTES 32
+#define CRYPTO_CONSTBYTES 16

+ 134 - 0
NaClCrypto/nacl/crypto_core/salsa20/ref/core.c

@@ -0,0 +1,134 @@
+/*
+version 20080912
+D. J. Bernstein
+Public domain.
+*/
+
+#include "crypto_core.h"
+
+#define ROUNDS 20
+
+typedef unsigned int uint32;
+
+static uint32 rotate(uint32 u,int c)
+{
+    return (u << c) | (u >> (32 - c));
+}
+
+static uint32 load_littleendian(const unsigned char *x)
+{
+    return
+    (uint32) (x[0]) \
+    | (((uint32) (x[1])) << 8) \
+    | (((uint32) (x[2])) << 16) \
+    | (((uint32) (x[3])) << 24)
+    ;
+}
+
+static void store_littleendian(unsigned char *x,uint32 u)
+{
+    x[0] = u; u >>= 8;
+    x[1] = u; u >>= 8;
+    x[2] = u; u >>= 8;
+    x[3] = u;
+}
+
+int crypto_core_salsa20_ref(
+        unsigned char *out,
+  const unsigned char *in,
+  const unsigned char *k,
+  const unsigned char *c
+)
+{
+  uint32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
+  uint32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
+  int i;
+
+  j0 = x0 = load_littleendian(c + 0);
+  j1 = x1 = load_littleendian(k + 0);
+  j2 = x2 = load_littleendian(k + 4);
+  j3 = x3 = load_littleendian(k + 8);
+  j4 = x4 = load_littleendian(k + 12);
+  j5 = x5 = load_littleendian(c + 4);
+  j6 = x6 = load_littleendian(in + 0);
+  j7 = x7 = load_littleendian(in + 4);
+  j8 = x8 = load_littleendian(in + 8);
+  j9 = x9 = load_littleendian(in + 12);
+  j10 = x10 = load_littleendian(c + 8);
+  j11 = x11 = load_littleendian(k + 16);
+  j12 = x12 = load_littleendian(k + 20);
+  j13 = x13 = load_littleendian(k + 24);
+  j14 = x14 = load_littleendian(k + 28);
+  j15 = x15 = load_littleendian(c + 12);
+
+  for (i = ROUNDS;i > 0;i -= 2) {
+     x4 ^= rotate( x0+x12, 7);
+     x8 ^= rotate( x4+ x0, 9);
+    x12 ^= rotate( x8+ x4,13);
+     x0 ^= rotate(x12+ x8,18);
+     x9 ^= rotate( x5+ x1, 7);
+    x13 ^= rotate( x9+ x5, 9);
+     x1 ^= rotate(x13+ x9,13);
+     x5 ^= rotate( x1+x13,18);
+    x14 ^= rotate(x10+ x6, 7);
+     x2 ^= rotate(x14+x10, 9);
+     x6 ^= rotate( x2+x14,13);
+    x10 ^= rotate( x6+ x2,18);
+     x3 ^= rotate(x15+x11, 7);
+     x7 ^= rotate( x3+x15, 9);
+    x11 ^= rotate( x7+ x3,13);
+    x15 ^= rotate(x11+ x7,18);
+     x1 ^= rotate( x0+ x3, 7);
+     x2 ^= rotate( x1+ x0, 9);
+     x3 ^= rotate( x2+ x1,13);
+     x0 ^= rotate( x3+ x2,18);
+     x6 ^= rotate( x5+ x4, 7);
+     x7 ^= rotate( x6+ x5, 9);
+     x4 ^= rotate( x7+ x6,13);
+     x5 ^= rotate( x4+ x7,18);
+    x11 ^= rotate(x10+ x9, 7);
+     x8 ^= rotate(x11+x10, 9);
+     x9 ^= rotate( x8+x11,13);
+    x10 ^= rotate( x9+ x8,18);
+    x12 ^= rotate(x15+x14, 7);
+    x13 ^= rotate(x12+x15, 9);
+    x14 ^= rotate(x13+x12,13);
+    x15 ^= rotate(x14+x13,18);
+  }
+
+  x0 += j0;
+  x1 += j1;
+  x2 += j2;
+  x3 += j3;
+  x4 += j4;
+  x5 += j5;
+  x6 += j6;
+  x7 += j7;
+  x8 += j8;
+  x9 += j9;
+  x10 += j10;
+  x11 += j11;
+  x12 += j12;
+  x13 += j13;
+  x14 += j14;
+  x15 += j15;
+
+  store_littleendian(out + 0,x0);
+  store_littleendian(out + 4,x1);
+  store_littleendian(out + 8,x2);
+  store_littleendian(out + 12,x3);
+  store_littleendian(out + 16,x4);
+  store_littleendian(out + 20,x5);
+  store_littleendian(out + 24,x6);
+  store_littleendian(out + 28,x7);
+  store_littleendian(out + 32,x8);
+  store_littleendian(out + 36,x9);
+  store_littleendian(out + 40,x10);
+  store_littleendian(out + 44,x11);
+  store_littleendian(out + 48,x12);
+  store_littleendian(out + 52,x13);
+  store_littleendian(out + 56,x14);
+  store_littleendian(out + 60,x15);
+
+  return 0;
+}

+ 2 - 0
NaClCrypto/nacl/crypto_onetimeauth/poly1305/53/api.h

@@ -0,0 +1,2 @@
+#define CRYPTO_BYTES 16
+#define CRYPTO_KEYBYTES 32

+ 1616 - 0
NaClCrypto/nacl/crypto_onetimeauth/poly1305/53/auth.c

@@ -0,0 +1,1616 @@
+/*
+20080910
+D. J. Bernstein
+Public domain.
+*/
+
+#include "crypto_onetimeauth.h"
+
+typedef unsigned char uchar;
+typedef int int32;
+typedef unsigned int uint32;
+typedef long long int64;
+typedef unsigned long long uint64;
+
+static const double poly1305_53_constants[] = {
+  0.00000000558793544769287109375 /* alpham80 = 3 2^(-29) */
+, 24.0 /* alpham48 = 3 2^3 */
+, 103079215104.0 /* alpham16 = 3 2^35 */
+, 6755399441055744.0 /* alpha0 = 3 2^51 */
+, 1770887431076116955136.0 /* alpha18 = 3 2^69 */
+, 29014219670751100192948224.0 /* alpha32 = 3 2^83 */
+, 7605903601369376408980219232256.0 /* alpha50 = 3 2^101 */
+, 124615124604835863084731911901282304.0 /* alpha64 = 3 2^115 */
+, 32667107224410092492483962313449748299776.0 /* alpha82 = 3 2^133 */
+, 535217884764734955396857238543560676143529984.0 /* alpha96 = 3 2^147 */
+, 35076039295941670036888435985190792471742381031424.0 /* alpha112 = 3 2^163 */
+, 9194973245195333150150082162901855101712434733101613056.0 /* alpha130 = 3 2^181 */
+, 0.0000000000000000000000000000000000000036734198463196484624023016788195177431833298649127735047148490821200539357960224151611328125 /* scale = 5 2^(-130) */
+, 6755408030990331.0 /* offset0 = alpha0 + 2^33 - 5 */
+, 29014256564239239022116864.0 /* offset1 = alpha32 + 2^65 - 2^33 */
+, 124615283061160854719918951570079744.0 /* offset2 = alpha64 + 2^97 - 2^65 */
+, 535219245894202480694386063513315216128475136.0 /* offset3 = alpha96 + 2^130 - 2^97 */
+} ;
+
+int crypto_onetimeauth_poly1305_53(unsigned char *out,const unsigned char *m,unsigned long long l,const unsigned char *k)
+{
+  register const unsigned char *r = k;
+  register const unsigned char *s = k + 16;
+  double r0high_stack;
+  double r1high_stack;
+  double r1low_stack;
+  double sr1high_stack;
+  double r2low_stack;
+  double sr2high_stack;
+  double r0low_stack;
+  double sr1low_stack;
+  double r2high_stack;
+  double sr2low_stack;
+  double r3high_stack;
+  double sr3high_stack;
+  double r3low_stack;
+  double sr3low_stack;
+  int64 d0;
+  int64 d1;
+  int64 d2;
+  int64 d3;
+  register double scale;
+  register double alpha0;
+  register double alpha32;
+  register double alpha64;
+  register double alpha96;
+  register double alpha130;
+  register double h0;
+  register double h1;
+  register double h2;
+  register double h3;
+  register double h4;
+  register double h5;
+  register double h6;
+  register double h7;
+  register double y7;
+  register double y6;
+  register double y1;
+  register double y0;
+  register double y5;
+  register double y4;
+  register double x7;
+  register double x6;
+  register double x1;
+  register double x0;
+  register double y3;
+  register double y2;
+  register double r3low;
+  register double r0low;
+  register double r3high;
+  register double r0high;
+  register double sr1low;
+  register double x5;
+  register double r3lowx0;
+  register double sr1high;
+  register double x4;
+  register double r0lowx6;
+  register double r1low;
+  register double x3;
+  register double r3highx0;
+  register double r1high;
+  register double x2;
+  register double r0highx6;
+  register double sr2low;
+  register double r0lowx0;
+  register double sr2high;
+  register double sr1lowx6;
+  register double r2low;
+  register double r0highx0;
+  register double r2high;
+  register double sr1highx6;
+  register double sr3low;
+  register double r1lowx0;
+  register double sr3high;
+  register double sr2lowx6;
+  register double r1highx0;
+  register double sr2highx6;
+  register double r2lowx0;
+  register double sr3lowx6;
+  register double r2highx0;
+  register double sr3highx6;
+  register double r1highx4;
+  register double r1lowx4;
+  register double r0highx4;
+  register double r0lowx4;
+  register double sr3highx4;
+  register double sr3lowx4;
+  register double sr2highx4;
+  register double sr2lowx4;
+  register double r0lowx2;
+  register double r0highx2;
+  register double r1lowx2;
+  register double r1highx2;
+  register double r2lowx2;
+  register double r2highx2;
+  register double sr3lowx2;
+  register double sr3highx2;
+  register double z0;
+  register double z1;
+  register double z2;
+  register double z3;
+  register int64 r0;
+  register int64 r1;
+  register int64 r2;
+  register int64 r3;
+  register uint32 r00;
+  register uint32 r01;
+  register uint32 r02;
+  register uint32 r03;
+  register uint32 r10;
+  register uint32 r11;
+  register uint32 r12;
+  register uint32 r13;
+  register uint32 r20;
+  register uint32 r21;
+  register uint32 r22;
+  register uint32 r23;
+  register uint32 r30;
+  register uint32 r31;
+  register uint32 r32;
+  register uint32 r33;
+  register int64 m0;
+  register int64 m1;
+  register int64 m2;
+  register int64 m3;
+  register uint32 m00;
+  register uint32 m01;
+  register uint32 m02;
+  register uint32 m03;
+  register uint32 m10;
+  register uint32 m11;
+  register uint32 m12;
+  register uint32 m13;
+  register uint32 m20;
+  register uint32 m21;
+  register uint32 m22;
+  register uint32 m23;
+  register uint32 m30;
+  register uint32 m31;
+  register uint32 m32;
+  register uint64 m33;
+  register char *constants;
+  register int32 lbelow2;
+  register int32 lbelow3;
+  register int32 lbelow4;
+  register int32 lbelow5;
+  register int32 lbelow6;
+  register int32 lbelow7;
+  register int32 lbelow8;
+  register int32 lbelow9;
+  register int32 lbelow10;
+  register int32 lbelow11;
+  register int32 lbelow12;
+  register int32 lbelow13;
+  register int32 lbelow14;
+  register int32 lbelow15;
+  register double alpham80;
+  register double alpham48;
+  register double alpham16;
+  register double alpha18;
+  register double alpha50;
+  register double alpha82;
+  register double alpha112;
+  register double offset0;
+  register double offset1;
+  register double offset2;
+  register double offset3;
+  register uint32 s00;
+  register uint32 s01;
+  register uint32 s02;
+  register uint32 s03;
+  register uint32 s10;
+  register uint32 s11;
+  register uint32 s12;
+  register uint32 s13;
+  register uint32 s20;
+  register uint32 s21;
+  register uint32 s22;
+  register uint32 s23;
+  register uint32 s30;
+  register uint32 s31;
+  register uint32 s32;
+  register uint32 s33;
+  register uint64 bits32;
+  register uint64 f;
+  register uint64 f0;
+  register uint64 f1;
+  register uint64 f2;
+  register uint64 f3;
+  register uint64 f4;
+  register uint64 g;
+  register uint64 g0;
+  register uint64 g1;
+  register uint64 g2;
+  register uint64 g3;
+  register uint64 g4;
+
+  r00 = *(uchar *) (r + 0);
+  constants = (char *) &poly1305_53_constants;
+
+  r01 = *(uchar *) (r + 1);
+
+  r02 = *(uchar *) (r + 2);
+  r0 = 2151;
+
+  r03 = *(uchar *) (r + 3); r03 &= 15;
+  r0 <<= 51;
+
+  r10 = *(uchar *) (r + 4); r10 &= 252;
+  r01 <<= 8;
+  r0 += r00;
+
+  r11 = *(uchar *) (r + 5);
+  r02 <<= 16;
+  r0 += r01;
+
+  r12 = *(uchar *) (r + 6);
+  r03 <<= 24;
+  r0 += r02;
+
+  r13 = *(uchar *) (r + 7); r13 &= 15;
+  r1 = 2215;
+  r0 += r03;
+
+  d0 = r0;
+  r1 <<= 51;
+  r2 = 2279;
+
+  r20 = *(uchar *) (r + 8); r20 &= 252;
+  r11 <<= 8;
+  r1 += r10;
+
+  r21 = *(uchar *) (r + 9);
+  r12 <<= 16;
+  r1 += r11;
+
+  r22 = *(uchar *) (r + 10);
+  r13 <<= 24;
+  r1 += r12;
+
+  r23 = *(uchar *) (r + 11); r23 &= 15;
+  r2 <<= 51;
+  r1 += r13;
+
+  d1 = r1;
+  r21 <<= 8;
+  r2 += r20;
+
+  r30 = *(uchar *) (r + 12); r30 &= 252;
+  r22 <<= 16;
+  r2 += r21;
+
+  r31 = *(uchar *) (r + 13);
+  r23 <<= 24;
+  r2 += r22;
+
+  r32 = *(uchar *) (r + 14);
+  r2 += r23;
+  r3 = 2343;
+
+  d2 = r2;
+  r3 <<= 51;
+  alpha32 = *(double *) (constants + 40);
+
+  r33 = *(uchar *) (r + 15); r33 &= 15;
+  r31 <<= 8;
+  r3 += r30;
+
+  r32 <<= 16;
+  r3 += r31;
+
+  r33 <<= 24;
+  r3 += r32;
+
+  r3 += r33;
+  h0 = alpha32 - alpha32;
+
+  d3 = r3;
+  h1 = alpha32 - alpha32;
+
+  alpha0 = *(double *) (constants + 24);
+  h2 = alpha32 - alpha32;
+
+  alpha64 = *(double *) (constants + 56);
+  h3 = alpha32 - alpha32;
+
+  alpha18 = *(double *) (constants + 32);
+  h4 = alpha32 - alpha32;
+
+  r0low = *(double *) &d0;
+  h5 = alpha32 - alpha32;
+
+  r1low = *(double *) &d1;
+  h6 = alpha32 - alpha32;
+
+  r2low = *(double *) &d2;
+  h7 = alpha32 - alpha32;
+
+  alpha50 = *(double *) (constants + 48);
+  r0low -= alpha0;
+
+  alpha82 = *(double *) (constants + 64);
+  r1low -= alpha32;
+
+  scale = *(double *) (constants + 96);
+  r2low -= alpha64;
+
+  alpha96 = *(double *) (constants + 72);
+  r0high = r0low + alpha18;
+
+  r3low = *(double *) &d3;
+
+  alpham80 = *(double *) (constants + 0);
+  r1high = r1low + alpha50;
+  sr1low = scale * r1low;
+
+  alpham48 = *(double *) (constants + 8);
+  r2high = r2low + alpha82;
+  sr2low = scale * r2low;
+
+  r0high -= alpha18;
+  r0high_stack = r0high;
+
+  r3low -= alpha96;
+
+  r1high -= alpha50;
+  r1high_stack = r1high;
+
+  sr1high = sr1low + alpham80;
+
+  alpha112 = *(double *) (constants + 80);
+  r0low -= r0high;
+
+  alpham16 = *(double *) (constants + 16);
+  r2high -= alpha82;
+  sr3low = scale * r3low;
+
+  alpha130 = *(double *) (constants + 88);
+  sr2high = sr2low + alpham48;
+
+  r1low -= r1high;
+  r1low_stack = r1low;
+
+  sr1high -= alpham80;
+  sr1high_stack = sr1high;
+
+  r2low -= r2high;
+  r2low_stack = r2low;
+
+  sr2high -= alpham48;
+  sr2high_stack = sr2high;
+
+  r3high = r3low + alpha112;
+  r0low_stack = r0low;
+
+  sr1low -= sr1high;
+  sr1low_stack = sr1low;
+
+  sr3high = sr3low + alpham16;
+  r2high_stack = r2high;
+
+  sr2low -= sr2high;
+  sr2low_stack = sr2low;
+
+  r3high -= alpha112;
+  r3high_stack = r3high;
+
+
+  sr3high -= alpham16;
+  sr3high_stack = sr3high;
+
+
+  r3low -= r3high;
+  r3low_stack = r3low;
+
+
+  sr3low -= sr3high;
+  sr3low_stack = sr3low;
+
+if (l < 16) goto addatmost15bytes;
+
+  m00 = *(uchar *) (m + 0);
+  m0 = 2151;
+
+  m0 <<= 51;
+  m1 = 2215;
+  m01 = *(uchar *) (m + 1);
+
+  m1 <<= 51;
+  m2 = 2279;
+  m02 = *(uchar *) (m + 2);
+
+  m2 <<= 51;
+  m3 = 2343;
+  m03 = *(uchar *) (m + 3);
+
+  m10 = *(uchar *) (m + 4);
+  m01 <<= 8;
+  m0 += m00;
+
+  m11 = *(uchar *) (m + 5);
+  m02 <<= 16;
+  m0 += m01;
+
+  m12 = *(uchar *) (m + 6);
+  m03 <<= 24;
+  m0 += m02;
+
+  m13 = *(uchar *) (m + 7);
+  m3 <<= 51;
+  m0 += m03;
+
+  m20 = *(uchar *) (m + 8);
+  m11 <<= 8;
+  m1 += m10;
+
+  m21 = *(uchar *) (m + 9);
+  m12 <<= 16;
+  m1 += m11;
+
+  m22 = *(uchar *) (m + 10);
+  m13 <<= 24;
+  m1 += m12;
+
+  m23 = *(uchar *) (m + 11);
+  m1 += m13;
+
+  m30 = *(uchar *) (m + 12);
+  m21 <<= 8;
+  m2 += m20;
+
+  m31 = *(uchar *) (m + 13);
+  m22 <<= 16;
+  m2 += m21;
+
+  m32 = *(uchar *) (m + 14);
+  m23 <<= 24;
+  m2 += m22;
+
+  m33 = *(uchar *) (m + 15);
+  m2 += m23;
+
+  d0 = m0;
+  m31 <<= 8;
+  m3 += m30;
+
+  d1 = m1;
+  m32 <<= 16;
+  m3 += m31;
+
+  d2 = m2;
+  m33 += 256;
+
+  m33 <<= 24;
+  m3 += m32;
+
+  m3 += m33;
+  d3 = m3;
+
+  m += 16;
+  l -= 16;
+
+  z0 = *(double *) &d0;
+
+  z1 = *(double *) &d1;
+
+  z2 = *(double *) &d2;
+
+  z3 = *(double *) &d3;
+
+  z0 -= alpha0;
+
+  z1 -= alpha32;
+
+  z2 -= alpha64;
+
+  z3 -= alpha96;
+
+  h0 += z0;
+
+  h1 += z1;
+
+  h3 += z2;
+
+  h5 += z3;
+
+if (l < 16) goto multiplyaddatmost15bytes;
+
+multiplyaddatleast16bytes:;
+
+  m2 = 2279;
+  m20 = *(uchar *) (m + 8);
+  y7 = h7 + alpha130;
+
+  m2 <<= 51;
+  m3 = 2343;
+  m21 = *(uchar *) (m + 9);
+  y6 = h6 + alpha130;
+
+  m3 <<= 51;
+  m0 = 2151;
+  m22 = *(uchar *) (m + 10);
+  y1 = h1 + alpha32;
+
+  m0 <<= 51;
+  m1 = 2215;
+  m23 = *(uchar *) (m + 11);
+  y0 = h0 + alpha32;
+
+  m1 <<= 51;
+  m30 = *(uchar *) (m + 12);
+  y7 -= alpha130;
+
+  m21 <<= 8;
+  m2 += m20;
+  m31 = *(uchar *) (m + 13);
+  y6 -= alpha130;
+
+  m22 <<= 16;
+  m2 += m21;
+  m32 = *(uchar *) (m + 14);
+  y1 -= alpha32;
+
+  m23 <<= 24;
+  m2 += m22;
+  m33 = *(uchar *) (m + 15);
+  y0 -= alpha32;
+
+  m2 += m23;
+  m00 = *(uchar *) (m + 0);
+  y5 = h5 + alpha96;
+
+  m31 <<= 8;
+  m3 += m30;
+  m01 = *(uchar *) (m + 1);
+  y4 = h4 + alpha96;
+
+  m32 <<= 16;
+  m02 = *(uchar *) (m + 2);
+  x7 = h7 - y7;
+  y7 *= scale;
+
+  m33 += 256;
+  m03 = *(uchar *) (m + 3);
+  x6 = h6 - y6;
+  y6 *= scale;
+
+  m33 <<= 24;
+  m3 += m31;
+  m10 = *(uchar *) (m + 4);
+  x1 = h1 - y1;
+
+  m01 <<= 8;
+  m3 += m32;
+  m11 = *(uchar *) (m + 5);
+  x0 = h0 - y0;
+
+  m3 += m33;
+  m0 += m00;
+  m12 = *(uchar *) (m + 6);
+  y5 -= alpha96;
+
+  m02 <<= 16;
+  m0 += m01;
+  m13 = *(uchar *) (m + 7);
+  y4 -= alpha96;
+
+  m03 <<= 24;
+  m0 += m02;
+  d2 = m2;
+  x1 += y7;
+
+  m0 += m03;
+  d3 = m3;
+  x0 += y6;
+
+  m11 <<= 8;
+  m1 += m10;
+  d0 = m0;
+  x7 += y5;
+
+  m12 <<= 16;
+  m1 += m11;
+  x6 += y4;
+
+  m13 <<= 24;
+  m1 += m12;
+  y3 = h3 + alpha64;
+
+  m1 += m13;
+  d1 = m1;
+  y2 = h2 + alpha64;
+
+  x0 += x1;
+
+  x6 += x7;
+
+  y3 -= alpha64;
+  r3low = r3low_stack;
+
+  y2 -= alpha64;
+  r0low = r0low_stack;
+
+  x5 = h5 - y5;
+  r3lowx0 = r3low * x0;
+  r3high = r3high_stack;
+
+  x4 = h4 - y4;
+  r0lowx6 = r0low * x6;
+  r0high = r0high_stack;
+
+  x3 = h3 - y3;
+  r3highx0 = r3high * x0;
+  sr1low = sr1low_stack;
+
+  x2 = h2 - y2;
+  r0highx6 = r0high * x6;
+  sr1high = sr1high_stack;
+
+  x5 += y3;
+  r0lowx0 = r0low * x0;
+  r1low = r1low_stack;
+
+  h6 = r3lowx0 + r0lowx6;
+  sr1lowx6 = sr1low * x6;
+  r1high = r1high_stack;
+
+  x4 += y2;
+  r0highx0 = r0high * x0;
+  sr2low = sr2low_stack;
+
+  h7 = r3highx0 + r0highx6;
+  sr1highx6 = sr1high * x6;
+  sr2high = sr2high_stack;
+
+  x3 += y1;
+  r1lowx0 = r1low * x0;
+  r2low = r2low_stack;
+
+  h0 = r0lowx0 + sr1lowx6;
+  sr2lowx6 = sr2low * x6;
+  r2high = r2high_stack;
+
+  x2 += y0;
+  r1highx0 = r1high * x0;
+  sr3low = sr3low_stack;
+
+  h1 = r0highx0 + sr1highx6;
+  sr2highx6 = sr2high * x6;
+  sr3high = sr3high_stack;
+
+  x4 += x5;
+  r2lowx0 = r2low * x0;
+  z2 = *(double *) &d2;
+
+  h2 = r1lowx0 + sr2lowx6;
+  sr3lowx6 = sr3low * x6;
+
+  x2 += x3;
+  r2highx0 = r2high * x0;
+  z3 = *(double *) &d3;
+
+  h3 = r1highx0 + sr2highx6;
+  sr3highx6 = sr3high * x6;
+
+  r1highx4 = r1high * x4;
+  z2 -= alpha64;
+
+  h4 = r2lowx0 + sr3lowx6;
+  r1lowx4 = r1low * x4;
+
+  r0highx4 = r0high * x4;
+  z3 -= alpha96;
+
+  h5 = r2highx0 + sr3highx6;
+  r0lowx4 = r0low * x4;
+
+  h7 += r1highx4;
+  sr3highx4 = sr3high * x4;
+
+  h6 += r1lowx4;
+  sr3lowx4 = sr3low * x4;
+
+  h5 += r0highx4;
+  sr2highx4 = sr2high * x4;
+
+  h4 += r0lowx4;
+  sr2lowx4 = sr2low * x4;
+
+  h3 += sr3highx4;
+  r0lowx2 = r0low * x2;
+
+  h2 += sr3lowx4;
+  r0highx2 = r0high * x2;
+
+  h1 += sr2highx4;
+  r1lowx2 = r1low * x2;
+
+  h0 += sr2lowx4;
+  r1highx2 = r1high * x2;
+
+  h2 += r0lowx2;
+  r2lowx2 = r2low * x2;
+
+  h3 += r0highx2;
+  r2highx2 = r2high * x2;
+
+  h4 += r1lowx2;
+  sr3lowx2 = sr3low * x2;
+
+  h5 += r1highx2;
+  sr3highx2 = sr3high * x2;
+  alpha0 = *(double *) (constants + 24);
+
+  m += 16;
+  h6 += r2lowx2;
+
+  l -= 16;
+  h7 += r2highx2;
+
+  z1 = *(double *) &d1;
+  h0 += sr3lowx2;
+
+  z0 = *(double *) &d0;
+  h1 += sr3highx2;
+
+  z1 -= alpha32;
+
+  z0 -= alpha0;
+
+  h5 += z3;
+
+  h3 += z2;
+
+  h1 += z1;
+
+  h0 += z0;
+
+if (l >= 16) goto multiplyaddatleast16bytes;
+
+multiplyaddatmost15bytes:;
+
+  y7 = h7 + alpha130;
+
+  y6 = h6 + alpha130;
+
+  y1 = h1 + alpha32;
+
+  y0 = h0 + alpha32;
+
+  y7 -= alpha130;
+
+  y6 -= alpha130;
+
+  y1 -= alpha32;
+
+  y0 -= alpha32;
+
+  y5 = h5 + alpha96;
+
+  y4 = h4 + alpha96;
+
+  x7 = h7 - y7;
+  y7 *= scale;
+
+  x6 = h6 - y6;
+  y6 *= scale;
+
+  x1 = h1 - y1;
+
+  x0 = h0 - y0;
+
+  y5 -= alpha96;
+
+  y4 -= alpha96;
+
+  x1 += y7;
+
+  x0 += y6;
+
+  x7 += y5;
+
+  x6 += y4;
+
+  y3 = h3 + alpha64;
+
+  y2 = h2 + alpha64;
+
+  x0 += x1;
+
+  x6 += x7;
+
+  y3 -= alpha64;
+  r3low = r3low_stack;
+
+  y2 -= alpha64;
+  r0low = r0low_stack;
+
+  x5 = h5 - y5;
+  r3lowx0 = r3low * x0;
+  r3high = r3high_stack;
+
+  x4 = h4 - y4;
+  r0lowx6 = r0low * x6;
+  r0high = r0high_stack;
+
+  x3 = h3 - y3;
+  r3highx0 = r3high * x0;
+  sr1low = sr1low_stack;
+
+  x2 = h2 - y2;
+  r0highx6 = r0high * x6;
+  sr1high = sr1high_stack;
+
+  x5 += y3;
+  r0lowx0 = r0low * x0;
+  r1low = r1low_stack;
+
+  h6 = r3lowx0 + r0lowx6;
+  sr1lowx6 = sr1low * x6;
+  r1high = r1high_stack;
+
+  x4 += y2;
+  r0highx0 = r0high * x0;
+  sr2low = sr2low_stack;
+
+  h7 = r3highx0 + r0highx6;
+  sr1highx6 = sr1high * x6;
+  sr2high = sr2high_stack;
+
+  x3 += y1;
+  r1lowx0 = r1low * x0;
+  r2low = r2low_stack;
+
+  h0 = r0lowx0 + sr1lowx6;
+  sr2lowx6 = sr2low * x6;
+  r2high = r2high_stack;
+
+  x2 += y0;
+  r1highx0 = r1high * x0;
+  sr3low = sr3low_stack;
+
+  h1 = r0highx0 + sr1highx6;
+  sr2highx6 = sr2high * x6;
+  sr3high = sr3high_stack;
+
+  x4 += x5;
+  r2lowx0 = r2low * x0;
+
+  h2 = r1lowx0 + sr2lowx6;
+  sr3lowx6 = sr3low * x6;
+
+  x2 += x3;
+  r2highx0 = r2high * x0;
+
+  h3 = r1highx0 + sr2highx6;
+  sr3highx6 = sr3high * x6;
+
+  r1highx4 = r1high * x4;
+
+  h4 = r2lowx0 + sr3lowx6;
+  r1lowx4 = r1low * x4;
+
+  r0highx4 = r0high * x4;
+
+  h5 = r2highx0 + sr3highx6;
+  r0lowx4 = r0low * x4;
+
+  h7 += r1highx4;
+  sr3highx4 = sr3high * x4;
+
+  h6 += r1lowx4;
+  sr3lowx4 = sr3low * x4;
+
+  h5 += r0highx4;
+  sr2highx4 = sr2high * x4;
+
+  h4 += r0lowx4;
+  sr2lowx4 = sr2low * x4;
+
+  h3 += sr3highx4;
+  r0lowx2 = r0low * x2;
+
+  h2 += sr3lowx4;
+  r0highx2 = r0high * x2;
+
+  h1 += sr2highx4;
+  r1lowx2 = r1low * x2;
+
+  h0 += sr2lowx4;
+  r1highx2 = r1high * x2;
+
+  h2 += r0lowx2;
+  r2lowx2 = r2low * x2;
+
+  h3 += r0highx2;
+  r2highx2 = r2high * x2;
+
+  h4 += r1lowx2;
+  sr3lowx2 = sr3low * x2;
+
+  h5 += r1highx2;
+  sr3highx2 = sr3high * x2;
+
+  h6 += r2lowx2;
+
+  h7 += r2highx2;
+
+  h0 += sr3lowx2;
+
+  h1 += sr3highx2;
+
+addatmost15bytes:;
+
+if (l == 0) goto nomorebytes;
+
+  lbelow2 = (int32)(l - 2);
+
+  lbelow3 = (int32)(l - 3);
+
+  lbelow2 >>= 31;
+  lbelow4 = (int32)(l - 4);
+
+  m00 = *(uchar *) (m + 0);
+  lbelow3 >>= 31;
+  m += lbelow2;
+
+  m01 = *(uchar *) (m + 1);
+  lbelow4 >>= 31;
+  m += lbelow3;
+
+  m02 = *(uchar *) (m + 2);
+  m += lbelow4;
+  m0 = 2151;
+
+  m03 = *(uchar *) (m + 3);
+  m0 <<= 51;
+  m1 = 2215;
+
+  m0 += m00;
+  m01 &= ~lbelow2;
+
+  m02 &= ~lbelow3;
+  m01 -= lbelow2;
+
+  m01 <<= 8;
+  m03 &= ~lbelow4;
+
+  m0 += m01;
+  lbelow2 -= lbelow3;
+
+  m02 += lbelow2;
+  lbelow3 -= lbelow4;
+
+  m02 <<= 16;
+  m03 += lbelow3;
+
+  m03 <<= 24;
+  m0 += m02;
+
+  m0 += m03;
+  lbelow5 = (int32)(l - 5);
+
+  lbelow6 = (int32)(l - 6);
+  lbelow7 = (int32)(l - 7);
+
+  lbelow5 >>= 31;
+  lbelow8 = (int32)(l - 8);
+
+  lbelow6 >>= 31;
+  m += lbelow5;
+
+  m10 = *(uchar *) (m + 4);
+  lbelow7 >>= 31;
+  m += lbelow6;
+
+  m11 = *(uchar *) (m + 5);
+  lbelow8 >>= 31;
+  m += lbelow7;
+
+  m12 = *(uchar *) (m + 6);
+  m1 <<= 51;
+  m += lbelow8;
+
+  m13 = *(uchar *) (m + 7);
+  m10 &= ~lbelow5;
+  lbelow4 -= lbelow5;
+
+  m10 += lbelow4;
+  lbelow5 -= lbelow6;
+
+  m11 &= ~lbelow6;
+  m11 += lbelow5;
+
+  m11 <<= 8;
+  m1 += m10;
+
+  m1 += m11;
+  m12 &= ~lbelow7;
+
+  lbelow6 -= lbelow7;
+  m13 &= ~lbelow8;
+
+  m12 += lbelow6;
+  lbelow7 -= lbelow8;
+
+  m12 <<= 16;
+  m13 += lbelow7;
+
+  m13 <<= 24;
+  m1 += m12;
+
+  m1 += m13;
+  m2 = 2279;
+
+  lbelow9 = (int32)(l - 9);
+  m3 = 2343;
+
+  lbelow10 = (int32)(l - 10);
+  lbelow11 = (int32)(l - 11);
+
+  lbelow9 >>= 31;
+  lbelow12 = (int32)(l - 12);
+
+  lbelow10 >>= 31;
+  m += lbelow9;
+
+  m20 = *(uchar *) (m + 8);
+  lbelow11 >>= 31;
+  m += lbelow10;
+
+  m21 = *(uchar *) (m + 9);
+  lbelow12 >>= 31;
+  m += lbelow11;
+
+  m22 = *(uchar *) (m + 10);
+  m2 <<= 51;
+  m += lbelow12;
+
+  m23 = *(uchar *) (m + 11);
+  m20 &= ~lbelow9;
+  lbelow8 -= lbelow9;
+
+  m20 += lbelow8;
+  lbelow9 -= lbelow10;
+
+  m21 &= ~lbelow10;
+  m21 += lbelow9;
+
+  m21 <<= 8;
+  m2 += m20;
+
+  m2 += m21;
+  m22 &= ~lbelow11;
+
+  lbelow10 -= lbelow11;
+  m23 &= ~lbelow12;
+
+  m22 += lbelow10;
+  lbelow11 -= lbelow12;
+
+  m22 <<= 16;
+  m23 += lbelow11;
+
+  m23 <<= 24;
+  m2 += m22;
+
+  m3 <<= 51;
+  lbelow13 = (int32)(l - 13);
+
+  lbelow13 >>= 31;
+  lbelow14 = (int32)(l - 14);
+
+  lbelow14 >>= 31;
+  m += lbelow13;
+  lbelow15 = (int32)(l - 15);
+
+  m30 = *(uchar *) (m + 12);
+  lbelow15 >>= 31;
+  m += lbelow14;
+
+  m31 = *(uchar *) (m + 13);
+  m += lbelow15;
+  m2 += m23;
+
+  m32 = *(uchar *) (m + 14);
+  m30 &= ~lbelow13;
+  lbelow12 -= lbelow13;
+
+  m30 += lbelow12;
+  lbelow13 -= lbelow14;
+
+  m3 += m30;
+  m31 &= ~lbelow14;
+
+  m31 += lbelow13;
+  m32 &= ~lbelow15;
+
+  m31 <<= 8;
+  lbelow14 -= lbelow15;
+
+  m3 += m31;
+  m32 += lbelow14;
+  d0 = m0;
+
+  m32 <<= 16;
+  m33 = lbelow15 + 1;
+  d1 = m1;
+
+  m33 <<= 24;
+  m3 += m32;
+  d2 = m2;
+
+  m3 += m33;
+  d3 = m3;
+
+  alpha0 = *(double *) (constants + 24);
+
+  z3 = *(double *) &d3;
+
+  z2 = *(double *) &d2;
+
+  z1 = *(double *) &d1;
+
+  z0 = *(double *) &d0;
+
+  z3 -= alpha96;
+
+  z2 -= alpha64;
+
+  z1 -= alpha32;
+
+  z0 -= alpha0;
+
+  h5 += z3;
+
+  h3 += z2;
+
+  h1 += z1;
+
+  h0 += z0;
+
+  y7 = h7 + alpha130;
+
+  y6 = h6 + alpha130;
+
+  y1 = h1 + alpha32;
+
+  y0 = h0 + alpha32;
+
+  y7 -= alpha130;
+
+  y6 -= alpha130;
+
+  y1 -= alpha32;
+
+  y0 -= alpha32;
+
+  y5 = h5 + alpha96;
+
+  y4 = h4 + alpha96;
+
+  x7 = h7 - y7;
+  y7 *= scale;
+
+  x6 = h6 - y6;
+  y6 *= scale;
+
+  x1 = h1 - y1;
+
+  x0 = h0 - y0;
+
+  y5 -= alpha96;
+
+  y4 -= alpha96;
+
+  x1 += y7;
+
+  x0 += y6;
+
+  x7 += y5;
+
+  x6 += y4;
+
+  y3 = h3 + alpha64;
+
+  y2 = h2 + alpha64;
+
+  x0 += x1;
+
+  x6 += x7;
+
+  y3 -= alpha64;
+  r3low = r3low_stack;
+
+  y2 -= alpha64;
+  r0low = r0low_stack;
+
+  x5 = h5 - y5;
+  r3lowx0 = r3low * x0;
+  r3high = r3high_stack;
+
+  x4 = h4 - y4;
+  r0lowx6 = r0low * x6;
+  r0high = r0high_stack;
+
+  x3 = h3 - y3;
+  r3highx0 = r3high * x0;
+  sr1low = sr1low_stack;
+
+  x2 = h2 - y2;
+  r0highx6 = r0high * x6;
+  sr1high = sr1high_stack;
+
+  x5 += y3;
+  r0lowx0 = r0low * x0;
+  r1low = r1low_stack;
+
+  h6 = r3lowx0 + r0lowx6;
+  sr1lowx6 = sr1low * x6;
+  r1high = r1high_stack;
+
+  x4 += y2;
+  r0highx0 = r0high * x0;
+  sr2low = sr2low_stack;
+
+  h7 = r3highx0 + r0highx6;
+  sr1highx6 = sr1high * x6;
+  sr2high = sr2high_stack;
+
+  x3 += y1;
+  r1lowx0 = r1low * x0;
+  r2low = r2low_stack;
+
+  h0 = r0lowx0 + sr1lowx6;
+  sr2lowx6 = sr2low * x6;
+  r2high = r2high_stack;
+
+  x2 += y0;
+  r1highx0 = r1high * x0;
+  sr3low = sr3low_stack;
+
+  h1 = r0highx0 + sr1highx6;
+  sr2highx6 = sr2high * x6;
+  sr3high = sr3high_stack;
+
+  x4 += x5;
+  r2lowx0 = r2low * x0;
+
+  h2 = r1lowx0 + sr2lowx6;
+  sr3lowx6 = sr3low * x6;
+
+  x2 += x3;
+  r2highx0 = r2high * x0;
+
+  h3 = r1highx0 + sr2highx6;
+  sr3highx6 = sr3high * x6;
+
+  r1highx4 = r1high * x4;
+
+  h4 = r2lowx0 + sr3lowx6;
+  r1lowx4 = r1low * x4;
+
+  r0highx4 = r0high * x4;
+
+  h5 = r2highx0 + sr3highx6;
+  r0lowx4 = r0low * x4;
+
+  h7 += r1highx4;
+  sr3highx4 = sr3high * x4;
+
+  h6 += r1lowx4;
+  sr3lowx4 = sr3low * x4;
+
+  h5 += r0highx4;
+  sr2highx4 = sr2high * x4;
+
+  h4 += r0lowx4;
+  sr2lowx4 = sr2low * x4;
+
+  h3 += sr3highx4;
+  r0lowx2 = r0low * x2;
+
+  h2 += sr3lowx4;
+  r0highx2 = r0high * x2;
+
+  h1 += sr2highx4;
+  r1lowx2 = r1low * x2;
+
+  h0 += sr2lowx4;
+  r1highx2 = r1high * x2;
+
+  h2 += r0lowx2;
+  r2lowx2 = r2low * x2;
+
+  h3 += r0highx2;
+  r2highx2 = r2high * x2;
+
+  h4 += r1lowx2;
+  sr3lowx2 = sr3low * x2;
+
+  h5 += r1highx2;
+  sr3highx2 = sr3high * x2;
+
+  h6 += r2lowx2;
+
+  h7 += r2highx2;
+
+  h0 += sr3lowx2;
+
+  h1 += sr3highx2;
+
+
+nomorebytes:;
+
+  offset0 = *(double *) (constants + 104);
+  y7 = h7 + alpha130;
+
+  offset1 = *(double *) (constants + 112);
+  y0 = h0 + alpha32;
+
+  offset2 = *(double *) (constants + 120);
+  y1 = h1 + alpha32;
+
+  offset3 = *(double *) (constants + 128);
+  y2 = h2 + alpha64;
+
+  y7 -= alpha130;
+
+  y3 = h3 + alpha64;
+
+  y4 = h4 + alpha96;
+
+  y5 = h5 + alpha96;
+
+  x7 = h7 - y7;
+  y7 *= scale;
+
+  y0 -= alpha32;
+
+  y1 -= alpha32;
+
+  y2 -= alpha64;
+
+  h6 += x7;
+
+  y3 -= alpha64;
+
+  y4 -= alpha96;
+
+  y5 -= alpha96;
+
+  y6 = h6 + alpha130;
+
+  x0 = h0 - y0;
+
+  x1 = h1 - y1;
+
+  x2 = h2 - y2;
+
+  y6 -= alpha130;
+
+  x0 += y7;
+
+  x3 = h3 - y3;
+
+  x4 = h4 - y4;
+
+  x5 = h5 - y5;
+
+  x6 = h6 - y6;
+
+  y6 *= scale;
+
+  x2 += y0;
+
+  x3 += y1;
+
+  x4 += y2;
+
+  x0 += y6;
+
+  x5 += y3;
+
+  x6 += y4;
+
+  x2 += x3;
+
+  x0 += x1;
+
+  x4 += x5;
+
+  x6 += y5;
+
+  x2 += offset1;
+  *(double *) &d1 = x2;
+
+  x0 += offset0;
+  *(double *) &d0 = x0;
+
+  x4 += offset2;
+  *(double *) &d2 = x4;
+
+  x6 += offset3;
+  *(double *) &d3 = x6;
+
+
+
+
+  f0 = d0;
+
+  f1 = d1;
+  bits32 = -1;
+
+  f2 = d2;
+  bits32 >>= 32;
+
+  f3 = d3;
+  f = f0 >> 32;
+
+  f0 &= bits32;
+  f &= 255;
+
+  f1 += f;
+  g0 = f0 + 5;
+
+  g = g0 >> 32;
+  g0 &= bits32;
+
+  f = f1 >> 32;
+  f1 &= bits32;
+
+  f &= 255;
+  g1 = f1 + g;
+
+  g = g1 >> 32;
+  f2 += f;
+
+  f = f2 >> 32;
+  g1 &= bits32;
+
+  f2 &= bits32;
+  f &= 255;
+
+  f3 += f;
+  g2 = f2 + g;
+
+  g = g2 >> 32;
+  g2 &= bits32;
+
+  f4 = f3 >> 32;
+  f3 &= bits32;
+
+  f4 &= 255;
+  g3 = f3 + g;
+
+  g = g3 >> 32;
+  g3 &= bits32;
+
+  g4 = f4 + g;
+
+  g4 = g4 - 4;
+  s00 = *(uchar *) (s + 0);
+
+  f = (int64) g4 >> 63;
+  s01 = *(uchar *) (s + 1);
+
+  f0 &= f;
+  g0 &= ~f;
+  s02 = *(uchar *) (s + 2);
+
+  f1 &= f;
+  f0 |= g0;
+  s03 = *(uchar *) (s + 3);
+
+  g1 &= ~f;
+  f2 &= f;
+  s10 = *(uchar *) (s + 4);
+
+  f3 &= f;
+  g2 &= ~f;
+  s11 = *(uchar *) (s + 5);
+
+  g3 &= ~f;
+  f1 |= g1;
+  s12 = *(uchar *) (s + 6);
+
+  f2 |= g2;
+  f3 |= g3;
+  s13 = *(uchar *) (s + 7);
+
+  s01 <<= 8;
+  f0 += s00;
+  s20 = *(uchar *) (s + 8);
+
+  s02 <<= 16;
+  f0 += s01;
+  s21 = *(uchar *) (s + 9);
+
+  s03 <<= 24;
+  f0 += s02;
+  s22 = *(uchar *) (s + 10);
+
+  s11 <<= 8;
+  f1 += s10;
+  s23 = *(uchar *) (s + 11);
+
+  s12 <<= 16;
+  f1 += s11;
+  s30 = *(uchar *) (s + 12);
+
+  s13 <<= 24;
+  f1 += s12;
+  s31 = *(uchar *) (s + 13);
+
+  f0 += s03;
+  f1 += s13;
+  s32 = *(uchar *) (s + 14);
+
+  s21 <<= 8;
+  f2 += s20;
+  s33 = *(uchar *) (s + 15);
+
+  s22 <<= 16;
+  f2 += s21;
+
+  s23 <<= 24;
+  f2 += s22;
+
+  s31 <<= 8;
+  f3 += s30;
+
+  s32 <<= 16;
+  f3 += s31;
+
+  s33 <<= 24;
+  f3 += s32;
+
+  f2 += s23;
+  f3 += s33;
+
+  *(uchar *) (out + 0) = f0;
+  f0 >>= 8;
+  *(uchar *) (out + 1) = f0;
+  f0 >>= 8;
+  *(uchar *) (out + 2) = f0;
+  f0 >>= 8;
+  *(uchar *) (out + 3) = f0;
+  f0 >>= 8;
+  f1 += f0;
+
+  *(uchar *) (out + 4) = f1;
+  f1 >>= 8;
+  *(uchar *) (out + 5) = f1;
+  f1 >>= 8;
+  *(uchar *) (out + 6) = f1;
+  f1 >>= 8;
+  *(uchar *) (out + 7) = f1;
+  f1 >>= 8;
+  f2 += f1;
+
+  *(uchar *) (out + 8) = f2;
+  f2 >>= 8;
+  *(uchar *) (out + 9) = f2;
+  f2 >>= 8;
+  *(uchar *) (out + 10) = f2;
+  f2 >>= 8;
+  *(uchar *) (out + 11) = f2;
+  f2 >>= 8;
+  f3 += f2;
+
+  *(uchar *) (out + 12) = f3;
+  f3 >>= 8;
+  *(uchar *) (out + 13) = f3;
+  f3 >>= 8;
+  *(uchar *) (out + 14) = f3;
+  f3 >>= 8;
+  *(uchar *) (out + 15) = f3;
+
+  return 0;
+}

+ 9 - 0
NaClCrypto/nacl/crypto_onetimeauth/poly1305/53/verify.c

@@ -0,0 +1,9 @@
+#include "crypto_verify_16.h"
+#include "crypto_onetimeauth.h"
+
+int crypto_onetimeauth_poly1305_53_verify(const unsigned char *h,const unsigned char *in,unsigned long long inlen,const unsigned char *k)
+{
+  unsigned char correct[16];
+  crypto_onetimeauth(correct,in,inlen,k);
+  return crypto_verify_16(h,correct);
+}

+ 2 - 0
NaClCrypto/nacl/crypto_scalarmult/curve25519/donna/api.h

@@ -0,0 +1,2 @@
+#define CRYPTO_BYTES 32
+#define CRYPTO_SCALARBYTES 32

+ 8 - 0
NaClCrypto/nacl/crypto_scalarmult/curve25519/donna/base.c

@@ -0,0 +1,8 @@
+#include "crypto_scalarmult.h"
+
+static const unsigned char basepoint[32] = {9};
+
+int crypto_scalarmult_curve25519_donna_base(unsigned char *q,const unsigned char *n)
+{
+  return crypto_scalarmult_curve25519_donna(q, n, basepoint);
+}

+ 733 - 0
NaClCrypto/nacl/crypto_scalarmult/curve25519/donna/smult.c

@@ -0,0 +1,733 @@
+/* Copyright 2008, Google Inc.
+ * 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 the above copyright
+ * notice, 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 Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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.
+ *
+ * curve25519-donna: Curve25519 elliptic curve, public key function
+ *
+ * http://code.google.com/p/curve25519-donna/
+ *
+ * Adam Langley <agl@imperialviolet.org>
+ *
+ * Derived from public domain C code by Daniel J. Bernstein <djb@cr.yp.to>
+ *
+ * More information about curve25519 can be found here
+ *   http://cr.yp.to/ecdh.html
+ *
+ * djb's sample implementation of curve25519 is written in a special assembly
+ * language called qhasm and uses the floating point registers.
+ *
+ * This is, almost, a clean room reimplementation from the curve25519 paper. It
+ * uses many of the tricks described therein. Only the crecip function is taken
+ * from the sample implementation.
+ */
+
+#include <string.h>
+#include <stdint.h>
+#include "crypto_scalarmult.h"
+
+#ifdef _MSC_VER
+#define inline __inline
+#endif
+
+typedef uint8_t u8;
+typedef int32_t s32;
+typedef int64_t limb;
+
+/* Field element representation:
+ *
+ * Field elements are written as an array of signed, 64-bit limbs, least
+ * significant first. The value of the field element is:
+ *   x[0] + 2^26·x[1] + x^51·x[2] + 2^102·x[3] + ...
+ *
+ * i.e. the limbs are 26, 25, 26, 25, ... bits wide.
+ */
+
+/* Sum two numbers: output += in */
+static void fsum(limb *output, const limb *in) {
+  unsigned i;
+  for (i = 0; i < 10; i += 2) {
+    output[0+i] = (output[0+i] + in[0+i]);
+    output[1+i] = (output[1+i] + in[1+i]);
+  }
+}
+
+/* Find the difference of two numbers: output = in - output
+ * (note the order of the arguments!)
+ */
+static void fdifference(limb *output, const limb *in) {
+  unsigned i;
+  for (i = 0; i < 10; ++i) {
+    output[i] = (in[i] - output[i]);
+  }
+}
+
+/* Multiply a number by a scalar: output = in * scalar */
+static void fscalar_product(limb *output, const limb *in, const limb scalar) {
+  unsigned i;
+  for (i = 0; i < 10; ++i) {
+    output[i] = in[i] * scalar;
+  }
+}
+
+/* Multiply two numbers: output = in2 * in
+ *
+ * output must be distinct to both inputs. The inputs are reduced coefficient
+ * form, the output is not.
+ */
+static void fproduct(limb *output, const limb *in2, const limb *in) {
+  output[0] =       ((limb) ((s32) in2[0])) * ((s32) in[0]);
+  output[1] =       ((limb) ((s32) in2[0])) * ((s32) in[1]) +
+                    ((limb) ((s32) in2[1])) * ((s32) in[0]);
+  output[2] =  2 *  ((limb) ((s32) in2[1])) * ((s32) in[1]) +
+                    ((limb) ((s32) in2[0])) * ((s32) in[2]) +
+                    ((limb) ((s32) in2[2])) * ((s32) in[0]);
+  output[3] =       ((limb) ((s32) in2[1])) * ((s32) in[2]) +
+                    ((limb) ((s32) in2[2])) * ((s32) in[1]) +
+                    ((limb) ((s32) in2[0])) * ((s32) in[3]) +
+                    ((limb) ((s32) in2[3])) * ((s32) in[0]);
+  output[4] =       ((limb) ((s32) in2[2])) * ((s32) in[2]) +
+               2 * (((limb) ((s32) in2[1])) * ((s32) in[3]) +
+                    ((limb) ((s32) in2[3])) * ((s32) in[1])) +
+                    ((limb) ((s32) in2[0])) * ((s32) in[4]) +
+                    ((limb) ((s32) in2[4])) * ((s32) in[0]);
+  output[5] =       ((limb) ((s32) in2[2])) * ((s32) in[3]) +
+                    ((limb) ((s32) in2[3])) * ((s32) in[2]) +
+                    ((limb) ((s32) in2[1])) * ((s32) in[4]) +
+                    ((limb) ((s32) in2[4])) * ((s32) in[1]) +
+                    ((limb) ((s32) in2[0])) * ((s32) in[5]) +
+                    ((limb) ((s32) in2[5])) * ((s32) in[0]);
+  output[6] =  2 * (((limb) ((s32) in2[3])) * ((s32) in[3]) +
+                    ((limb) ((s32) in2[1])) * ((s32) in[5]) +
+                    ((limb) ((s32) in2[5])) * ((s32) in[1])) +
+                    ((limb) ((s32) in2[2])) * ((s32) in[4]) +
+                    ((limb) ((s32) in2[4])) * ((s32) in[2]) +
+                    ((limb) ((s32) in2[0])) * ((s32) in[6]) +
+                    ((limb) ((s32) in2[6])) * ((s32) in[0]);
+  output[7] =       ((limb) ((s32) in2[3])) * ((s32) in[4]) +
+                    ((limb) ((s32) in2[4])) * ((s32) in[3]) +
+                    ((limb) ((s32) in2[2])) * ((s32) in[5]) +
+                    ((limb) ((s32) in2[5])) * ((s32) in[2]) +
+                    ((limb) ((s32) in2[1])) * ((s32) in[6]) +
+                    ((limb) ((s32) in2[6])) * ((s32) in[1]) +
+                    ((limb) ((s32) in2[0])) * ((s32) in[7]) +
+                    ((limb) ((s32) in2[7])) * ((s32) in[0]);
+  output[8] =       ((limb) ((s32) in2[4])) * ((s32) in[4]) +
+               2 * (((limb) ((s32) in2[3])) * ((s32) in[5]) +
+                    ((limb) ((s32) in2[5])) * ((s32) in[3]) +
+                    ((limb) ((s32) in2[1])) * ((s32) in[7]) +
+                    ((limb) ((s32) in2[7])) * ((s32) in[1])) +
+                    ((limb) ((s32) in2[2])) * ((s32) in[6]) +
+                    ((limb) ((s32) in2[6])) * ((s32) in[2]) +
+                    ((limb) ((s32) in2[0])) * ((s32) in[8]) +
+                    ((limb) ((s32) in2[8])) * ((s32) in[0]);
+  output[9] =       ((limb) ((s32) in2[4])) * ((s32) in[5]) +
+                    ((limb) ((s32) in2[5])) * ((s32) in[4]) +
+                    ((limb) ((s32) in2[3])) * ((s32) in[6]) +
+                    ((limb) ((s32) in2[6])) * ((s32) in[3]) +
+                    ((limb) ((s32) in2[2])) * ((s32) in[7]) +
+                    ((limb) ((s32) in2[7])) * ((s32) in[2]) +
+                    ((limb) ((s32) in2[1])) * ((s32) in[8]) +
+                    ((limb) ((s32) in2[8])) * ((s32) in[1]) +
+                    ((limb) ((s32) in2[0])) * ((s32) in[9]) +
+                    ((limb) ((s32) in2[9])) * ((s32) in[0]);
+  output[10] = 2 * (((limb) ((s32) in2[5])) * ((s32) in[5]) +
+                    ((limb) ((s32) in2[3])) * ((s32) in[7]) +
+                    ((limb) ((s32) in2[7])) * ((s32) in[3]) +
+                    ((limb) ((s32) in2[1])) * ((s32) in[9]) +
+                    ((limb) ((s32) in2[9])) * ((s32) in[1])) +
+                    ((limb) ((s32) in2[4])) * ((s32) in[6]) +
+                    ((limb) ((s32) in2[6])) * ((s32) in[4]) +
+                    ((limb) ((s32) in2[2])) * ((s32) in[8]) +
+                    ((limb) ((s32) in2[8])) * ((s32) in[2]);
+  output[11] =      ((limb) ((s32) in2[5])) * ((s32) in[6]) +
+                    ((limb) ((s32) in2[6])) * ((s32) in[5]) +
+                    ((limb) ((s32) in2[4])) * ((s32) in[7]) +
+                    ((limb) ((s32) in2[7])) * ((s32) in[4]) +
+                    ((limb) ((s32) in2[3])) * ((s32) in[8]) +
+                    ((limb) ((s32) in2[8])) * ((s32) in[3]) +
+                    ((limb) ((s32) in2[2])) * ((s32) in[9]) +
+                    ((limb) ((s32) in2[9])) * ((s32) in[2]);
+  output[12] =      ((limb) ((s32) in2[6])) * ((s32) in[6]) +
+               2 * (((limb) ((s32) in2[5])) * ((s32) in[7]) +
+                    ((limb) ((s32) in2[7])) * ((s32) in[5]) +
+                    ((limb) ((s32) in2[3])) * ((s32) in[9]) +
+                    ((limb) ((s32) in2[9])) * ((s32) in[3])) +
+                    ((limb) ((s32) in2[4])) * ((s32) in[8]) +
+                    ((limb) ((s32) in2[8])) * ((s32) in[4]);
+  output[13] =      ((limb) ((s32) in2[6])) * ((s32) in[7]) +
+                    ((limb) ((s32) in2[7])) * ((s32) in[6]) +
+                    ((limb) ((s32) in2[5])) * ((s32) in[8]) +
+                    ((limb) ((s32) in2[8])) * ((s32) in[5]) +
+                    ((limb) ((s32) in2[4])) * ((s32) in[9]) +
+                    ((limb) ((s32) in2[9])) * ((s32) in[4]);
+  output[14] = 2 * (((limb) ((s32) in2[7])) * ((s32) in[7]) +
+                    ((limb) ((s32) in2[5])) * ((s32) in[9]) +
+                    ((limb) ((s32) in2[9])) * ((s32) in[5])) +
+                    ((limb) ((s32) in2[6])) * ((s32) in[8]) +
+                    ((limb) ((s32) in2[8])) * ((s32) in[6]);
+  output[15] =      ((limb) ((s32) in2[7])) * ((s32) in[8]) +
+                    ((limb) ((s32) in2[8])) * ((s32) in[7]) +
+                    ((limb) ((s32) in2[6])) * ((s32) in[9]) +
+                    ((limb) ((s32) in2[9])) * ((s32) in[6]);
+  output[16] =      ((limb) ((s32) in2[8])) * ((s32) in[8]) +
+               2 * (((limb) ((s32) in2[7])) * ((s32) in[9]) +
+                    ((limb) ((s32) in2[9])) * ((s32) in[7]));
+  output[17] =      ((limb) ((s32) in2[8])) * ((s32) in[9]) +
+                    ((limb) ((s32) in2[9])) * ((s32) in[8]);
+  output[18] = 2 *  ((limb) ((s32) in2[9])) * ((s32) in[9]);
+}
+
+/* Reduce a long form to a short form by taking the input mod 2^255 - 19. */
+static void freduce_degree(limb *output) {
+  /* Each of these shifts and adds ends up multiplying the value by 19. */
+  output[8] += output[18] << 4;
+  output[8] += output[18] << 1;
+  output[8] += output[18];
+  output[7] += output[17] << 4;
+  output[7] += output[17] << 1;
+  output[7] += output[17];
+  output[6] += output[16] << 4;
+  output[6] += output[16] << 1;
+  output[6] += output[16];
+  output[5] += output[15] << 4;
+  output[5] += output[15] << 1;
+  output[5] += output[15];
+  output[4] += output[14] << 4;
+  output[4] += output[14] << 1;
+  output[4] += output[14];
+  output[3] += output[13] << 4;
+  output[3] += output[13] << 1;
+  output[3] += output[13];
+  output[2] += output[12] << 4;
+  output[2] += output[12] << 1;
+  output[2] += output[12];
+  output[1] += output[11] << 4;
+  output[1] += output[11] << 1;
+  output[1] += output[11];
+  output[0] += output[10] << 4;
+  output[0] += output[10] << 1;
+  output[0] += output[10];
+}
+
+#if (-1 & 3) != 3
+#error "This code only works on a two's complement system"
+#endif
+
+/* return v / 2^26, using only shifts and adds. */
+static inline limb
+div_by_2_26(const limb v)
+{
+  /* High word of v; no shift needed*/
+  const uint32_t highword = (uint32_t) (((uint64_t) v) >> 32);
+  /* Set to all 1s if v was negative; else set to 0s. */
+  const int32_t sign = ((int32_t) highword) >> 31;
+  /* Set to 0x3ffffff if v was negative; else set to 0. */
+  const int32_t roundoff = ((uint32_t) sign) >> 6;
+  /* Should return v / (1<<26) */
+  return (v + roundoff) >> 26;
+}
+
+/* return v / (2^25), using only shifts and adds. */
+static inline limb
+div_by_2_25(const limb v)
+{
+  /* High word of v; no shift needed*/
+  const uint32_t highword = (uint32_t) (((uint64_t) v) >> 32);
+  /* Set to all 1s if v was negative; else set to 0s. */
+  const int32_t sign = ((int32_t) highword) >> 31;
+  /* Set to 0x1ffffff if v was negative; else set to 0. */
+  const int32_t roundoff = ((uint32_t) sign) >> 7;
+  /* Should return v / (1<<25) */
+  return (v + roundoff) >> 25;
+}
+
+static inline s32
+div_s32_by_2_25(const s32 v)
+{
+   const s32 roundoff = ((uint32_t)(v >> 31)) >> 7;
+   return (v + roundoff) >> 25;
+}
+
+/* Reduce all coefficients of the short form input so that |x| < 2^26.
+ *
+ * On entry: |output[i]| < 2^62
+ */
+static void freduce_coefficients(limb *output) {
+  unsigned i;
+
+  output[10] = 0;
+
+  for (i = 0; i < 10; i += 2) {
+    limb over = div_by_2_26(output[i]);
+    output[i] -= over << 26;
+    output[i+1] += over;
+
+    over = div_by_2_25(output[i+1]);
+    output[i+1] -= over << 25;
+    output[i+2] += over;
+  }
+  /* Now |output[10]| < 2 ^ 38 and all other coefficients are reduced. */
+  output[0] += output[10] << 4;
+  output[0] += output[10] << 1;
+  output[0] += output[10];
+
+  output[10] = 0;
+
+  /* Now output[1..9] are reduced, and |output[0]| < 2^26 + 19 * 2^38
+   * So |over| will be no more than 77825  */
+  {
+    limb over = div_by_2_26(output[0]);
+    output[0] -= over << 26;
+    output[1] += over;
+  }
+
+  /* Now output[0,2..9] are reduced, and |output[1]| < 2^25 + 77825
+   * So |over| will be no more than 1. */
+  {
+    /* output[1] fits in 32 bits, so we can use div_s32_by_2_25 here. */
+    s32 over32 = div_s32_by_2_25((s32) output[1]);
+    output[1] -= over32 << 25;
+    output[2] += over32;
+  }
+
+  /* Finally, output[0,1,3..9] are reduced, and output[2] is "nearly reduced":
+   * we have |output[2]| <= 2^26.  This is good enough for all of our math,
+   * but it will require an extra freduce_coefficients before fcontract. */
+}
+
+/* A helpful wrapper around fproduct: output = in * in2.
+ *
+ * output must be distinct to both inputs. The output is reduced degree and
+ * reduced coefficient.
+ */
+static void
+fmul(limb *output, const limb *in, const limb *in2) {
+  limb t[19];
+  fproduct(t, in, in2);
+  freduce_degree(t);
+  freduce_coefficients(t);
+  memcpy(output, t, sizeof(limb) * 10);
+}
+
+static void fsquare_inner(limb *output, const limb *in) {
+  output[0] =       ((limb) ((s32) in[0])) * ((s32) in[0]);
+  output[1] =  2 *  ((limb) ((s32) in[0])) * ((s32) in[1]);
+  output[2] =  2 * (((limb) ((s32) in[1])) * ((s32) in[1]) +
+                    ((limb) ((s32) in[0])) * ((s32) in[2]));
+  output[3] =  2 * (((limb) ((s32) in[1])) * ((s32) in[2]) +
+                    ((limb) ((s32) in[0])) * ((s32) in[3]));
+  output[4] =       ((limb) ((s32) in[2])) * ((s32) in[2]) +
+               4 *  ((limb) ((s32) in[1])) * ((s32) in[3]) +
+               2 *  ((limb) ((s32) in[0])) * ((s32) in[4]);
+  output[5] =  2 * (((limb) ((s32) in[2])) * ((s32) in[3]) +
+                    ((limb) ((s32) in[1])) * ((s32) in[4]) +
+                    ((limb) ((s32) in[0])) * ((s32) in[5]));
+  output[6] =  2 * (((limb) ((s32) in[3])) * ((s32) in[3]) +
+                    ((limb) ((s32) in[2])) * ((s32) in[4]) +
+                    ((limb) ((s32) in[0])) * ((s32) in[6]) +
+               2 *  ((limb) ((s32) in[1])) * ((s32) in[5]));
+  output[7] =  2 * (((limb) ((s32) in[3])) * ((s32) in[4]) +
+                    ((limb) ((s32) in[2])) * ((s32) in[5]) +
+                    ((limb) ((s32) in[1])) * ((s32) in[6]) +
+                    ((limb) ((s32) in[0])) * ((s32) in[7]));
+  output[8] =       ((limb) ((s32) in[4])) * ((s32) in[4]) +
+               2 * (((limb) ((s32) in[2])) * ((s32) in[6]) +
+                    ((limb) ((s32) in[0])) * ((s32) in[8]) +
+               2 * (((limb) ((s32) in[1])) * ((s32) in[7]) +
+                    ((limb) ((s32) in[3])) * ((s32) in[5])));
+  output[9] =  2 * (((limb) ((s32) in[4])) * ((s32) in[5]) +
+                    ((limb) ((s32) in[3])) * ((s32) in[6]) +
+                    ((limb) ((s32) in[2])) * ((s32) in[7]) +
+                    ((limb) ((s32) in[1])) * ((s32) in[8]) +
+                    ((limb) ((s32) in[0])) * ((s32) in[9]));
+  output[10] = 2 * (((limb) ((s32) in[5])) * ((s32) in[5]) +
+                    ((limb) ((s32) in[4])) * ((s32) in[6]) +
+                    ((limb) ((s32) in[2])) * ((s32) in[8]) +
+               2 * (((limb) ((s32) in[3])) * ((s32) in[7]) +
+                    ((limb) ((s32) in[1])) * ((s32) in[9])));
+  output[11] = 2 * (((limb) ((s32) in[5])) * ((s32) in[6]) +
+                    ((limb) ((s32) in[4])) * ((s32) in[7]) +
+                    ((limb) ((s32) in[3])) * ((s32) in[8]) +
+                    ((limb) ((s32) in[2])) * ((s32) in[9]));
+  output[12] =      ((limb) ((s32) in[6])) * ((s32) in[6]) +
+               2 * (((limb) ((s32) in[4])) * ((s32) in[8]) +
+               2 * (((limb) ((s32) in[5])) * ((s32) in[7]) +
+                    ((limb) ((s32) in[3])) * ((s32) in[9])));
+  output[13] = 2 * (((limb) ((s32) in[6])) * ((s32) in[7]) +
+                    ((limb) ((s32) in[5])) * ((s32) in[8]) +
+                    ((limb) ((s32) in[4])) * ((s32) in[9]));
+  output[14] = 2 * (((limb) ((s32) in[7])) * ((s32) in[7]) +
+                    ((limb) ((s32) in[6])) * ((s32) in[8]) +
+               2 *  ((limb) ((s32) in[5])) * ((s32) in[9]));
+  output[15] = 2 * (((limb) ((s32) in[7])) * ((s32) in[8]) +
+                    ((limb) ((s32) in[6])) * ((s32) in[9]));
+  output[16] =      ((limb) ((s32) in[8])) * ((s32) in[8]) +
+               4 *  ((limb) ((s32) in[7])) * ((s32) in[9]);
+  output[17] = 2 *  ((limb) ((s32) in[8])) * ((s32) in[9]);
+  output[18] = 2 *  ((limb) ((s32) in[9])) * ((s32) in[9]);
+}
+
+static void
+fsquare(limb *output, const limb *in) {
+  limb t[19];
+  fsquare_inner(t, in);
+  freduce_degree(t);
+  freduce_coefficients(t);
+  memcpy(output, t, sizeof(limb) * 10);
+}
+
+/* Take a little-endian, 32-byte number and expand it into polynomial form */
+static void
+fexpand(limb *output, const u8 *input) {
+#define F(n,start,shift,mask) \
+  output[n] = ((((limb) input[start + 0]) | \
+                ((limb) input[start + 1]) << 8 | \
+                ((limb) input[start + 2]) << 16 | \
+                ((limb) input[start + 3]) << 24) >> shift) & mask;
+  F(0, 0, 0, 0x3ffffff);
+  F(1, 3, 2, 0x1ffffff);
+  F(2, 6, 3, 0x3ffffff);
+  F(3, 9, 5, 0x1ffffff);
+  F(4, 12, 6, 0x3ffffff);
+  F(5, 16, 0, 0x1ffffff);
+  F(6, 19, 1, 0x3ffffff);
+  F(7, 22, 3, 0x1ffffff);
+  F(8, 25, 4, 0x3ffffff);
+  F(9, 28, 6, 0x3ffffff);
+#undef F
+}
+
+#if (-32 >> 1) != -16
+#error "This code only works when >> does sign-extension on negative numbers"
+#endif
+
+/* Take a fully reduced polynomial form number and contract it into a
+ * little-endian, 32-byte array
+ */
+static void
+fcontract(u8 *output, limb *input) {
+  int i;
+  int j;
+
+  for (j = 0; j < 2; ++j) {
+    for (i = 0; i < 9; ++i) {
+      if ((i & 1) == 1) {
+        /* This calculation is a time-invariant way to make input[i] positive
+           by borrowing from the next-larger limb.
+        */
+        const s32 mask = (s32)(input[i]) >> 31;
+        const s32 carry = -(((s32)(input[i]) & mask) >> 25);
+        input[i] = (s32)(input[i]) + (carry << 25);
+        input[i+1] = (s32)(input[i+1]) - carry;
+      } else {
+        const s32 mask = (s32)(input[i]) >> 31;
+        const s32 carry = -(((s32)(input[i]) & mask) >> 26);
+        input[i] = (s32)(input[i]) + (carry << 26);
+        input[i+1] = (s32)(input[i+1]) - carry;
+      }
+    }
+    {
+      const s32 mask = (s32)(input[9]) >> 31;
+      const s32 carry = -(((s32)(input[9]) & mask) >> 25);
+      input[9] = (s32)(input[9]) + (carry << 25);
+      input[0] = (s32)(input[0]) - (carry * 19);
+    }
+  }
+
+  /* The first borrow-propagation pass above ended with every limb
+     except (possibly) input[0] non-negative.
+
+     Since each input limb except input[0] is decreased by at most 1
+     by a borrow-propagation pass, the second borrow-propagation pass
+     could only have wrapped around to decrease input[0] again if the
+     first pass left input[0] negative *and* input[1] through input[9]
+     were all zero.  In that case, input[1] is now 2^25 - 1, and this
+     last borrow-propagation step will leave input[1] non-negative.
+  */
+  {
+    const s32 mask = (s32)(input[0]) >> 31;
+    const s32 carry = -(((s32)(input[0]) & mask) >> 26);
+    input[0] = (s32)(input[0]) + (carry << 26);
+    input[1] = (s32)(input[1]) - carry;
+  }
+
+  /* Both passes through the above loop, plus the last 0-to-1 step, are
+     necessary: if input[9] is -1 and input[0] through input[8] are 0,
+     negative values will remain in the array until the end.
+   */
+
+  input[1] <<= 2;
+  input[2] <<= 3;
+  input[3] <<= 5;
+  input[4] <<= 6;
+  input[6] <<= 1;
+  input[7] <<= 3;
+  input[8] <<= 4;
+  input[9] <<= 6;
+#define F(i, s) \
+  output[s+0] |=  input[i] & 0xff; \
+  output[s+1]  = (input[i] >> 8) & 0xff; \
+  output[s+2]  = (input[i] >> 16) & 0xff; \
+  output[s+3]  = (input[i] >> 24) & 0xff;
+  output[0] = 0;
+  output[16] = 0;
+  F(0,0);
+  F(1,3);
+  F(2,6);
+  F(3,9);
+  F(4,12);
+  F(5,16);
+  F(6,19);
+  F(7,22);
+  F(8,25);
+  F(9,28);
+#undef F
+}
+
+/* Input: Q, Q', Q-Q'
+ * Output: 2Q, Q+Q'
+ *
+ *   x2 z3: long form
+ *   x3 z3: long form
+ *   x z: short form, destroyed
+ *   xprime zprime: short form, destroyed
+ *   qmqp: short form, preserved
+ */
+static void fmonty(limb *x2, limb *z2,  /* output 2Q */
+                   limb *x3, limb *z3,  /* output Q + Q' */
+                   limb *x, limb *z,    /* input Q */
+                   limb *xprime, limb *zprime,  /* input Q' */
+                   const limb *qmqp /* input Q - Q' */) {
+  limb origx[10], origxprime[10], zzz[19], xx[19], zz[19], xxprime[19],
+        zzprime[19], zzzprime[19], xxxprime[19];
+
+  memcpy(origx, x, 10 * sizeof(limb));
+  fsum(x, z);
+  fdifference(z, origx);  // does x - z
+
+  memcpy(origxprime, xprime, sizeof(limb) * 10);
+  fsum(xprime, zprime);
+  fdifference(zprime, origxprime);
+  fproduct(xxprime, xprime, z);
+  fproduct(zzprime, x, zprime);
+  freduce_degree(xxprime);
+  freduce_coefficients(xxprime);
+  freduce_degree(zzprime);
+  freduce_coefficients(zzprime);
+  memcpy(origxprime, xxprime, sizeof(limb) * 10);
+  fsum(xxprime, zzprime);
+  fdifference(zzprime, origxprime);
+  fsquare(xxxprime, xxprime);
+  fsquare(zzzprime, zzprime);
+  fproduct(zzprime, zzzprime, qmqp);
+  freduce_degree(zzprime);
+  freduce_coefficients(zzprime);
+  memcpy(x3, xxxprime, sizeof(limb) * 10);
+  memcpy(z3, zzprime, sizeof(limb) * 10);
+
+  fsquare(xx, x);
+  fsquare(zz, z);
+  fproduct(x2, xx, zz);
+  freduce_degree(x2);
+  freduce_coefficients(x2);
+  fdifference(zz, xx);  // does zz = xx - zz
+  memset(zzz + 10, 0, sizeof(limb) * 9);
+  fscalar_product(zzz, zz, 121665);
+  /* No need to call freduce_degree here:
+     fscalar_product doesn't increase the degree of its input. */
+  freduce_coefficients(zzz);
+  fsum(zzz, xx);
+  fproduct(z2, zz, zzz);
+  freduce_degree(z2);
+  freduce_coefficients(z2);
+}
+
+/* Conditionally swap two reduced-form limb arrays if 'iswap' is 1, but leave
+ * them unchanged if 'iswap' is 0.  Runs in data-invariant time to avoid
+ * side-channel attacks.
+ *
+ * NOTE that this function requires that 'iswap' be 1 or 0; other values give
+ * wrong results.  Also, the two limb arrays must be in reduced-coefficient,
+ * reduced-degree form: the values in a[10..19] or b[10..19] aren't swapped,
+ * and all all values in a[0..9],b[0..9] must have magnitude less than
+ * INT32_MAX.
+ */
+static void
+swap_conditional(limb a[19], limb b[19], limb iswap) {
+  unsigned i;
+  const s32 swap = (s32) -iswap;
+
+  for (i = 0; i < 10; ++i) {
+    const s32 x = swap & ( ((s32)a[i]) ^ ((s32)b[i]) );
+    a[i] = ((s32)a[i]) ^ x;
+    b[i] = ((s32)b[i]) ^ x;
+  }
+}
+
+/* Calculates nQ where Q is the x-coordinate of a point on the curve
+ *
+ *   resultx/resultz: the x coordinate of the resulting curve point (short form)
+ *   n: a little endian, 32-byte number
+ *   q: a point of the curve (short form)
+ */
+static void
+cmult(limb *resultx, limb *resultz, const u8 *n, const limb *q) {
+  limb a[19] = {0}, b[19] = {1}, c[19] = {1}, d[19] = {0};
+  limb *nqpqx = a, *nqpqz = b, *nqx = c, *nqz = d, *t;
+  limb e[19] = {0}, f[19] = {1}, g[19] = {0}, h[19] = {1};
+  limb *nqpqx2 = e, *nqpqz2 = f, *nqx2 = g, *nqz2 = h;
+
+  unsigned i, j;
+
+  memcpy(nqpqx, q, sizeof(limb) * 10);
+
+  for (i = 0; i < 32; ++i) {
+    u8 byte = n[31 - i];
+    for (j = 0; j < 8; ++j) {
+      const limb bit = byte >> 7;
+
+      swap_conditional(nqx, nqpqx, bit);
+      swap_conditional(nqz, nqpqz, bit);
+      fmonty(nqx2, nqz2,
+             nqpqx2, nqpqz2,
+             nqx, nqz,
+             nqpqx, nqpqz,
+             q);
+      swap_conditional(nqx2, nqpqx2, bit);
+      swap_conditional(nqz2, nqpqz2, bit);
+
+      t = nqx;
+      nqx = nqx2;
+      nqx2 = t;
+      t = nqz;
+      nqz = nqz2;
+      nqz2 = t;
+      t = nqpqx;
+      nqpqx = nqpqx2;
+      nqpqx2 = t;
+      t = nqpqz;
+      nqpqz = nqpqz2;
+      nqpqz2 = t;
+
+      byte <<= 1;
+    }
+  }
+
+  memcpy(resultx, nqx, sizeof(limb) * 10);
+  memcpy(resultz, nqz, sizeof(limb) * 10);
+}
+
+// -----------------------------------------------------------------------------
+// Shamelessly copied from djb's code
+// -----------------------------------------------------------------------------
+static void
+crecip(limb *out, const limb *z) {
+  limb z2[10];
+  limb z9[10];
+  limb z11[10];
+  limb z2_5_0[10];
+  limb z2_10_0[10];
+  limb z2_20_0[10];
+  limb z2_50_0[10];
+  limb z2_100_0[10];
+  limb t0[10];
+  limb t1[10];
+  int i;
+
+  /* 2 */ fsquare(z2,z);
+  /* 4 */ fsquare(t1,z2);
+  /* 8 */ fsquare(t0,t1);
+  /* 9 */ fmul(z9,t0,z);
+  /* 11 */ fmul(z11,z9,z2);
+  /* 22 */ fsquare(t0,z11);
+  /* 2^5 - 2^0 = 31 */ fmul(z2_5_0,t0,z9);
+
+  /* 2^6 - 2^1 */ fsquare(t0,z2_5_0);
+  /* 2^7 - 2^2 */ fsquare(t1,t0);
+  /* 2^8 - 2^3 */ fsquare(t0,t1);
+  /* 2^9 - 2^4 */ fsquare(t1,t0);
+  /* 2^10 - 2^5 */ fsquare(t0,t1);
+  /* 2^10 - 2^0 */ fmul(z2_10_0,t0,z2_5_0);
+
+  /* 2^11 - 2^1 */ fsquare(t0,z2_10_0);
+  /* 2^12 - 2^2 */ fsquare(t1,t0);
+  /* 2^20 - 2^10 */ for (i = 2;i < 10;i += 2) { fsquare(t0,t1); fsquare(t1,t0); }
+  /* 2^20 - 2^0 */ fmul(z2_20_0,t1,z2_10_0);
+
+  /* 2^21 - 2^1 */ fsquare(t0,z2_20_0);
+  /* 2^22 - 2^2 */ fsquare(t1,t0);
+  /* 2^40 - 2^20 */ for (i = 2;i < 20;i += 2) { fsquare(t0,t1); fsquare(t1,t0); }
+  /* 2^40 - 2^0 */ fmul(t0,t1,z2_20_0);
+
+  /* 2^41 - 2^1 */ fsquare(t1,t0);
+  /* 2^42 - 2^2 */ fsquare(t0,t1);
+  /* 2^50 - 2^10 */ for (i = 2;i < 10;i += 2) { fsquare(t1,t0); fsquare(t0,t1); }
+  /* 2^50 - 2^0 */ fmul(z2_50_0,t0,z2_10_0);
+
+  /* 2^51 - 2^1 */ fsquare(t0,z2_50_0);
+  /* 2^52 - 2^2 */ fsquare(t1,t0);
+  /* 2^100 - 2^50 */ for (i = 2;i < 50;i += 2) { fsquare(t0,t1); fsquare(t1,t0); }
+  /* 2^100 - 2^0 */ fmul(z2_100_0,t1,z2_50_0);
+
+  /* 2^101 - 2^1 */ fsquare(t1,z2_100_0);
+  /* 2^102 - 2^2 */ fsquare(t0,t1);
+  /* 2^200 - 2^100 */ for (i = 2;i < 100;i += 2) { fsquare(t1,t0); fsquare(t0,t1); }
+  /* 2^200 - 2^0 */ fmul(t1,t0,z2_100_0);
+
+  /* 2^201 - 2^1 */ fsquare(t0,t1);
+  /* 2^202 - 2^2 */ fsquare(t1,t0);
+  /* 2^250 - 2^50 */ for (i = 2;i < 50;i += 2) { fsquare(t0,t1); fsquare(t1,t0); }
+  /* 2^250 - 2^0 */ fmul(t0,t1,z2_50_0);
+
+  /* 2^251 - 2^1 */ fsquare(t1,t0);
+  /* 2^252 - 2^2 */ fsquare(t0,t1);
+  /* 2^253 - 2^3 */ fsquare(t1,t0);
+  /* 2^254 - 2^4 */ fsquare(t0,t1);
+  /* 2^255 - 2^5 */ fsquare(t1,t0);
+  /* 2^255 - 21 */ fmul(out,t1,z11);
+}
+
+int
+crypto_scalarmult_curve25519_donna(u8 *mypublic, const u8 *secret, const u8 *basepoint) {
+  limb bp[10], x[10], z[11], zmone[10];
+  uint8_t e[32];
+  int i;
+
+  for (i = 0; i < 32; ++i) e[i] = secret[i];
+  e[0] &= 248;
+  e[31] &= 127;
+  e[31] |= 64;
+
+  fexpand(bp, basepoint);
+  cmult(x, z, e, bp);
+  crecip(zmone, z);
+  fmul(z, x, zmone);
+  freduce_coefficients(z);
+  fcontract(mypublic, z);
+  return 0;
+}

+ 4 - 0
NaClCrypto/nacl/crypto_secretbox/xsalsa20poly1305/ref/api.h

@@ -0,0 +1,4 @@
+#define CRYPTO_KEYBYTES 32
+#define CRYPTO_NONCEBYTES 24
+#define CRYPTO_ZEROBYTES 32
+#define CRYPTO_BOXZEROBYTES 16

+ 35 - 0
NaClCrypto/nacl/crypto_secretbox/xsalsa20poly1305/ref/box.c

@@ -0,0 +1,35 @@
+#include "crypto_onetimeauth_poly1305.h"
+#include "crypto_stream_xsalsa20.h"
+#include "crypto_secretbox.h"
+
+int crypto_secretbox(
+  unsigned char *c,
+  const unsigned char *m,unsigned long long mlen,
+  const unsigned char *n,
+  const unsigned char *k
+)
+{
+  int i;
+  if (mlen < 32) return -1;
+  crypto_stream_xsalsa20_xor(c,m,mlen,n,k);
+  crypto_onetimeauth_poly1305(c + 16,c + 32,mlen - 32,c);
+  for (i = 0;i < 16;++i) c[i] = 0;
+  return 0;
+}
+
+int crypto_secretbox_open(
+  unsigned char *m,
+  const unsigned char *c,unsigned long long clen,
+  const unsigned char *n,
+  const unsigned char *k
+)
+{
+  int i;
+  unsigned char subkey[32];
+  if (clen < 32) return -1;
+  crypto_stream_xsalsa20(subkey,32,n,k);
+  if (crypto_onetimeauth_poly1305_verify(c + 16,c + 32,clen - 32,subkey) != 0) return -1;
+  crypto_stream_xsalsa20_xor(m,c,clen,n,k);
+  for (i = 0;i < 32;++i) m[i] = 0;
+  return 0;
+}

+ 2 - 0
NaClCrypto/nacl/crypto_stream/salsa20/ref/api.h

@@ -0,0 +1,2 @@
+#define CRYPTO_KEYBYTES 32
+#define CRYPTO_NONCEBYTES 8

+ 49 - 0
NaClCrypto/nacl/crypto_stream/salsa20/ref/stream.c

@@ -0,0 +1,49 @@
+/*
+version 20080913
+D. J. Bernstein
+Public domain.
+*/
+
+#include "crypto_core_salsa20.h"
+#include "crypto_stream_salsa20.h"
+
+typedef unsigned int uint32;
+
+static const unsigned char sigma[16] = "expand 32-byte k";
+
+int crypto_stream_salsa20_ref(
+        unsigned char *c,unsigned long long clen,
+  const unsigned char *n,
+  const unsigned char *k
+)
+{
+  unsigned char in[16];
+  unsigned char block[64];
+  int i;
+  unsigned int u;
+
+  if (!clen) return 0;
+
+  for (i = 0;i < 8;++i) in[i] = n[i];
+  for (i = 8;i < 16;++i) in[i] = 0;
+
+  while (clen >= 64) {
+    crypto_core_salsa20(c,in,k,sigma);
+
+    u = 1;
+    for (i = 8;i < 16;++i) {
+      u += (unsigned int) in[i];
+      in[i] = u;
+      u >>= 8;
+    }
+
+    clen -= 64;
+    c += 64;
+  }
+
+  if (clen) {
+    crypto_core_salsa20(block,in,k,sigma);
+    for (i = 0;i < clen;++i) c[i] = block[i];
+  }
+  return 0;
+}

+ 52 - 0
NaClCrypto/nacl/crypto_stream/salsa20/ref/xor.c

@@ -0,0 +1,52 @@
+/*
+version 20080913
+D. J. Bernstein
+Public domain.
+*/
+
+#include "crypto_core_salsa20.h"
+#include "crypto_stream_salsa20.h"
+
+typedef unsigned int uint32;
+
+static const unsigned char sigma[16] = "expand 32-byte k";
+
+int crypto_stream_salsa20_ref_xor(
+        unsigned char *c,
+  const unsigned char *m,unsigned long long mlen,
+  const unsigned char *n,
+  const unsigned char *k
+)
+{
+  unsigned char in[16];
+  unsigned char block[64];
+  int i;
+  unsigned int u;
+
+  if (!mlen) return 0;
+
+  for (i = 0;i < 8;++i) in[i] = n[i];
+  for (i = 8;i < 16;++i) in[i] = 0;
+
+  while (mlen >= 64) {
+    crypto_core_salsa20(block,in,k,sigma);
+    for (i = 0;i < 64;++i) c[i] = m[i] ^ block[i];
+
+    u = 1;
+    for (i = 8;i < 16;++i) {
+      u += (unsigned int) in[i];
+      in[i] = u;
+      u >>= 8;
+    }
+
+    mlen -= 64;
+    c += 64;
+    m += 64;
+  }
+
+  if (mlen) {
+    crypto_core_salsa20(block,in,k,sigma);
+    for (i = 0;i < mlen;++i) c[i] = m[i] ^ block[i];
+  }
+  return 0;
+}

+ 2 - 0
NaClCrypto/nacl/crypto_stream/xsalsa20/ref/api.h

@@ -0,0 +1,2 @@
+#define CRYPTO_KEYBYTES 32
+#define CRYPTO_NONCEBYTES 24

+ 22 - 0
NaClCrypto/nacl/crypto_stream/xsalsa20/ref/stream.c

@@ -0,0 +1,22 @@
+/*
+version 20080914
+D. J. Bernstein
+Public domain.
+*/
+
+#include "crypto_core_hsalsa20.h"
+#include "crypto_stream_salsa20.h"
+#include "crypto_stream.h"
+
+static const unsigned char sigma[16] = "expand 32-byte k";
+
+int crypto_stream_xsalsa20_ref(
+        unsigned char *c,unsigned long long clen,
+  const unsigned char *n,
+  const unsigned char *k
+)
+{
+  unsigned char subkey[32];
+  crypto_core_hsalsa20(subkey,n,k,sigma);
+  return crypto_stream_salsa20(c,clen,n + 16,subkey);
+}

+ 23 - 0
NaClCrypto/nacl/crypto_stream/xsalsa20/ref/xor.c

@@ -0,0 +1,23 @@
+/*
+version 20080913
+D. J. Bernstein
+Public domain.
+*/
+
+#include "crypto_core_hsalsa20.h"
+#include "crypto_stream_salsa20.h"
+#include "crypto_stream.h"
+
+static const unsigned char sigma[16] = "expand 32-byte k";
+
+int crypto_stream_xsalsa20_ref_xor(
+        unsigned char *c,
+  const unsigned char *m,unsigned long long mlen,
+  const unsigned char *n,
+  const unsigned char *k
+)
+{
+  unsigned char subkey[32];
+  crypto_core_hsalsa20(subkey,n,k,sigma);
+  return crypto_stream_salsa20_xor(c,m,mlen,n + 16,subkey);
+}

+ 1 - 0
NaClCrypto/nacl/crypto_verify/16/ref/api.h

@@ -0,0 +1 @@
+#define CRYPTO_BYTES 16

+ 24 - 0
NaClCrypto/nacl/crypto_verify/16/ref/verify.c

@@ -0,0 +1,24 @@
+#include "crypto_verify_16.h"
+
+int crypto_verify_16_ref(const unsigned char *x,const unsigned char *y)
+{
+  unsigned int differentbits = 0;
+#define F(i) differentbits |= x[i] ^ y[i];
+  F(0)
+  F(1)
+  F(2)
+  F(3)
+  F(4)
+  F(5)
+  F(6)
+  F(7)
+  F(8)
+  F(9)
+  F(10)
+  F(11)
+  F(12)
+  F(13)
+  F(14)
+  F(15)
+  return (1 & ((differentbits - 1) >> 8)) - 1;
+}

+ 1 - 0
NaClCrypto/nacl/crypto_verify/32/ref/api.h

@@ -0,0 +1 @@
+#define CRYPTO_BYTES 32

+ 40 - 0
NaClCrypto/nacl/crypto_verify/32/ref/verify.c

@@ -0,0 +1,40 @@
+#include "crypto_verify_32.h"
+
+int crypto_verify_32_ref(const unsigned char *x,const unsigned char *y)
+{
+  unsigned int differentbits = 0;
+#define F(i) differentbits |= x[i] ^ y[i];
+  F(0)
+  F(1)
+  F(2)
+  F(3)
+  F(4)
+  F(5)
+  F(6)
+  F(7)
+  F(8)
+  F(9)
+  F(10)
+  F(11)
+  F(12)
+  F(13)
+  F(14)
+  F(15)
+  F(16)
+  F(17)
+  F(18)
+  F(19)
+  F(20)
+  F(21)
+  F(22)
+  F(23)
+  F(24)
+  F(25)
+  F(26)
+  F(27)
+  F(28)
+  F(29)
+  F(30)
+  F(31)
+  return (1 & ((differentbits - 1) >> 8)) - 1;
+}

+ 22 - 0
NaClCrypto/nacl/include/crypto_box.h

@@ -0,0 +1,22 @@
+#ifndef crypto_box_H
+#define crypto_box_H
+
+#include "crypto_box_curve25519xsalsa20poly1305.h"
+
+#define crypto_box crypto_box_curve25519xsalsa20poly1305
+#define crypto_box_open crypto_box_curve25519xsalsa20poly1305_open
+#define crypto_box_keypair crypto_box_curve25519xsalsa20poly1305_keypair
+#define crypto_box_beforenm crypto_box_curve25519xsalsa20poly1305_beforenm
+#define crypto_box_afternm crypto_box_curve25519xsalsa20poly1305_afternm
+#define crypto_box_open_afternm crypto_box_curve25519xsalsa20poly1305_open_afternm
+#define crypto_box_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES
+#define crypto_box_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES
+#define crypto_box_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES
+#define crypto_box_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_NONCEBYTES
+#define crypto_box_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ZEROBYTES
+#define crypto_box_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES
+#define crypto_box_PRIMITIVE "curve25519xsalsa20poly1305"
+#define crypto_box_IMPLEMENTATION crypto_box_curve25519xsalsa20poly1305_IMPLEMENTATION
+#define crypto_box_VERSION crypto_box_curve25519xsalsa20poly1305_VERSION
+
+#endif

+ 45 - 0
NaClCrypto/nacl/include/crypto_box_curve25519xsalsa20poly1305.h

@@ -0,0 +1,45 @@
+#ifndef crypto_box_curve25519xsalsa20poly1305_H
+#define crypto_box_curve25519xsalsa20poly1305_H
+
+#define crypto_box_curve25519xsalsa20poly1305_ref_PUBLICKEYBYTES 32
+#define crypto_box_curve25519xsalsa20poly1305_ref_SECRETKEYBYTES 32
+#define crypto_box_curve25519xsalsa20poly1305_ref_BEFORENMBYTES 32
+#define crypto_box_curve25519xsalsa20poly1305_ref_NONCEBYTES 24
+#define crypto_box_curve25519xsalsa20poly1305_ref_ZEROBYTES 32
+#define crypto_box_curve25519xsalsa20poly1305_ref_BOXZEROBYTES 16
+#ifdef __cplusplus
+#include <string>
+extern std::string crypto_box_curve25519xsalsa20poly1305_ref(const std::string &,const std::string &,const std::string &,const std::string &);
+extern std::string crypto_box_curve25519xsalsa20poly1305_ref_open(const std::string &,const std::string &,const std::string &,const std::string &);
+extern std::string crypto_box_curve25519xsalsa20poly1305_ref_keypair(std::string *);
+extern "C" {
+#endif
+extern int crypto_box_curve25519xsalsa20poly1305_ref(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *);
+extern int crypto_box_curve25519xsalsa20poly1305_ref_open(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *,const unsigned char *);
+extern int crypto_box_curve25519xsalsa20poly1305_ref_keypair(unsigned char *,unsigned char *);
+extern int crypto_box_curve25519xsalsa20poly1305_ref_beforenm(unsigned char *,const unsigned char *,const unsigned char *);
+extern int crypto_box_curve25519xsalsa20poly1305_ref_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+extern int crypto_box_curve25519xsalsa20poly1305_ref_open_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+#ifdef __cplusplus
+}
+#endif
+
+#define crypto_box_curve25519xsalsa20poly1305 crypto_box_curve25519xsalsa20poly1305_ref
+#define crypto_box_curve25519xsalsa20poly1305_open crypto_box_curve25519xsalsa20poly1305_ref_open
+#define crypto_box_curve25519xsalsa20poly1305_keypair crypto_box_curve25519xsalsa20poly1305_ref_keypair
+#define crypto_box_curve25519xsalsa20poly1305_beforenm crypto_box_curve25519xsalsa20poly1305_ref_beforenm
+#define crypto_box_curve25519xsalsa20poly1305_afternm crypto_box_curve25519xsalsa20poly1305_ref_afternm
+#define crypto_box_curve25519xsalsa20poly1305_open_afternm crypto_box_curve25519xsalsa20poly1305_ref_open_afternm
+#define crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES crypto_box_curve25519xsalsa20poly1305_ref_PUBLICKEYBYTES
+#define crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES crypto_box_curve25519xsalsa20poly1305_ref_SECRETKEYBYTES
+#define crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES crypto_box_curve25519xsalsa20poly1305_ref_BEFORENMBYTES
+#define crypto_box_curve25519xsalsa20poly1305_NONCEBYTES crypto_box_curve25519xsalsa20poly1305_ref_NONCEBYTES
+#define crypto_box_curve25519xsalsa20poly1305_ZEROBYTES crypto_box_curve25519xsalsa20poly1305_ref_ZEROBYTES
+#define crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES crypto_box_curve25519xsalsa20poly1305_ref_BOXZEROBYTES
+#define crypto_box_curve25519xsalsa20poly1305_IMPLEMENTATION "crypto_box/curve25519xsalsa20poly1305/ref"
+#ifndef crypto_box_curve25519xsalsa20poly1305_ref_VERSION
+#define crypto_box_curve25519xsalsa20poly1305_ref_VERSION "-"
+#endif
+#define crypto_box_curve25519xsalsa20poly1305_VERSION crypto_box_curve25519xsalsa20poly1305_ref_VERSION
+
+#endif

+ 28 - 0
NaClCrypto/nacl/include/crypto_core.h

@@ -0,0 +1,28 @@
+#ifndef crypto_core_salsa20_H
+#define crypto_core_salsa20_H
+
+#define crypto_core_salsa20_ref_OUTPUTBYTES 64
+#define crypto_core_salsa20_ref_INPUTBYTES 16
+#define crypto_core_salsa20_ref_KEYBYTES 32
+#define crypto_core_salsa20_ref_CONSTBYTES 16
+#ifdef __cplusplus
+#include <string>
+extern "C" {
+#endif
+extern int crypto_core_salsa20_ref(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
+#ifdef __cplusplus
+}
+#endif
+
+#define crypto_core_salsa20 crypto_core_salsa20_ref
+#define crypto_core_salsa20_OUTPUTBYTES crypto_core_salsa20_ref_OUTPUTBYTES
+#define crypto_core_salsa20_INPUTBYTES crypto_core_salsa20_ref_INPUTBYTES
+#define crypto_core_salsa20_KEYBYTES crypto_core_salsa20_ref_KEYBYTES
+#define crypto_core_salsa20_CONSTBYTES crypto_core_salsa20_ref_CONSTBYTES
+#define crypto_core_salsa20_IMPLEMENTATION "crypto_core/salsa20/ref"
+#ifndef crypto_core_salsa20_ref_VERSION
+#define crypto_core_salsa20_ref_VERSION "-"
+#endif
+#define crypto_core_salsa20_VERSION crypto_core_salsa20_ref_VERSION
+
+#endif

+ 28 - 0
NaClCrypto/nacl/include/crypto_core_hsalsa20.h

@@ -0,0 +1,28 @@
+#ifndef crypto_core_hsalsa20_H
+#define crypto_core_hsalsa20_H
+
+#define crypto_core_hsalsa20_ref_OUTPUTBYTES 32
+#define crypto_core_hsalsa20_ref_INPUTBYTES 16
+#define crypto_core_hsalsa20_ref_KEYBYTES 32
+#define crypto_core_hsalsa20_ref_CONSTBYTES 16
+#ifdef __cplusplus
+#include <string>
+extern "C" {
+#endif
+extern int crypto_core_hsalsa20_ref(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
+#ifdef __cplusplus
+}
+#endif
+
+#define crypto_core_hsalsa20 crypto_core_hsalsa20_ref
+#define crypto_core_hsalsa20_OUTPUTBYTES crypto_core_hsalsa20_ref_OUTPUTBYTES
+#define crypto_core_hsalsa20_INPUTBYTES crypto_core_hsalsa20_ref_INPUTBYTES
+#define crypto_core_hsalsa20_KEYBYTES crypto_core_hsalsa20_ref_KEYBYTES
+#define crypto_core_hsalsa20_CONSTBYTES crypto_core_hsalsa20_ref_CONSTBYTES
+#define crypto_core_hsalsa20_IMPLEMENTATION "crypto_core/hsalsa20/ref"
+#ifndef crypto_core_hsalsa20_ref_VERSION
+#define crypto_core_hsalsa20_ref_VERSION "-"
+#endif
+#define crypto_core_hsalsa20_VERSION crypto_core_hsalsa20_ref_VERSION
+
+#endif

+ 28 - 0
NaClCrypto/nacl/include/crypto_core_salsa20.h

@@ -0,0 +1,28 @@
+#ifndef crypto_core_salsa20_H
+#define crypto_core_salsa20_H
+
+#define crypto_core_salsa20_ref_OUTPUTBYTES 64
+#define crypto_core_salsa20_ref_INPUTBYTES 16
+#define crypto_core_salsa20_ref_KEYBYTES 32
+#define crypto_core_salsa20_ref_CONSTBYTES 16
+#ifdef __cplusplus
+#include <string>
+extern "C" {
+#endif
+extern int crypto_core_salsa20_ref(unsigned char *,const unsigned char *,const unsigned char *,const unsigned char *);
+#ifdef __cplusplus
+}
+#endif
+
+#define crypto_core_salsa20 crypto_core_salsa20_ref
+#define crypto_core_salsa20_OUTPUTBYTES crypto_core_salsa20_ref_OUTPUTBYTES
+#define crypto_core_salsa20_INPUTBYTES crypto_core_salsa20_ref_INPUTBYTES
+#define crypto_core_salsa20_KEYBYTES crypto_core_salsa20_ref_KEYBYTES
+#define crypto_core_salsa20_CONSTBYTES crypto_core_salsa20_ref_CONSTBYTES
+#define crypto_core_salsa20_IMPLEMENTATION "crypto_core/salsa20/ref"
+#ifndef crypto_core_salsa20_ref_VERSION
+#define crypto_core_salsa20_ref_VERSION "-"
+#endif
+#define crypto_core_salsa20_VERSION crypto_core_salsa20_ref_VERSION
+
+#endif

+ 14 - 0
NaClCrypto/nacl/include/crypto_onetimeauth.h

@@ -0,0 +1,14 @@
+#ifndef crypto_onetimeauth_H
+#define crypto_onetimeauth_H
+
+#include "crypto_onetimeauth_poly1305.h"
+
+#define crypto_onetimeauth crypto_onetimeauth_poly1305
+#define crypto_onetimeauth_verify crypto_onetimeauth_poly1305_verify
+#define crypto_onetimeauth_BYTES crypto_onetimeauth_poly1305_BYTES
+#define crypto_onetimeauth_KEYBYTES crypto_onetimeauth_poly1305_KEYBYTES
+#define crypto_onetimeauth_PRIMITIVE "poly1305"
+#define crypto_onetimeauth_IMPLEMENTATION crypto_onetimeauth_poly1305_IMPLEMENTATION
+#define crypto_onetimeauth_VERSION crypto_onetimeauth_poly1305_VERSION
+
+#endif

+ 28 - 0
NaClCrypto/nacl/include/crypto_onetimeauth_poly1305.h

@@ -0,0 +1,28 @@
+#ifndef crypto_onetimeauth_poly1305_H
+#define crypto_onetimeauth_poly1305_H
+
+#define crypto_onetimeauth_poly1305_53_BYTES 16
+#define crypto_onetimeauth_poly1305_53_KEYBYTES 32
+#ifdef __cplusplus
+#include <string>
+extern std::string crypto_onetimeauth_poly1305_53(const std::string &,const std::string &);
+extern void crypto_onetimeauth_poly1305_53_verify(const std::string &,const std::string &,const std::string &);
+extern "C" {
+#endif
+    extern int crypto_onetimeauth_poly1305_53(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
+    extern int crypto_onetimeauth_poly1305_53_verify(const unsigned char *,const unsigned char *,unsigned long long,const unsigned char *);
+#ifdef __cplusplus
+}
+#endif
+
+#define crypto_onetimeauth_poly1305 crypto_onetimeauth_poly1305_53
+#define crypto_onetimeauth_poly1305_verify crypto_onetimeauth_poly1305_53_verify
+#define crypto_onetimeauth_poly1305_BYTES crypto_onetimeauth_poly1305_53_BYTES
+#define crypto_onetimeauth_poly1305_KEYBYTES crypto_onetimeauth_poly1305_53_KEYBYTES
+#define crypto_onetimeauth_poly1305_IMPLEMENTATION "crypto_onetimeauth/poly1305/53"
+#ifndef crypto_onetimeauth_poly1305_53_VERSION
+#define crypto_onetimeauth_poly1305_53_VERSION "-"
+#endif
+#define crypto_onetimeauth_poly1305_VERSION crypto_onetimeauth_poly1305_53_VERSION
+
+#endif

+ 28 - 0
NaClCrypto/nacl/include/crypto_scalarmult.h

@@ -0,0 +1,28 @@
+#ifndef crypto_scalarmult_curve25519_H
+#define crypto_scalarmult_curve25519_H
+
+#define crypto_scalarmult_curve25519_donna_BYTES 32
+#define crypto_scalarmult_curve25519_donna_SCALARBYTES 32
+#ifdef __cplusplus
+#include <string>
+extern std::string crypto_scalarmult_curve25519_donna(const std::string &,const std::string &);
+extern std::string crypto_scalarmult_curve25519_donna_base(const std::string &);
+extern "C" {
+#endif
+extern int crypto_scalarmult_curve25519_donna(unsigned char *,const unsigned char *,const unsigned char *);
+extern int crypto_scalarmult_curve25519_donna_base(unsigned char *,const unsigned char *);
+#ifdef __cplusplus
+}
+#endif
+
+#define crypto_scalarmult_curve25519 crypto_scalarmult_curve25519_donna
+#define crypto_scalarmult_curve25519_base crypto_scalarmult_curve25519_donna_base
+#define crypto_scalarmult_curve25519_BYTES crypto_scalarmult_curve25519_donna_BYTES
+#define crypto_scalarmult_curve25519_SCALARBYTES crypto_scalarmult_curve25519_donna_SCALARBYTES
+#define crypto_scalarmult_curve25519_IMPLEMENTATION "crypto_scalarmult/curve25519/ref"
+#ifndef crypto_scalarmult_curve25519_donna_VERSION
+#define crypto_scalarmult_curve25519_donna_VERSION "-"
+#endif
+#define crypto_scalarmult_curve25519_VERSION crypto_scalarmult_curve25519_donna_VERSION
+
+#endif

+ 28 - 0
NaClCrypto/nacl/include/crypto_scalarmult_curve25519.h

@@ -0,0 +1,28 @@
+#ifndef crypto_scalarmult_curve25519_H
+#define crypto_scalarmult_curve25519_H
+
+#define crypto_scalarmult_curve25519_donna_BYTES 32
+#define crypto_scalarmult_curve25519_donna_SCALARBYTES 32
+#ifdef __cplusplus
+#include <string>
+extern std::string crypto_scalarmult_curve25519_donna(const std::string &,const std::string &);
+extern std::string crypto_scalarmult_curve25519_donna_base(const std::string &);
+extern "C" {
+#endif
+extern int crypto_scalarmult_curve25519_donna(unsigned char *,const unsigned char *,const unsigned char *);
+extern int crypto_scalarmult_curve25519_donna_base(unsigned char *,const unsigned char *);
+#ifdef __cplusplus
+}
+#endif
+
+#define crypto_scalarmult_curve25519 crypto_scalarmult_curve25519_donna
+#define crypto_scalarmult_curve25519_base crypto_scalarmult_curve25519_donna_base
+#define crypto_scalarmult_curve25519_BYTES crypto_scalarmult_curve25519_donna_BYTES
+#define crypto_scalarmult_curve25519_SCALARBYTES crypto_scalarmult_curve25519_donna_SCALARBYTES
+#define crypto_scalarmult_curve25519_IMPLEMENTATION "crypto_scalarmult/curve25519/ref"
+#ifndef crypto_scalarmult_curve25519_donna_VERSION
+#define crypto_scalarmult_curve25519_donna_VERSION "-"
+#endif
+#define crypto_scalarmult_curve25519_VERSION crypto_scalarmult_curve25519_donna_VERSION
+
+#endif

+ 16 - 0
NaClCrypto/nacl/include/crypto_secretbox.h

@@ -0,0 +1,16 @@
+#ifndef crypto_secretbox_H
+#define crypto_secretbox_H
+
+#include "crypto_secretbox_xsalsa20poly1305.h"
+
+#define crypto_secretbox crypto_secretbox_xsalsa20poly1305
+#define crypto_secretbox_open crypto_secretbox_xsalsa20poly1305_open
+#define crypto_secretbox_KEYBYTES crypto_secretbox_xsalsa20poly1305_KEYBYTES
+#define crypto_secretbox_NONCEBYTES crypto_secretbox_xsalsa20poly1305_NONCEBYTES
+#define crypto_secretbox_ZEROBYTES crypto_secretbox_xsalsa20poly1305_ZEROBYTES
+#define crypto_secretbox_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES
+#define crypto_secretbox_PRIMITIVE "xsalsa20poly1305"
+#define crypto_secretbox_IMPLEMENTATION crypto_secretbox_xsalsa20poly1305_IMPLEMENTATION
+#define crypto_secretbox_VERSION crypto_secretbox_xsalsa20poly1305_VERSION
+
+#endif

+ 32 - 0
NaClCrypto/nacl/include/crypto_secretbox_xsalsa20poly1305.h

@@ -0,0 +1,32 @@
+#ifndef crypto_secretbox_xsalsa20poly1305_H
+#define crypto_secretbox_xsalsa20poly1305_H
+
+#define crypto_secretbox_xsalsa20poly1305_ref_KEYBYTES 32
+#define crypto_secretbox_xsalsa20poly1305_ref_NONCEBYTES 24
+#define crypto_secretbox_xsalsa20poly1305_ref_ZEROBYTES 32
+#define crypto_secretbox_xsalsa20poly1305_ref_BOXZEROBYTES 16
+#ifdef __cplusplus
+#include <string>
+extern std::string crypto_secretbox_xsalsa20poly1305_ref(const std::string &,const std::string &,const std::string &);
+extern std::string crypto_secretbox_xsalsa20poly1305_ref_open(const std::string &,const std::string &,const std::string &);
+extern "C" {
+#endif
+extern int crypto_secretbox_xsalsa20poly1305_ref(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+extern int crypto_secretbox_xsalsa20poly1305_ref_open(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+#ifdef __cplusplus
+}
+#endif
+
+#define crypto_secretbox_xsalsa20poly1305 crypto_secretbox_xsalsa20poly1305_ref
+#define crypto_secretbox_xsalsa20poly1305_open crypto_secretbox_xsalsa20poly1305_ref_open
+#define crypto_secretbox_xsalsa20poly1305_KEYBYTES crypto_secretbox_xsalsa20poly1305_ref_KEYBYTES
+#define crypto_secretbox_xsalsa20poly1305_NONCEBYTES crypto_secretbox_xsalsa20poly1305_ref_NONCEBYTES
+#define crypto_secretbox_xsalsa20poly1305_ZEROBYTES crypto_secretbox_xsalsa20poly1305_ref_ZEROBYTES
+#define crypto_secretbox_xsalsa20poly1305_BOXZEROBYTES crypto_secretbox_xsalsa20poly1305_ref_BOXZEROBYTES
+#define crypto_secretbox_xsalsa20poly1305_IMPLEMENTATION "crypto_secretbox/xsalsa20poly1305/ref"
+#ifndef crypto_secretbox_xsalsa20poly1305_ref_VERSION
+#define crypto_secretbox_xsalsa20poly1305_ref_VERSION "-"
+#endif
+#define crypto_secretbox_xsalsa20poly1305_VERSION crypto_secretbox_xsalsa20poly1305_ref_VERSION
+
+#endif

+ 18 - 0
NaClCrypto/nacl/include/crypto_stream.h

@@ -0,0 +1,18 @@
+#ifndef crypto_stream_H
+#define crypto_stream_H
+
+#include "crypto_stream_xsalsa20.h"
+
+#define crypto_stream crypto_stream_xsalsa20
+#define crypto_stream_xor crypto_stream_xsalsa20_xor
+#define crypto_stream_beforenm crypto_stream_xsalsa20_beforenm
+#define crypto_stream_afternm crypto_stream_xsalsa20_afternm
+#define crypto_stream_xor_afternm crypto_stream_xsalsa20_xor_afternm
+#define crypto_stream_KEYBYTES crypto_stream_xsalsa20_KEYBYTES
+#define crypto_stream_NONCEBYTES crypto_stream_xsalsa20_NONCEBYTES
+#define crypto_stream_BEFORENMBYTES crypto_stream_xsalsa20_BEFORENMBYTES
+#define crypto_stream_PRIMITIVE "xsalsa20"
+#define crypto_stream_IMPLEMENTATION crypto_stream_xsalsa20_IMPLEMENTATION
+#define crypto_stream_VERSION crypto_stream_xsalsa20_VERSION
+
+#endif

+ 35 - 0
NaClCrypto/nacl/include/crypto_stream_salsa20.h

@@ -0,0 +1,35 @@
+#ifndef crypto_stream_salsa20_H
+#define crypto_stream_salsa20_H
+
+#define crypto_stream_salsa20_ref_KEYBYTES 32
+#define crypto_stream_salsa20_ref_NONCEBYTES 8
+#ifdef __cplusplus
+#include <string>
+extern std::string crypto_stream_salsa20_ref(size_t,const std::string &,const std::string &);
+extern std::string crypto_stream_salsa20_ref_xor(const std::string &,const std::string &,const std::string &);
+extern "C" {
+#endif
+extern int crypto_stream_salsa20_ref(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+extern int crypto_stream_salsa20_ref_xor(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+extern int crypto_stream_salsa20_ref_beforenm(unsigned char *,const unsigned char *);
+extern int crypto_stream_salsa20_ref_afternm(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+extern int crypto_stream_salsa20_ref_xor_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+#ifdef __cplusplus
+}
+#endif
+
+#define crypto_stream_salsa20 crypto_stream_salsa20_ref
+#define crypto_stream_salsa20_xor crypto_stream_salsa20_ref_xor
+#define crypto_stream_salsa20_beforenm crypto_stream_salsa20_ref_beforenm
+#define crypto_stream_salsa20_afternm crypto_stream_salsa20_ref_afternm
+#define crypto_stream_salsa20_xor_afternm crypto_stream_salsa20_ref_xor_afternm
+#define crypto_stream_salsa20_KEYBYTES crypto_stream_salsa20_ref_KEYBYTES
+#define crypto_stream_salsa20_NONCEBYTES crypto_stream_salsa20_ref_NONCEBYTES
+#define crypto_stream_salsa20_BEFORENMBYTES crypto_stream_salsa20_ref_BEFORENMBYTES
+#define crypto_stream_salsa20_IMPLEMENTATION "crypto_stream/salsa20/ref"
+#ifndef crypto_stream_salsa20_ref_VERSION
+#define crypto_stream_salsa20_ref_VERSION "-"
+#endif
+#define crypto_stream_salsa20_VERSION crypto_stream_salsa20_ref_VERSION
+
+#endif

+ 35 - 0
NaClCrypto/nacl/include/crypto_stream_xsalsa20.h

@@ -0,0 +1,35 @@
+#ifndef crypto_stream_xsalsa20_H
+#define crypto_stream_xsalsa20_H
+
+#define crypto_stream_xsalsa20_ref_KEYBYTES 32
+#define crypto_stream_xsalsa20_ref_NONCEBYTES 24
+#ifdef __cplusplus
+#include <string>
+extern std::string crypto_stream_xsalsa20_ref(size_t,const std::string &,const std::string &);
+extern std::string crypto_stream_xsalsa20_ref_xor(const std::string &,const std::string &,const std::string &);
+extern "C" {
+#endif
+extern int crypto_stream_xsalsa20_ref(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+extern int crypto_stream_xsalsa20_ref_xor(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+extern int crypto_stream_xsalsa20_ref_beforenm(unsigned char *,const unsigned char *);
+extern int crypto_stream_xsalsa20_ref_afternm(unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+extern int crypto_stream_xsalsa20_ref_xor_afternm(unsigned char *,const unsigned char *,unsigned long long,const unsigned char *,const unsigned char *);
+#ifdef __cplusplus
+}
+#endif
+
+#define crypto_stream_xsalsa20 crypto_stream_xsalsa20_ref
+#define crypto_stream_xsalsa20_xor crypto_stream_xsalsa20_ref_xor
+#define crypto_stream_xsalsa20_beforenm crypto_stream_xsalsa20_ref_beforenm
+#define crypto_stream_xsalsa20_afternm crypto_stream_xsalsa20_ref_afternm
+#define crypto_stream_xsalsa20_xor_afternm crypto_stream_xsalsa20_ref_xor_afternm
+#define crypto_stream_xsalsa20_KEYBYTES crypto_stream_xsalsa20_ref_KEYBYTES
+#define crypto_stream_xsalsa20_NONCEBYTES crypto_stream_xsalsa20_ref_NONCEBYTES
+#define crypto_stream_xsalsa20_BEFORENMBYTES crypto_stream_xsalsa20_ref_BEFORENMBYTES
+#define crypto_stream_xsalsa20_IMPLEMENTATION "crypto_stream/xsalsa20/ref"
+#ifndef crypto_stream_xsalsa20_ref_VERSION
+#define crypto_stream_xsalsa20_ref_VERSION "-"
+#endif
+#define crypto_stream_xsalsa20_VERSION crypto_stream_xsalsa20_ref_VERSION
+
+#endif

+ 22 - 0
NaClCrypto/nacl/include/crypto_verify_16.h

@@ -0,0 +1,22 @@
+#ifndef crypto_verify_16_H
+#define crypto_verify_16_H
+
+#define crypto_verify_16_ref_BYTES 16
+#ifdef __cplusplus
+#include <string>
+extern "C" {
+#endif
+extern int crypto_verify_16_ref(const unsigned char *,const unsigned char *);
+#ifdef __cplusplus
+}
+#endif
+
+#define crypto_verify_16 crypto_verify_16_ref
+#define crypto_verify_16_BYTES crypto_verify_16_ref_BYTES
+#define crypto_verify_16_IMPLEMENTATION "crypto_verify/16/ref"
+#ifndef crypto_verify_16_ref_VERSION
+#define crypto_verify_16_ref_VERSION "-"
+#endif
+#define crypto_verify_16_VERSION crypto_verify_16_ref_VERSION
+
+#endif

+ 22 - 0
NaClCrypto/nacl/include/crypto_verify_32.h

@@ -0,0 +1,22 @@
+#ifndef crypto_verify_32_H
+#define crypto_verify_32_H
+
+#define crypto_verify_32_ref_BYTES 32
+#ifdef __cplusplus
+#include <string>
+extern "C" {
+#endif
+extern int crypto_verify_32_ref(const unsigned char *,const unsigned char *);
+#ifdef __cplusplus
+}
+#endif
+
+#define crypto_verify_32 crypto_verify_32_ref
+#define crypto_verify_32_BYTES crypto_verify_32_ref_BYTES
+#define crypto_verify_32_IMPLEMENTATION "crypto_verify/32/ref"
+#ifndef crypto_verify_32_ref_VERSION
+#define crypto_verify_32_ref_VERSION "-"
+#endif
+#define crypto_verify_32_VERSION crypto_verify_32_ref_VERSION
+
+#endif

+ 24 - 0
NaClCrypto/nacl/include/randombytes.h

@@ -0,0 +1,24 @@
+/*
+randombytes/devurandom.h version 20080713
+D. J. Bernstein
+Public domain.
+*/
+
+#ifndef randombytes_devurandom_H
+#define randombytes_devurandom_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void randombytes(unsigned char *,unsigned long long);
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifndef randombytes_implementation
+#define randombytes_implementation "devurandom"
+#endif
+
+#endif

+ 36 - 0
NaClCrypto/nacl/randombytes/devurandom.c

@@ -0,0 +1,36 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "randombytes.h"
+
+/* it's really stupid that there isn't a syscall for this */
+
+static int fd = -1;
+
+void randombytes(unsigned char *x,unsigned long long xlen)
+{
+  ssize_t i;
+
+  if (fd == -1) {
+    for (;;) {
+      fd = open("/dev/urandom",O_RDONLY);
+      if (fd != -1) break;
+      sleep(1);
+    }
+  }
+
+  while (xlen > 0) {
+    if (xlen < 1048576) i = (ssize_t)xlen; else i = 1048576;
+
+    i = read(fd,x,i);
+    if (i < 1) {
+      sleep(1);
+      continue;
+    }
+
+    x += i;
+    xlen -= i;
+  }
+}

+ 24 - 0
NaClCrypto/nacl/randombytes/devurandom.h

@@ -0,0 +1,24 @@
+/*
+randombytes/devurandom.h version 20080713
+D. J. Bernstein
+Public domain.
+*/
+
+#ifndef randombytes_devurandom_H
+#define randombytes_devurandom_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern void randombytes(unsigned char *,unsigned long long);
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifndef randombytes_implementation
+#define randombytes_implementation "devurandom"
+#endif
+
+#endif

+ 170 - 0
README.md

@@ -0,0 +1,170 @@
+<div align="center">
+  <!-- Centered README header hack -->
+  <img width="400" src="logo.svg">
+  <br><br>
+</div>
+
+# Threema for iOS
+
+[This repository](https://github.com/threema-ch/threema-ios) contains the complete source code of [Threema](https://threema.ch/) for iOS.
+
+## Table of Contents
+
+- [Bug Reports / Feature Requests / Security Issues](#issues)
+- [Source Code Release Policy](#release-policy)
+- [License Checks](#license-checks)
+- [Schemes](#schemes)
+- [Building](#building)
+- [Testing](#testing)
+- [Reproducible Builds](#reproducible-builds)
+- [Code Organization / Architecture](#architecture)
+- [Contributions](#contributions)
+- [License](#license)
+
+
+## <a name="issues"></a>Bug Reports / Feature Requests / Security Issues
+
+To report bugs and request new features, please contact the [Threema support team](https://threema.ch/support).
+
+If you find a security issue in Threema, please follow responsible disclosure and report it to us via Threema or by encrypted email, we will try to respond as quickly as possible. You can find the contact details at
+ [threema.ch/contact](https://threema.ch/contact) (section "Security").
+
+
+## <a name="release-policy"></a>Source Code Release Policy
+
+This source code repository will be updated for every public non-beta release. There will be one commit per released version.
+
+
+## <a name="license-checks"></a>License Checks
+
+While the source code for Threema for iOS is published under an open source license, Threema is still a paid app. To run the app in combination with our official server infrastructure, you must have bought a license on the App Store. 
+
+The app uses two different license check types, depending on the target app:
+
+### App Store Licensing
+
+When creating a new Threema ID using the Threema app bought on the [App Store](https://apps.apple.com/gw/app/threema/id578665578), the app sends the digitally signed App Store receipt to the directory server. This allows the server to verify that you have indeed bought the app, without being able to identify you. 
+
+This means that a self-compiled app using the `Threema` scheme cannot be used to create a new Threema ID. You can, however, use an app that was purchased in the App Store to create an ID and then export a backup. This backup can then be imported into the self-compiled app. 
+
+Note that the ID creation endpoint is monitored for abuse.
+
+### Threema Work
+
+If you build the Threema Work target, credentials from the [Threema Work](https://work.threema.ch/) subscription must be provided in order to use the app.
+
+## <a name="schemes"></a>Schemes
+
+- `Threema` builds and tests the consumer app. (recommended for local testing)
+- `ThreemaWork` builds and tests the enterprise version of our app.
+
+
+## <a name="building"></a>Building
+
+To get started you need a [Mac](https://www.apple.com/mac/), [Xcode](https://developer.apple.com/xcode/) (12.2) and a (free) [Apple Developer Account](https://developer.apple.com/programs/).
+
+### 1. Install Dependencies
+
+1. Install [Carthage](https://github.com/Carthage/Carthage)
+
+   ```sh
+   brew install carthage
+   ```
+
+   (If you don't have [homebrew](https://brew.sh) see their [official install instructions](https://github.com/Carthage/Carthage#installing-carthage).)
+
+2. If your Xcode installation is fresh make sure that command line tools are selected
+
+   ```sh
+   sudo xcode-select --switch /Applications/Xcode.app
+   ```
+
+3. Install and build the dependencies
+
+   ```sh
+   ./scripts/build.sh --dependencies
+   ```
+
+   This checks out and builds Carthage dependencies, and downloads debug and release WebRTC binaries if they are missing. (The script uses a workaround for limitations of [Carthage with Xcode 12](https://github.com/Carthage/Carthage/blob/master/Documentation/Xcode12Workaround.md). If you want to build WebRTC yourself see [BUILD_WEBRTC.md](BUILD_WEBRTC.md).)
+
+### 2. Setup Project
+
+You can either build the Threema app (recommended) or Threema Work app. 
+
+_Note_: These setups are for running in the simulator.
+
+#### Threema (recommended)
+
+1. Open `Threema.xcproject` in Xcode
+2. Repeat these steps for the `Threema` and `ThreemaShareExtension` target
+   1. Check "Automatically manage signing" and confirm it ("Enable Automatic")
+   2. Set "Team" to the team of your developer account
+3. Choose `Threema` as scheme and a simulator
+
+#### Threema Work
+
+1. Open `Threema.xcproject` in Xcode
+2. Repeat these steps for the `Threema Work` and `ThreemaForWorkShareExtension` target
+   1. Check "Automatically manage signing" and confirm it ("Enable Automatic")
+   2. Set "Team" to the team of your developer account
+3. Choose `Threema Work` as scheme and a simulator
+
+### 3. Build and Run
+
+1. Build and Run
+2. To create a Threema ID see "App Store Licensing" above. (You can cancel the "Sign in with Apple ID" dialogue and import a Threema ID backup.)
+
+_Note_: We currently don't support Apple Silicon based Macs, because of current limitations of [Carthage with Xcode 12](https://github.com/Carthage/Carthage/blob/master/Documentation/Xcode12Workaround.md) and our current WebRTC builds.
+
+
+## <a name="testing"></a>Testing
+
+See "Building" for setting up a running environment. Before running the tests check if you can sucessfully build and run the app.
+
+- Choose `Threema` as scheme to run the app and framework tests.
+- Choose `ThreemaWork` as scheme to run Threema Work specific tests.
+
+
+## <a name="reproducible-builds"></a>Reproducible Builds
+
+Due to restrictions by Apple, it’s no easy task to offer reproducible builds for iOS, but we are currently evaluating possible ways to also support reproducible builds for this platform.
+
+
+## <a name="architecture"></a>Code Organization / Architecture
+
+Before digging into the codebase, you should read the [Cryptography Whitepaper](https://threema.ch/press-files/2_documentation/cryptography_whitepaper.pdf) to understand the design concepts.
+
+These are the most important groups of the Xcode project:
+
+- `ThreemaFramework`: Shared code between the main app and extensions
+- `Threema`: Code of both apps (Threema and Threema Work)
+- `ThreemaShareExtension`: Code of share extension
+- `Threema{Framework}Tests`: Test files
+
+Our dependencies are manged with Carthage. Additionally we use WebRTC based on binaries hosted on our servers. If you want to build WebRTC yourself see [BUILD_WEBRTC.md](BUILD_WEBRTC.md).
+
+
+## <a name="contributions"></a>Contributions
+
+For the time being, we do not accept contributions via GitHub. If you want to make a contribution, first make sure that you have signed the [CLA](https://threema.ch/open-source/cla/). You can then submit patches over email by following the instructions at [threema.ch/open-source/contributions/](https://threema.ch/open-source/contributions/).
+
+
+## <a name="license"></a>License
+
+Threema for iOS is licensed under the GNU Affero General Public License v3.
+
+    Copyright (c) 2012-2020 Threema GmbH
+    
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License, version 3,
+    as published by the Free Software Foundation.
+    
+    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 Affero General Public License for more details.
+    
+    You should have received a copy of the GNU Affero General Public License
+    along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+The full license text can be found in [`LICENSE.txt`](LICENSE.txt).

BIN
Resources/Images.xcassets/AppIcon.appiconset/100.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/1024.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/114.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/120-1.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/120.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/144.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/152.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/167.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/180.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/20.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/29-1.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/29.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/40-1.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/40-2.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/40.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/50.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/57.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/58-1.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/58.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/60.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/72.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/76.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/80-1.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/80.png


BIN
Resources/Images.xcassets/AppIcon.appiconset/87.png


+ 158 - 0
Resources/Images.xcassets/AppIcon.appiconset/Contents.json

@@ -0,0 +1,158 @@
+{
+  "images" : [
+    {
+      "size" : "20x20",
+      "idiom" : "iphone",
+      "filename" : "40.png",
+      "scale" : "2x"
+    },
+    {
+      "size" : "20x20",
+      "idiom" : "iphone",
+      "filename" : "60.png",
+      "scale" : "3x"
+    },
+    {
+      "size" : "29x29",
+      "idiom" : "iphone",
+      "filename" : "29.png",
+      "scale" : "1x"
+    },
+    {
+      "size" : "29x29",
+      "idiom" : "iphone",
+      "filename" : "58.png",
+      "scale" : "2x"
+    },
+    {
+      "size" : "29x29",
+      "idiom" : "iphone",
+      "filename" : "87.png",
+      "scale" : "3x"
+    },
+    {
+      "size" : "40x40",
+      "idiom" : "iphone",
+      "filename" : "80.png",
+      "scale" : "2x"
+    },
+    {
+      "size" : "40x40",
+      "idiom" : "iphone",
+      "filename" : "120.png",
+      "scale" : "3x"
+    },
+    {
+      "size" : "57x57",
+      "idiom" : "iphone",
+      "filename" : "57.png",
+      "scale" : "1x"
+    },
+    {
+      "size" : "57x57",
+      "idiom" : "iphone",
+      "filename" : "114.png",
+      "scale" : "2x"
+    },
+    {
+      "size" : "60x60",
+      "idiom" : "iphone",
+      "filename" : "120-1.png",
+      "scale" : "2x"
+    },
+    {
+      "size" : "60x60",
+      "idiom" : "iphone",
+      "filename" : "180.png",
+      "scale" : "3x"
+    },
+    {
+      "size" : "20x20",
+      "idiom" : "ipad",
+      "filename" : "20.png",
+      "scale" : "1x"
+    },
+    {
+      "size" : "20x20",
+      "idiom" : "ipad",
+      "filename" : "40-1.png",
+      "scale" : "2x"
+    },
+    {
+      "size" : "29x29",
+      "idiom" : "ipad",
+      "filename" : "29-1.png",
+      "scale" : "1x"
+    },
+    {
+      "size" : "29x29",
+      "idiom" : "ipad",
+      "filename" : "58-1.png",
+      "scale" : "2x"
+    },
+    {
+      "size" : "40x40",
+      "idiom" : "ipad",
+      "filename" : "40-2.png",
+      "scale" : "1x"
+    },
+    {
+      "size" : "40x40",
+      "idiom" : "ipad",
+      "filename" : "80-1.png",
+      "scale" : "2x"
+    },
+    {
+      "size" : "50x50",
+      "idiom" : "ipad",
+      "filename" : "50.png",
+      "scale" : "1x"
+    },
+    {
+      "size" : "50x50",
+      "idiom" : "ipad",
+      "filename" : "100.png",
+      "scale" : "2x"
+    },
+    {
+      "size" : "72x72",
+      "idiom" : "ipad",
+      "filename" : "72.png",
+      "scale" : "1x"
+    },
+    {
+      "size" : "72x72",
+      "idiom" : "ipad",
+      "filename" : "144.png",
+      "scale" : "2x"
+    },
+    {
+      "size" : "76x76",
+      "idiom" : "ipad",
+      "filename" : "76.png",
+      "scale" : "1x"
+    },
+    {
+      "size" : "76x76",
+      "idiom" : "ipad",
+      "filename" : "152.png",
+      "scale" : "2x"
+    },
+    {
+      "size" : "83.5x83.5",
+      "idiom" : "ipad",
+      "filename" : "167.png",
+      "scale" : "2x"
+    },
+    {
+      "size" : "1024x1024",
+      "idiom" : "ios-marketing",
+      "filename" : "1024.png",
+      "scale" : "1x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

+ 6 - 0
Resources/Images.xcassets/Contents.json

@@ -0,0 +1,6 @@
+{
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
Resources/Images/Icons.xcassets/AcceptCall.imageset/AcceptCall.pdf


+ 15 - 0
Resources/Images/Icons.xcassets/AcceptCall.imageset/Contents.json

@@ -0,0 +1,15 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "AcceptCall.pdf"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  },
+  "properties" : {
+    "preserves-vector-representation" : true
+  }
+}

BIN
Resources/Images/Icons.xcassets/ActionBallot.imageset/ActionBallot.pdf


+ 15 - 0
Resources/Images/Icons.xcassets/ActionBallot.imageset/Contents.json

@@ -0,0 +1,15 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "ActionBallot.pdf"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  },
+  "properties" : {
+    "preserves-vector-representation" : true
+  }
+}

BIN
Resources/Images/Icons.xcassets/ActionCamera.imageset/ActionCamera.pdf


+ 15 - 0
Resources/Images/Icons.xcassets/ActionCamera.imageset/Contents.json

@@ -0,0 +1,15 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "ActionCamera.pdf"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  },
+  "properties" : {
+    "preserves-vector-representation" : true
+  }
+}

BIN
Resources/Images/Icons.xcassets/ActionFile.imageset/ActionFile.pdf


+ 15 - 0
Resources/Images/Icons.xcassets/ActionFile.imageset/Contents.json

@@ -0,0 +1,15 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "ActionFile.pdf"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  },
+  "properties" : {
+    "preserves-vector-representation" : true
+  }
+}

BIN
Resources/Images/Icons.xcassets/ActionLocation.imageset/ActionLocation.pdf


+ 15 - 0
Resources/Images/Icons.xcassets/ActionLocation.imageset/Contents.json

@@ -0,0 +1,15 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "ActionLocation.pdf"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  },
+  "properties" : {
+    "preserves-vector-representation" : true
+  }
+}

BIN
Resources/Images/Icons.xcassets/ActionMicrophone.imageset/ActionMicrophone.pdf


+ 15 - 0
Resources/Images/Icons.xcassets/ActionMicrophone.imageset/Contents.json

@@ -0,0 +1,15 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "ActionMicrophone.pdf"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  },
+  "properties" : {
+    "preserves-vector-representation" : true
+  }
+}

BIN
Resources/Images/Icons.xcassets/ActionPhoto.imageset/ActionPhoto.pdf


+ 15 - 0
Resources/Images/Icons.xcassets/ActionPhoto.imageset/Contents.json

@@ -0,0 +1,15 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "ActionPhoto.pdf"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  },
+  "properties" : {
+    "preserves-vector-representation" : true
+  }
+}

BIN
Resources/Images/Icons.xcassets/AddMember.imageset/AddMember.pdf


+ 15 - 0
Resources/Images/Icons.xcassets/AddMember.imageset/Contents.json

@@ -0,0 +1,15 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "AddMember.pdf"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  },
+  "properties" : {
+    "preserves-vector-representation" : true
+  }
+}

BIN
Resources/Images/Icons.xcassets/AdvancedDark.imageset/AdvancedDark.pdf


+ 12 - 0
Resources/Images/Icons.xcassets/AdvancedDark.imageset/Contents.json

@@ -0,0 +1,12 @@
+{
+  "images" : [
+    {
+      "filename" : "AdvancedDark.pdf",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

Някои файлове не бяха показани, защото твърде много файлове са промени