Introducing libcrypton: easy-to-use Neo cryptography for developers

Igor Machado
NeoResearch
Published in
3 min readAug 28, 2019

In this month, NeoResearch Community introduced a new powerful tool for blockchain developers: the libcrypton. Written in C++, this library embeds all necessary cryptographic technologies from Neo blockchain in a very portable format, intended for usage in high-performance systems (via openssl engine), but also microcontrollers and low-energy devices (via arduino packages). A detailed library description (and build information) is presented on https://github.com/neoresearch/libcrypton

libcrypton webpage on github

Another useful tool in this package is the crypdev command-line utility. Using crypdev, one can easily automate tasks such as generating public keys on linux bash scripts, and signing/verifying payloads using Neo blockchain cryptography (elliptic curve NIST P-256 / secp256r1). It also integrates to common cryptographic hash functions, such as SHA-256, RIPEMD160, and it is intended to add “extra” features for the future, including experimental hash functions and new cryptography, to push further developments on Neo. We intend to add support to other engines as well, such as the Crypto++ library by Wei Dai, and the libressl (as alternative to openssl).

Some examples of the crypdev command-line (executing help command):

crypdev help command (pre-release v0.4)

Let’s generate a keypair (private/public keys) using secp256r1 elliptic curve:

crypdev gen keypair command (pre-release v0.4)

If you already had a private key, you could easily generate the respective public key (in compressed format):

crypdev gen pubkey command (pre-release v0.4)

To play with hashes is also quite simple (let’s hash “Hello World” with SHA-256):

crypdev hash sha256 (“Hello World”) command (pre-release v0.4)

Hashes can also be directly applied to a hexstring (or bytearray):

crypdev hash sha256 (0x010203) command (pre-release v0.4)

Many useful features can be used, such as counting bytes and reversing a hexstring:

crypdev bytes reverse and count commands (pre-release v0.4)

Note that everything can also be done directly from command-line, or reading from a script file (no interactive mode is necessary). Available parameters are (pre-release v0.4):

crypdev -c : passes command list directly as string (separated by semi-commas)

crypdev -f: passes a script file as parameter

crypdev -i : runs in interactive mode (default even without option -i)

crypdev -v: displays libcrypton version

Example: ./bin/crypdev -c “rand 10 ; bytes reverse 0x010203”
5b0bd646ab2d62a5f9b2
030201

In this example, 10 bytes were randomly generated, and second command reversed byte array sequence 0x010203 into 030201. So, the same thing applies to hashing and elliptic curves, which is very good to quickly create and test other tools and libraries.

The final example is to sign a “Hello World” payload, and verify that it’s correct (using secp256r1 ecc):

crypdev sign and verify using secp256r1 ecc and sha256 over message “Hello World” (pre-release v0.4)

Finally, this is currently published only via via make system (see README for build instructions), which is already usable in linux/windows/mac platforms. Anyway, due to the difficulties of easily packaging for cross OS in C++, we intend to make this process easier by adopting Cmake and other established build systems. This library is part of NeoPT (Neo Portable) macro project https://github.com/neoresearch/neopt, together with: csbiginteger, NeoVM++, and libbft.

--

--