I need to implement cryptographic algorithms such as AESCCM and elliptic curve algorithms (ECDSA, ECIES) within a smart contract. Is there any implementation of such algorithms in Solidity or Serpent?

Or is there is any way to integrate Python code (or other language) within Serpent for example (there many cryptographic libraries in Python)?

Or any other suggestions on how can I implement those algorithms?

  • 2
    If this is a private chain, consider forking pyethereum and adding your own "precompiled contracts": see github.com/ethereum/pyethereum/blob/develop/ethereum/….
    – eth
    Commented Feb 13, 2017 at 20:16
  • thank you for your reply, I'm new in Ethereum and smart contracts. Can you explain your reply please. Thank you
    – Dissou
    Commented Feb 14, 2017 at 8:15
  • I am also working on something similar. Did you get it to work? Commented Oct 16, 2017 at 20:38

2 Answers 2


This library is a good starting point: https://github.com/HarryR/solcrypto

As Richard points out symmetric key crypto and private key operation are rarely sensible in a smart contract as the smart contract has no privacy. However public key operations like checking signatures, proofs and hashes can be very useful and got more efficient with the addition of the elliptic curve precompiled contracts in Byzantium.


Remember that anything done inside a smart contract has to be paid for with gas: computational expense equates to gas expense. Even if high gas costs aren't a deterrent, there's still a per-block gas limit that would need to be considered. (I don't know much about implementing crypto alogorithms, but I checked the OpenSSL C implementation of ECDSA, and it's hundreds of lines long... )

Also, as previous threads have mentioned, signing anything inside a smart contract would necessarily expose the private keys, which presumably isn't what you want. A better option would be to perform the meat of the crypto outside the contract, and send the resulting hashes to it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.