Minimal Iot platform - General - Algorand

Minimal Iot platform

post by noomio on Feb 25, 2021

Hi,

I’m looking into Algorand and the uses in Iot.

The platform that I have is quite limited and can only compile code for C/C++.

In this case, what is the best approach to realise a transaction on a test node?

What are the minimal API’s that I shall need to port?

Thanks

post by JasonW on Feb 25, 2021

There are many c++ libraries that support REST calls. You could just use one of those and call the Algorand specific REST APIs - Algorand Developer Docs

post by fabrice on Feb 25, 2021

You may also want to look at AlgoDuino:

https://algoduino.com/

It’s in C++ for ESP8266 and ESP32, so it may or may not be useful for you.

post by noomio on Feb 25, 2021

Hi,

I had a look at these, thanks.

REST API are ok but what about the lower level stuff such as signing a wallet, generating a mnemonic etc.?

post by fabrice on Feb 25, 2021

For that, you would first need to find a crypto library that supports the required operations (essentially SHA512/256 - not just SHA256 -, and ED25519 signatures).

The official code ( GitHub - algorand/go-algorand: Algorand's official implementation in Go.) uses libsodium.

To see how accounts are generated, you can pick the SDK of your choice and look at the code.

If libsodium is too large, you may consider using TweetNACL ( TweetNaCl: Software) / uNACL ( μNaCl – FAQ) for ED25519 operations.

I don’t know a good very small library for SHA512/256 however.

post by noomio on Feb 25, 2021

Ok, great.

I have used this one in the past:

https://tls.mbed.org/api/modules.html

https://tls.mbed.org/api/annotated.html

Looks like it covers them.

I have also ported duktape - Javascript Engine so I could make a port for JavaScript. Hopefully I can contribute it to the community.

post by fabrice on Feb 25, 2021

I’m not sure they support SHA-512/256.

SHA-512/256 is SHA-512 with a difference initialization vector and truncated to 256 bits.

It might not be too difficult to tweak the code of SHA-512 to get SHA-512/256

You don’t need SHA-512/256 for normal signing/key generation.

But you need it to:

post by noomio on Feb 25, 2021

Ok, thanks for the clarification.

I will search a bit more on the SHA-512/256 and try and find something suitable.

post by noomio on Feb 27, 2021

Hi,

So far I have created a library for TweetNacl and used parts of the sodium lib for sha512/256.

From sodium: crypto_hash,crypto_auth, crypto_verify and created a customised random.

That should be enough for now right?

Nikolas

post by fabrice on Feb 28, 2021

If you want to be able to send transaction, you’ll also need crypto_sign.

Regarding randomness generation, this is usually a very complex operation especially on IoT.

One issue is that it’s almost impossible to test it is done properly and errors can be catastrophic (see e.g., Debian -- Security Information -- DSA-1571-1 openssl).

What source of randomness and algorithms for randomness generation are you using?

Just for the purpose of people stumbling on this post, I want to stress that rand from stdlib.h is completely insecure and should never be used for randomness generation for crypto-related operations.

post by noomio on Feb 28, 2021

Thanks for following up.

I was planning to use a hardware random generator but it seems that it’s not exposed on the ARMv7 platform (need to ask R&D that work with Qualcomm).

I’m thinking of using other physical sources such as RF front end etc. to create random generation as a source. Need to look into it a bit further.

I’m using the randombytes_internal_random_buf that uses chacha20.

The code is the same I use I just need to provide a hardware source of random generation by randombytes_getentropy.

post by noomio on Feb 28, 2021

Ok, so there is an API that exposes the hardware random number generator.

I’m good to go

post by jannotti on Mar 1, 2021

This is a first cut at a c++ sdk that does signing and such. Still very untested.

post by noomio on Mar 1, 2021

Thanks.

I shall have a look at it.

I’m starting to look into this now as the crypto stuff has been sorted.

What platform is this for - Linux?

post by jannotti on Mar 3, 2021

Developed on a Mac and periodically confirm compatibility with Linux.

I haven’t done multisig yet, and only a few indexer apis. But everything else should work.