Last active
June 27, 2019 02:01
-
-
Save baymac/6b1aab4f7762d4d80413739919090985 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<ssss.h> | |
#include<Entropy.h> | |
#include <gf256.h> // Not Used | |
FamilyId id = {5, 2}; | |
Ssss s; | |
void setup() { | |
Serial.begin(9600); | |
Entropy.initialize(); | |
uint8_t privateKey[30] = | |
{224, 181, 214, 219, 12, 53, 89, 154, 24, 137, 252, 189, 224, 203, 126, 98, 76, 163, 46, 126, 149, 108, 18, 109, 239, 225, 130, 7, 52, 212}; | |
uint8_t *share1=NULL; | |
uint8_t *share2=NULL; | |
uint8_t *share3=NULL; | |
uint8_t *share4=NULL; | |
uint8_t *share5=NULL; | |
// Shuffle Mode | |
s.LoadState(); | |
s.setFamily(27); // unique family id | |
s.setThreshold(2); // min number of shares required | |
s.setPayload(30); | |
s.beginShuffle(); | |
bool entropyMax = false; | |
while(!entropyMax) { | |
entropyMax = s.addEntropy(Entropy.randomByte()); // provide sufficient entropy | |
} | |
s.addSecret(privateKey); | |
// Deal Mode | |
s.beginDeal(); // begin deal mode | |
// Each share has 2 extra bytes as it has 2 extra metadata -> `family id` & `threshold` | |
uint8_t buffer[32]; // Using buffer to get shares | |
s.dealNextShare(buffer); | |
share1 = buffer; | |
Serial.print("Share 1: {"); | |
for(int i = 0; i < 32; i++) { | |
Serial.print(share1[i]); | |
Serial.print(", "); | |
} | |
Serial.println("}"); | |
s.dealNextShare(buffer); | |
share2 = buffer; | |
Serial.print("Share 2: {"); | |
for(int i = 0; i < 32; i++) { | |
Serial.print(share2[i]); | |
Serial.print(", "); | |
} | |
Serial.println("}"); | |
s.dealNextShare(buffer); | |
share3 = buffer; | |
Serial.print("Share 3: {"); | |
for(int i = 0; i < 32; i++) { | |
Serial.print(share3[i]); | |
Serial.print(", "); | |
} | |
Serial.println("}"); | |
s.dealNextShare(buffer); | |
share4 = buffer; | |
Serial.print("Share 4: {"); | |
for(int i = 0; i < 32; i++) { | |
Serial.print(share4[i]); | |
Serial.print(", "); | |
} | |
Serial.println("}"); | |
s.dealNextShare(buffer); | |
share5 = buffer; | |
Serial.print("Share 5: {"); | |
for(int i = 0; i < 32; i++) { | |
Serial.print(share5[i]); | |
Serial.print(", "); | |
} | |
Serial.println("}"); | |
Serial.print("\nNumber of Shares Dealt: "); | |
Serial.println(s.getShares()); // to get number of shares | |
s.clear(); // writes sensitive bytes with 0s and sets device in NoMode | |
// Collect Mode | |
s.setSharePayloadLength(32); | |
s.beginCollect(); | |
s.addShare(share1); | |
s.addShare(share2); | |
s.addShare(share3); | |
s.addShare(share4); | |
s.addShare(share5); | |
// Serial.println(s.secretAvailable()); | |
// Reveal Mode | |
s.beginReveal(); | |
s.getSecret(buffer); | |
Serial.print("\n\nSecret : {"); | |
for(int i = 0; i < 30; i++) { | |
Serial.print(buffer[i]); | |
Serial.print(", "); | |
} | |
Serial.println("}"); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment