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
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):
Let’s generate a keypair (private/public keys) using secp256r1 elliptic curve:
If you already had a private key, you could easily generate the respective public key (in compressed format):
To play with hashes is also quite simple (let’s hash “Hello World” with SHA-256):
Hashes can also be directly applied to a hexstring (or bytearray):
Many useful features can be used, such as counting bytes and reversing a hexstring:
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”
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):
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.