bip39 updates + tweaks
This commit is contained in:
@@ -35,6 +35,8 @@
|
|||||||
|
|
||||||
#if USE_BIP39_CACHE
|
#if USE_BIP39_CACHE
|
||||||
|
|
||||||
|
int BIP39_WORDS = 2048;
|
||||||
|
|
||||||
static int bip39_cache_index = 0;
|
static int bip39_cache_index = 0;
|
||||||
|
|
||||||
static CONFIDENTIAL struct {
|
static CONFIDENTIAL struct {
|
||||||
|
|||||||
@@ -24,13 +24,11 @@
|
|||||||
#ifndef __BIP39_H__
|
#ifndef __BIP39_H__
|
||||||
#define __BIP39_H__
|
#define __BIP39_H__
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define BIP39_WORDS 2048
|
|
||||||
#define BIP39_PBKDF2_ROUNDS 2048
|
#define BIP39_PBKDF2_ROUNDS 2048
|
||||||
|
|
||||||
const char *mnemonic_generate(int strength); // strength in bits
|
const char *mnemonic_generate(int strength); // strength in bits
|
||||||
const char *mnemonic_from_data(const uint8_t *data, int len);
|
const char *mnemonic_from_data(const uint8_t *data, int len);
|
||||||
void mnemonic_clear(void);
|
void mnemonic_clear(void);
|
||||||
|
|
||||||
@@ -39,14 +37,8 @@ int mnemonic_check(const char *mnemonic);
|
|||||||
int mnemonic_to_entropy(const char *mnemonic, uint8_t *entropy);
|
int mnemonic_to_entropy(const char *mnemonic, uint8_t *entropy);
|
||||||
|
|
||||||
// passphrase must be at most 256 characters otherwise it would be truncated
|
// passphrase must be at most 256 characters otherwise it would be truncated
|
||||||
void mnemonic_to_seed(const char *mnemonic, const char *passphrase,
|
void mnemonic_to_seed(const char *mnemonic, const char *passphrase, uint8_t seed[512 / 8], void (*progress_callback)(uint32_t current, uint32_t total));
|
||||||
uint8_t seed[512 / 8],
|
|
||||||
void (*progress_callback)(uint32_t current,
|
|
||||||
uint32_t total));
|
|
||||||
|
|
||||||
int mnemonic_find_word(const char *word);
|
const char * const *mnemonic_wordlist(void);
|
||||||
const char *mnemonic_complete_word(const char *prefix, int len);
|
|
||||||
const char *mnemonic_get_word(int index);
|
|
||||||
uint32_t mnemonic_word_completion_mask(const char *prefix, int len);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -28,33 +28,25 @@
|
|||||||
#include "sha2.h"
|
#include "sha2.h"
|
||||||
|
|
||||||
typedef struct _HMAC_SHA256_CTX {
|
typedef struct _HMAC_SHA256_CTX {
|
||||||
uint8_t o_key_pad[SHA256_BLOCK_LENGTH];
|
uint8_t o_key_pad[SHA256_BLOCK_LENGTH];
|
||||||
SHA256_CTX ctx;
|
SHA256_CTX ctx;
|
||||||
} HMAC_SHA256_CTX;
|
} HMAC_SHA256_CTX;
|
||||||
|
|
||||||
typedef struct _HMAC_SHA512_CTX {
|
typedef struct _HMAC_SHA512_CTX {
|
||||||
uint8_t o_key_pad[SHA512_BLOCK_LENGTH];
|
uint8_t o_key_pad[SHA512_BLOCK_LENGTH];
|
||||||
SHA512_CTX ctx;
|
SHA512_CTX ctx;
|
||||||
} HMAC_SHA512_CTX;
|
} HMAC_SHA512_CTX;
|
||||||
|
|
||||||
void hmac_sha256_Init(HMAC_SHA256_CTX *hctx, const uint8_t *key,
|
void hmac_sha256_Init(HMAC_SHA256_CTX *hctx, const uint8_t *key, const uint32_t keylen);
|
||||||
const uint32_t keylen);
|
void hmac_sha256_Update(HMAC_SHA256_CTX *hctx, const uint8_t *msg, const uint32_t msglen);
|
||||||
void hmac_sha256_Update(HMAC_SHA256_CTX *hctx, const uint8_t *msg,
|
|
||||||
const uint32_t msglen);
|
|
||||||
void hmac_sha256_Final(HMAC_SHA256_CTX *hctx, uint8_t *hmac);
|
void hmac_sha256_Final(HMAC_SHA256_CTX *hctx, uint8_t *hmac);
|
||||||
void hmac_sha256(const uint8_t *key, const uint32_t keylen, const uint8_t *msg,
|
void hmac_sha256(const uint8_t *key, const uint32_t keylen, const uint8_t *msg, const uint32_t msglen, uint8_t *hmac);
|
||||||
const uint32_t msglen, uint8_t *hmac);
|
void hmac_sha256_prepare(const uint8_t *key, const uint32_t keylen, uint32_t *opad_digest, uint32_t *ipad_digest);
|
||||||
void hmac_sha256_prepare(const uint8_t *key, const uint32_t keylen,
|
|
||||||
uint32_t *opad_digest, uint32_t *ipad_digest);
|
|
||||||
|
|
||||||
void hmac_sha512_Init(HMAC_SHA512_CTX *hctx, const uint8_t *key,
|
void hmac_sha512_Init(HMAC_SHA512_CTX *hctx, const uint8_t *key, const uint32_t keylen);
|
||||||
const uint32_t keylen);
|
void hmac_sha512_Update(HMAC_SHA512_CTX *hctx, const uint8_t *msg, const uint32_t msglen);
|
||||||
void hmac_sha512_Update(HMAC_SHA512_CTX *hctx, const uint8_t *msg,
|
|
||||||
const uint32_t msglen);
|
|
||||||
void hmac_sha512_Final(HMAC_SHA512_CTX *hctx, uint8_t *hmac);
|
void hmac_sha512_Final(HMAC_SHA512_CTX *hctx, uint8_t *hmac);
|
||||||
void hmac_sha512(const uint8_t *key, const uint32_t keylen, const uint8_t *msg,
|
void hmac_sha512(const uint8_t *key, const uint32_t keylen, const uint8_t *msg, const uint32_t msglen, uint8_t *hmac);
|
||||||
const uint32_t msglen, uint8_t *hmac);
|
void hmac_sha512_prepare(const uint8_t *key, const uint32_t keylen, uint64_t *opad_digest, uint64_t *ipad_digest);
|
||||||
void hmac_sha512_prepare(const uint8_t *key, const uint32_t keylen,
|
|
||||||
uint64_t *opad_digest, uint64_t *ipad_digest);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
void memzero(void* const pnt, const size_t len);
|
void memzero(void * const pnt, const size_t len);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
|
|
||||||
// support constructing BIP32 nodes from ed25519 and curve25519 curves.
|
// support constructing BIP32 nodes from ed25519 and curve25519 curves.
|
||||||
#ifndef USE_BIP32_25519_CURVES
|
#ifndef USE_BIP32_25519_CURVES
|
||||||
#define USE_BIP32_25519_CURVES 1
|
#define USE_BIP32_25519_CURVES 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// implement BIP39 caching
|
// implement BIP39 caching
|
||||||
|
|||||||
@@ -28,39 +28,29 @@
|
|||||||
#include "sha2.h"
|
#include "sha2.h"
|
||||||
|
|
||||||
typedef struct _PBKDF2_HMAC_SHA256_CTX {
|
typedef struct _PBKDF2_HMAC_SHA256_CTX {
|
||||||
uint32_t odig[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
|
uint32_t odig[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
|
||||||
uint32_t idig[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
|
uint32_t idig[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
|
||||||
uint32_t f[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
|
uint32_t f[SHA256_DIGEST_LENGTH / sizeof(uint32_t)];
|
||||||
uint32_t g[SHA256_BLOCK_LENGTH / sizeof(uint32_t)];
|
uint32_t g[SHA256_BLOCK_LENGTH / sizeof(uint32_t)];
|
||||||
char first;
|
char first;
|
||||||
} PBKDF2_HMAC_SHA256_CTX;
|
} PBKDF2_HMAC_SHA256_CTX;
|
||||||
|
|
||||||
typedef struct _PBKDF2_HMAC_SHA512_CTX {
|
typedef struct _PBKDF2_HMAC_SHA512_CTX {
|
||||||
uint64_t odig[SHA512_DIGEST_LENGTH / sizeof(uint64_t)];
|
uint64_t odig[SHA512_DIGEST_LENGTH / sizeof(uint64_t)];
|
||||||
uint64_t idig[SHA512_DIGEST_LENGTH / sizeof(uint64_t)];
|
uint64_t idig[SHA512_DIGEST_LENGTH / sizeof(uint64_t)];
|
||||||
uint64_t f[SHA512_DIGEST_LENGTH / sizeof(uint64_t)];
|
uint64_t f[SHA512_DIGEST_LENGTH / sizeof(uint64_t)];
|
||||||
uint64_t g[SHA512_BLOCK_LENGTH / sizeof(uint64_t)];
|
uint64_t g[SHA512_BLOCK_LENGTH / sizeof(uint64_t)];
|
||||||
char first;
|
char first;
|
||||||
} PBKDF2_HMAC_SHA512_CTX;
|
} PBKDF2_HMAC_SHA512_CTX;
|
||||||
|
|
||||||
void pbkdf2_hmac_sha256_Init(PBKDF2_HMAC_SHA256_CTX *pctx, const uint8_t *pass,
|
void pbkdf2_hmac_sha256_Init(PBKDF2_HMAC_SHA256_CTX *pctx, const uint8_t *pass, int passlen, const uint8_t *salt, int saltlen, uint32_t blocknr);
|
||||||
int passlen, const uint8_t *salt, int saltlen,
|
void pbkdf2_hmac_sha256_Update(PBKDF2_HMAC_SHA256_CTX *pctx, uint32_t iterations);
|
||||||
uint32_t blocknr);
|
|
||||||
void pbkdf2_hmac_sha256_Update(PBKDF2_HMAC_SHA256_CTX *pctx,
|
|
||||||
uint32_t iterations);
|
|
||||||
void pbkdf2_hmac_sha256_Final(PBKDF2_HMAC_SHA256_CTX *pctx, uint8_t *key);
|
void pbkdf2_hmac_sha256_Final(PBKDF2_HMAC_SHA256_CTX *pctx, uint8_t *key);
|
||||||
void pbkdf2_hmac_sha256(const uint8_t *pass, int passlen, const uint8_t *salt,
|
void pbkdf2_hmac_sha256(const uint8_t *pass, int passlen, const uint8_t *salt, int saltlen, uint32_t iterations, uint8_t *key, int keylen);
|
||||||
int saltlen, uint32_t iterations, uint8_t *key,
|
|
||||||
int keylen);
|
|
||||||
|
|
||||||
void pbkdf2_hmac_sha512_Init(PBKDF2_HMAC_SHA512_CTX *pctx, const uint8_t *pass,
|
void pbkdf2_hmac_sha512_Init(PBKDF2_HMAC_SHA512_CTX *pctx, const uint8_t *pass, int passlen, const uint8_t *salt, int saltlen, uint32_t blocknr);
|
||||||
int passlen, const uint8_t *salt, int saltlen,
|
void pbkdf2_hmac_sha512_Update(PBKDF2_HMAC_SHA512_CTX *pctx, uint32_t iterations);
|
||||||
uint32_t blocknr);
|
|
||||||
void pbkdf2_hmac_sha512_Update(PBKDF2_HMAC_SHA512_CTX *pctx,
|
|
||||||
uint32_t iterations);
|
|
||||||
void pbkdf2_hmac_sha512_Final(PBKDF2_HMAC_SHA512_CTX *pctx, uint8_t *key);
|
void pbkdf2_hmac_sha512_Final(PBKDF2_HMAC_SHA512_CTX *pctx, uint8_t *key);
|
||||||
void pbkdf2_hmac_sha512(const uint8_t *pass, int passlen, const uint8_t *salt,
|
void pbkdf2_hmac_sha512(const uint8_t *pass, int passlen, const uint8_t *salt, int saltlen, uint32_t iterations, uint8_t *key, int keylen);
|
||||||
int saltlen, uint32_t iterations, uint8_t *key,
|
|
||||||
int keylen);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user