Skip to content

Commit

Permalink
Merge pull request #496 from Concordium/arkworks-integration
Browse files Browse the repository at this point in the history
Arkworks integration and ed25519 upgrade
  • Loading branch information
annenkov authored Jan 18, 2024
2 parents bd93a27 + 0ef0868 commit a73ba79
Show file tree
Hide file tree
Showing 121 changed files with 3,334 additions and 3,981 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Code should be formatted using [`fourmolu`](https://github.com/fourmolu/fourmolu
version `0.13.1.0` and using the config `fourmolu.yaml` found in the project root.
The CI is setup to ensure the code follows this style.

To check the formatting locally run the following commnad from the project root:
To check the formatting locally run the following command from the project root:


**On unix-like systems**:
Expand Down
2 changes: 1 addition & 1 deletion haskell-src/Concordium/Crypto/BlockSignature.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ signatureLength :: Int
signatureLength = Ed25519.signatureSize

sign :: KeyPair -> ByteString -> Signature
sign KeyPair{..} = Signature . Ed25519.sign signKey verifyKey
sign KeyPair{..} = Signature . Ed25519.sign signKey

verify :: VerifyKey -> ByteString -> Signature -> Bool
verify vfKey bs (Signature s) = Ed25519.verify vfKey bs s
Expand Down
17 changes: 8 additions & 9 deletions haskell-src/Concordium/Crypto/Ed25519Signature.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import System.IO.Unsafe

foreign import ccall unsafe "eddsa_priv_key" genPrivateKey :: IO (Ptr SignKey)
foreign import ccall unsafe "eddsa_pub_key" derivePublicFFI :: Ptr SignKey -> IO (Ptr VerifyKey)
foreign import ccall unsafe "eddsa_sign" signFFI :: Ptr Word8 -> Word32 -> Ptr SignKey -> Ptr VerifyKey -> Ptr Word8 -> IO ()
foreign import ccall unsafe "eddsa_sign" signFFI :: Ptr Word8 -> Word32 -> Ptr SignKey -> Ptr Word8 -> IO ()
foreign import ccall unsafe "eddsa_verify" verifyFFI :: Ptr Word8 -> Word32 -> Ptr VerifyKey -> Ptr Word8 -> CSize -> IO Int32
foreign import ccall unsafe "&eddsa_public_free" freeVerifyKey :: FunPtr (Ptr VerifyKey -> IO ())
foreign import ccall unsafe "eddsa_public_to_bytes" toBytesVerifyKey :: Ptr VerifyKey -> Ptr CSize -> IO (Ptr Word8)
Expand Down Expand Up @@ -122,15 +122,14 @@ newKeyPair = do
let verifyKey = deriveVerifyKey signKey
return (signKey, verifyKey)

sign :: SignKey -> VerifyKey -> ByteString -> BSS.ShortByteString
sign signKey verifyKey m = unsafePerformIO $
sign :: SignKey -> ByteString -> BSS.ShortByteString
sign signKey m = unsafePerformIO $
withSignKey signKey $ \signKeyPtr ->
withVerifyKey verifyKey $ \verifyKeyPtr ->
BS.unsafeUseAsCStringLen m $ \(m', mlen) -> do
-- this use of unsafe is fine because the sign function
-- checks the length before dereferencing the data pointer
((), s) <- withAllocatedShortByteString signatureSize $ signFFI (castPtr m') (fromIntegral mlen) signKeyPtr verifyKeyPtr
return s
BS.unsafeUseAsCStringLen m $ \(m', mlen) -> do
-- this use of unsafe is fine because the sign function
-- checks the length before dereferencing the data pointer
((), s) <- withAllocatedShortByteString signatureSize $ signFFI (castPtr m') (fromIntegral mlen) signKeyPtr
return s

verify :: VerifyKey -> ByteString -> BSS.ShortByteString -> Bool
verify vf m sig = (BSS.length sig == signatureSize) && (suc > 0)
Expand Down
2 changes: 1 addition & 1 deletion haskell-src/Concordium/Crypto/SignatureScheme.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ toScheme n
| otherwise = Nothing

sign :: KeyPair -> ByteString -> Signature
sign KeyPairEd25519{..} = Signature . Ed25519.sign signKey verifyKey
sign KeyPairEd25519{..} = Signature . Ed25519.sign signKey

verify :: VerifyKey -> ByteString -> Signature -> Bool
verify (VerifyKeyEd25519 vfKey) bs (Signature s) = Ed25519.verify vfKey bs s
Expand Down
Loading

0 comments on commit a73ba79

Please sign in to comment.