-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-add EdDSA support + static libsodium #67
Changes from all commits
165b36c
58f080c
1be4a6b
9041581
547d0e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,5 @@ cabal-dev | |
.cabal-sandbox | ||
cabal.sandbox.config | ||
/tmp | ||
/gen | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#!/usr/bin/env runhaskell | ||
|
||
import Data.Char (isDigit, toLower) | ||
import Data.Function (on) | ||
import Data.List (intercalate, sortBy) | ||
import Data.Monoid ((<>)) | ||
import Data.Version (showVersion) | ||
|
||
import Distribution.InstalledPackageInfo | ||
import Distribution.PackageDescription | ||
import Distribution.Simple | ||
import Distribution.Simple.Setup (BuildFlags(..), ReplFlags(..), TestFlags(..), fromFlag) | ||
import Distribution.Simple.LocalBuildInfo | ||
import Distribution.Simple.PackageIndex | ||
import Distribution.Simple.BuildPaths (autogenModulesDir) | ||
import Distribution.Simple.Utils (createDirectoryIfMissingVerbose, rewriteFile, rawSystemStdout) | ||
import Distribution.Verbosity | ||
|
||
import System.Directory (createDirectoryIfMissing, getCurrentDirectory, setCurrentDirectory) | ||
import System.FilePath ((</>)) | ||
import System.Process (callProcess) | ||
|
||
main :: IO () | ||
main = | ||
let hooks = simpleUserHooks | ||
in defaultMainWithHooks hooks { | ||
preConf = \args flags -> do | ||
createDirectoryIfMissingVerbose silent True "gen" | ||
(preConf hooks) args flags | ||
, sDistHook = \pd mlbi uh flags -> do | ||
genBuildInfo silent pd | ||
(sDistHook hooks) pd mlbi uh flags | ||
, buildHook = \pd lbi uh flags -> do | ||
genBuildInfo (fromFlag $ buildVerbosity flags) pd | ||
genDependencyInfo (fromFlag $ buildVerbosity flags) pd lbi | ||
buildLibSodium | ||
(buildHook hooks) pd lbi uh flags | ||
, replHook = \pd lbi uh flags args -> do | ||
genBuildInfo (fromFlag $ replVerbosity flags) pd | ||
genDependencyInfo (fromFlag $ replVerbosity flags) pd lbi | ||
(replHook hooks) pd lbi uh flags args | ||
, testHook = \args pd lbi uh flags -> do | ||
genBuildInfo (fromFlag $ testVerbosity flags) pd | ||
genDependencyInfo (fromFlag $ testVerbosity flags) pd lbi | ||
(testHook hooks) args pd lbi uh flags | ||
} | ||
|
||
buildLibSodium :: IO () | ||
buildLibSodium = do | ||
cwd <- getCurrentDirectory | ||
let | ||
sodiumDir = cwd </> "gen" </> "libsodium" | ||
createDirectoryIfMissing True sodiumDir | ||
setCurrentDirectory $ cwd </> "lib" </> "libsodium" | ||
callProcess "./configure" ["--prefix=" <> sodiumDir] | ||
callProcess "make" ["-j"] | ||
callProcess "make" ["install"] | ||
setCurrentDirectory cwd | ||
|
||
genBuildInfo :: Verbosity -> PackageDescription -> IO () | ||
genBuildInfo verbosity pkg = do | ||
createDirectoryIfMissingVerbose verbosity True "gen" | ||
let (PackageName pname) = pkgName . package $ pkg | ||
version = pkgVersion . package $ pkg | ||
name = "BuildInfo_" ++ (map (\c -> if c == '-' then '_' else c) pname) | ||
targetHs = "gen/" ++ name ++ ".hs" | ||
targetText = "gen/version.txt" | ||
t <- timestamp verbosity | ||
gv <- gitVersion verbosity | ||
let v = showVersion version | ||
let buildVersion = intercalate "-" [v, t, gv] | ||
rewriteFile targetHs $ unlines [ | ||
"module " ++ name ++ " where" | ||
, "import Prelude" | ||
, "data RuntimeBuildInfo = RuntimeBuildInfo { buildVersion :: String, timestamp :: String, gitVersion :: String }" | ||
, "buildInfo :: RuntimeBuildInfo" | ||
, "buildInfo = RuntimeBuildInfo \"" ++ v ++ "\" \"" ++ t ++ "\" \"" ++ gv ++ "\"" | ||
, "buildInfoVersion :: String" | ||
, "buildInfoVersion = \"" ++ buildVersion ++ "\"" | ||
] | ||
rewriteFile targetText buildVersion | ||
|
||
genDependencyInfo :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO () | ||
genDependencyInfo verbosity pkg info = do | ||
let | ||
(PackageName pname) = pkgName . package $ pkg | ||
name = "DependencyInfo_" ++ (map (\c -> if c == '-' then '_' else c) pname) | ||
targetHs = autogenModulesDir info ++ "/" ++ name ++ ".hs" | ||
render p = | ||
let | ||
n = unPackageName $ pkgName p | ||
v = intercalate "." . fmap show . versionBranch $ pkgVersion p | ||
in | ||
n ++ "-" ++ v | ||
deps = fmap (render . sourcePackageId) . allPackages $ installedPkgs info | ||
sdeps = sortBy (compare `on` fmap toLower) deps | ||
strs = flip fmap sdeps $ \d -> "\"" ++ d ++ "\"" | ||
|
||
createDirectoryIfMissingVerbose verbosity True (autogenModulesDir info) | ||
|
||
rewriteFile targetHs $ unlines [ | ||
"module " ++ name ++ " where" | ||
, "import Prelude" | ||
, "dependencyInfo :: [String]" | ||
, "dependencyInfo = [\n " ++ intercalate "\n , " strs ++ "\n ]" | ||
] | ||
|
||
gitVersion :: Verbosity -> IO String | ||
gitVersion verbosity = do | ||
ver <- rawSystemStdout verbosity "git" ["log", "--pretty=format:%h", "-n", "1"] | ||
notModified <- ((>) 1 . length) `fmap` rawSystemStdout verbosity "git" ["status", "--porcelain"] | ||
return $ ver ++ if notModified then "" else "-M" | ||
|
||
timestamp :: Verbosity -> IO String | ||
timestamp verbosity = | ||
rawSystemStdout verbosity "date" ["+%Y%m%d%H%M%S"] >>= \s -> | ||
case splitAt 14 s of | ||
(d, n : []) -> | ||
if (length d == 14 && filter isDigit d == d) | ||
then return d | ||
else fail $ "date has failed to produce the correct format [" <> s <> "]." | ||
_ -> | ||
fail $ "date has failed to produce a date long enough [" <> s <> "]." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#! /bin/sh -eux | ||
|
||
echo "$@" | grep -q --version \ | ||
&& gcc $@ \ | ||
|| gcc $@ "$(pwd)/gen/libsodium/lib/libsodium.a" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <sodium.h> | ||
|
||
#include "constants.h" | ||
|
||
size_t tinfoil_sodium_pubkey_len(void) { | ||
return crypto_sign_PUBLICKEYBYTES; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep thanks, I thought I'd fixed that here but must have missed a few functions. |
||
} | ||
|
||
size_t tinfoil_sodium_seckey_len(void) { | ||
return crypto_sign_SECRETKEYBYTES; | ||
} | ||
|
||
size_t tinfoil_sodium_sig_len(void) { | ||
return crypto_sign_BYTES; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef H_TINFOIL_SODIUM_CONSTANTS | ||
#define H_TINFOIL_SODIUM_CONSTANTS | ||
|
||
#include <stdlib.h> | ||
|
||
#include <sodium.h> | ||
|
||
size_t tinfoil_sodium_pubkey_len(void); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above. |
||
size_t tinfoil_sodium_seckey_len(void); | ||
|
||
size_t tinfoil_sodium_sig_len(void); | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ | |
#define H_TINFOIL | ||
|
||
#include "memory.h" | ||
#include "sodium/constants.h" | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
*.bc | ||
*.cmake | ||
*.dSYM | ||
*.done | ||
*.final | ||
*.gcda | ||
*.gcno | ||
*.i | ||
*.la | ||
*.lo | ||
*.log | ||
*.mem | ||
*.nexe | ||
*.o | ||
*.plist | ||
*.s | ||
*.scan | ||
*.sdf | ||
*.status | ||
*.tar.* | ||
*~ | ||
.DS_Store | ||
.deps | ||
.dirstamp | ||
.done | ||
.libs | ||
/bin/ | ||
/obj/ | ||
Build | ||
INSTALL | ||
Makefile | ||
Vagrantfile | ||
aclocal.m4 | ||
android-toolchain | ||
android-toolchain-* | ||
autom4te.cache | ||
build | ||
confdefs.h | ||
coverage.info | ||
libsodium-*.tar.bz2 | ||
libsodium-*.tar.gz | ||
libsodium-*.vcproj | ||
libsodium-*.vcproj.filters | ||
libsodium-*.vcxproj | ||
libsodium-*.vcxproj.filters | ||
libsodium-android-* | ||
libsodium-ios | ||
libsodium-js | ||
libsodium-js-* | ||
libsodium-nativeclient | ||
libsodium-nativeclient-* | ||
libsodium-osx | ||
libsodium-uninstalled.pc | ||
libsodium-win32 | ||
libsodium-win64 | ||
libsodium.pc | ||
libtool | ||
man/*.html | ||
src/libsodium/*.def | ||
src/libsodium/include/sodium/version.h | ||
stamp-* | ||
test/default/browser | ||
test/default/*.res | ||
test/default/*.trs | ||
test/default/aead_aes256gcm | ||
test/default/aead_chacha20poly1305 | ||
test/default/auth | ||
test/default/auth2 | ||
test/default/auth3 | ||
test/default/auth5 | ||
test/default/auth6 | ||
test/default/auth7 | ||
test/default/box | ||
test/default/box2 | ||
test/default/box7 | ||
test/default/box8 | ||
test/default/box_easy | ||
test/default/box_easy2 | ||
test/default/box_seal | ||
test/default/box_seed | ||
test/default/chacha20 | ||
test/default/core1 | ||
test/default/core2 | ||
test/default/core3 | ||
test/default/core4 | ||
test/default/core5 | ||
test/default/core6 | ||
test/default/ed25519_convert | ||
test/default/generichash | ||
test/default/generichash2 | ||
test/default/generichash3 | ||
test/default/hash | ||
test/default/hash3 | ||
test/default/onetimeauth | ||
test/default/onetimeauth2 | ||
test/default/onetimeauth7 | ||
test/default/pwhash | ||
test/default/pwhash_scrypt | ||
test/default/pwhash_scrypt_ll | ||
test/default/randombytes | ||
test/default/scalarmult | ||
test/default/scalarmult2 | ||
test/default/scalarmult5 | ||
test/default/scalarmult6 | ||
test/default/scalarmult7 | ||
test/default/secretbox | ||
test/default/secretbox2 | ||
test/default/secretbox7 | ||
test/default/secretbox8 | ||
test/default/secretbox_easy | ||
test/default/secretbox_easy2 | ||
test/default/shorthash | ||
test/default/sign | ||
test/default/sodium_core | ||
test/default/sodium_utils | ||
test/default/sodium_utils2 | ||
test/default/sodium_utils3 | ||
test/default/sodium_version | ||
test/default/stream | ||
test/default/stream2 | ||
test/default/stream3 | ||
test/default/stream4 | ||
test/default/verify1 | ||
test/js.done | ||
testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want
-Wextra
there as well just to see the extra warnings.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-Wextra for the C code right? You're right, but shouldn't it go in
cc-opts
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, misread that, but
-Wextra
for the C code, always :).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, added, annoyed I didn't have it on from the start.