forked from aido/app-seed-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Stax layouts for generating SSKR shares
- Loading branch information
Showing
13 changed files
with
367 additions
and
191 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include <os.h> | ||
#include <string.h> | ||
|
||
#include "../ux_common/common_sskr.h" | ||
#include "./sskr_shares.h" | ||
#include "./bip39_mnemonic.h" | ||
|
||
#if defined(TARGET_STAX) | ||
|
||
typedef struct sskr_buffer_struct { | ||
// The SSKR shares, built over time | ||
char buffer[SSKR_SHARES_MAX_LENGTH]; | ||
// current length of the shares buffer | ||
unsigned int length; | ||
unsigned int group_descriptor[1][2]; | ||
uint8_t count; | ||
} sskr_buffer_t; | ||
|
||
static sskr_buffer_t shares = {0}; | ||
|
||
void sskr_sharenum_set(const uint8_t sharenum) { | ||
shares.group_descriptor[0][1] = sharenum; | ||
} | ||
|
||
uint8_t sskr_sharenum_get(void) { | ||
return shares.group_descriptor[0][1]; | ||
} | ||
|
||
void sskr_threshold_set(const uint8_t threshold) { | ||
shares.group_descriptor[0][0] = threshold; | ||
} | ||
|
||
uint8_t sskr_threshold_get(void) { | ||
return shares.group_descriptor[0][0]; | ||
} | ||
|
||
uint8_t sskr_sharecount_get(void) { | ||
return shares.count; | ||
} | ||
|
||
void sskr_shares_reset(void) { | ||
memzero(&shares, sizeof(shares)); | ||
} | ||
|
||
void sskr_shares_from_bip39_mnemonic(void) { | ||
|
||
shares.length = 0; | ||
|
||
bolos_ux_bip39_to_sskr_convert((unsigned char*) bip39_mnemonic_get(), | ||
bip39_mnemonic_length_get(), | ||
bip39_mnemonic_final_size_get(), | ||
shares.group_descriptor[0], | ||
&shares.count, | ||
(unsigned char*) shares.buffer, | ||
&shares.length); | ||
|
||
if (shares.count > 0) { | ||
PRINTF("SSKR share count is %d\n", shares.count); | ||
PRINTF("SSKR share buffer length is %d\n", shares.length); | ||
for (uint8_t share = 0; share < shares.count; share++) { | ||
PRINTF("SSKR share %d:\n", share + 1); | ||
PRINTF("%.*s\n", | ||
shares.length / shares.count, | ||
shares.buffer + share * shares.length / shares.count); | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/******************************************************************************* | ||
* (c) 2016-2022 Ledger SAS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
********************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#if defined(TARGET_STAX) | ||
|
||
#define memzero(...) explicit_bzero(__VA_ARGS__) | ||
|
||
// 16 shares * 229 chars per share (46 SSKR ByteWords) | ||
#define SSKR_SHARES_MAX_LENGTH 3664 | ||
|
||
/* | ||
* Sets the number of SSKR shares | ||
*/ | ||
void sskr_sharenum_set(const uint8_t sharenum); | ||
|
||
/* | ||
* Returns the SSKR shares | ||
*/ | ||
uint8_t sskr_sharenum_get(void); | ||
|
||
/* | ||
* Sets the SSKR threshold | ||
*/ | ||
void sskr_threshold_set(const uint8_t threshold); | ||
|
||
/* | ||
* Returns the SSKR threshold | ||
*/ | ||
uint8_t sskr_threshold_get(void); | ||
|
||
/* | ||
* Returns the SSKR share count | ||
*/ | ||
|
||
uint8_t sskr_sharecount_get(void); | ||
|
||
/* | ||
* Erase all information and reset the indexes | ||
*/ | ||
void sskr_shares_reset(void); | ||
|
||
/* | ||
* Generate SSKR shares from BIP39 mnemonic | ||
*/ | ||
void sskr_shares_from_bip39_mnemonic(void); | ||
|
||
#endif // TARGET_STAX |
Oops, something went wrong.