-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch from cryptonite library to crypton and fix cbits #95
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
#include <cryptonite_sha512.h> | ||
#include <crypton_sha512.h> | ||
typedef struct sha512_ctx ed25519_hash_context; | ||
|
||
static void | ||
ed25519_hash_init(ed25519_hash_context *ctx) { | ||
cryptonite_sha512_init(ctx); | ||
crypton_sha512_init(ctx); | ||
} | ||
|
||
static void | ||
ed25519_hash_update(ed25519_hash_context *ctx, const uint8_t *in, size_t inlen) { | ||
cryptonite_sha512_update(ctx, in, inlen); | ||
crypton_sha512_update(ctx, in, inlen); | ||
} | ||
|
||
static void | ||
ed25519_hash_final(ed25519_hash_context *ctx, uint8_t *hash) { | ||
cryptonite_sha512_finalize(ctx, hash); | ||
crypton_sha512_finalize(ctx, hash); | ||
} | ||
|
||
static void | ||
ed25519_hash(uint8_t *hash, const uint8_t *in, size_t inlen) { | ||
ed25519_hash_context ctx; | ||
cryptonite_sha512_init(&ctx); | ||
cryptonite_sha512_update(&ctx, in, inlen); | ||
cryptonite_sha512_finalize(&ctx, hash); | ||
crypton_sha512_init(&ctx); | ||
crypton_sha512_update(&ctx, in, inlen); | ||
crypton_sha512_finalize(&ctx, hash); | ||
memset(&ctx, 0, sizeof(ctx)); | ||
} |
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 |
---|---|---|
|
@@ -5,12 +5,12 @@ | |
#include <ed25519.h> | ||
#include <hmac.h> | ||
|
||
#include "cryptonite_pbkdf2.h" | ||
#include "crypton_pbkdf2.h" | ||
|
||
typedef uint8_t cryptonite_chacha_context[131]; | ||
typedef uint8_t crypton_chacha_context[131]; | ||
|
||
extern void cryptonite_chacha_init(cryptonite_chacha_context *ctx, uint8_t nb_rounds, uint32_t keylen, const uint8_t *key, uint32_t ivlen, const uint8_t *iv); | ||
extern void cryptonite_chacha_combine(uint8_t *dst, cryptonite_chacha_context *st, const uint8_t *src, uint32_t bytes); | ||
extern void crypton_chacha_init(crypton_chacha_context *ctx, uint8_t nb_rounds, uint32_t keylen, const uint8_t *key, uint32_t ivlen, const uint8_t *iv); | ||
extern void crypton_chacha_combine(uint8_t *dst, crypton_chacha_context *st, const uint8_t *src, uint32_t bytes); | ||
|
||
void clear(void *buf, uint32_t const sz) | ||
{ | ||
|
@@ -25,7 +25,7 @@ void stretch(uint8_t *buf, uint32_t const buf_len, uint8_t const *pass, uint32_t | |
{ | ||
const uint8_t salt[] = "encrypted wallet salt"; | ||
assert(pass_len > 0); | ||
cryptonite_fastpbkdf2_hmac_sha512(pass, pass_len, salt, sizeof(salt), NB_ITERATIONS, buf, buf_len); | ||
crypton_fastpbkdf2_hmac_sha512(pass, pass_len, salt, sizeof(salt), NB_ITERATIONS, buf, buf_len); | ||
} | ||
|
||
#define SYM_KEY_SIZE 32 | ||
|
@@ -53,18 +53,18 @@ typedef struct { | |
static void memory_combine(uint8_t const *pass, uint32_t const pass_len, uint8_t const *source, uint8_t *dest, uint32_t sz) | ||
{ | ||
uint8_t buf[SYM_BUF_SIZE]; | ||
cryptonite_chacha_context ctx; | ||
crypton_chacha_context ctx; | ||
static uint8_t const CHACHA_NB_ROUNDS = 20; | ||
|
||
if (pass_len) { | ||
memset(&ctx, 0, sizeof(cryptonite_chacha_context)); | ||
memset(&ctx, 0, sizeof(crypton_chacha_context)); | ||
|
||
/* generate BUF_SIZE bytes where first KEY_SIZE bytes is the key and NONCE_SIZE remaining bytes the nonce */ | ||
stretch(buf, SYM_BUF_SIZE, pass, pass_len); | ||
cryptonite_chacha_init(&ctx, CHACHA_NB_ROUNDS, SYM_KEY_SIZE, buf, SYM_NONCE_SIZE, buf + SYM_KEY_SIZE); | ||
crypton_chacha_init(&ctx, CHACHA_NB_ROUNDS, SYM_KEY_SIZE, buf, SYM_NONCE_SIZE, buf + SYM_KEY_SIZE); | ||
clear(buf, SYM_BUF_SIZE); | ||
cryptonite_chacha_combine(dest, &ctx, source, sz); | ||
clear(&ctx, sizeof(cryptonite_chacha_context)); | ||
crypton_chacha_combine(dest, &ctx, source, sz); | ||
clear(&ctx, sizeof(crypton_chacha_context)); | ||
} else { | ||
memcpy(dest, source, sz); | ||
} | ||
|
@@ -158,9 +158,9 @@ DECL_HMAC(sha512, | |
SHA512_BLOCK_SIZE, | ||
SHA512_DIGEST_SIZE, | ||
struct sha512_ctx, | ||
cryptonite_sha512_init, | ||
cryptonite_sha512_update, | ||
cryptonite_sha512_finalize); | ||
crypton_sha512_init, | ||
crypton_sha512_update, | ||
crypton_sha512_finalize); | ||
|
||
typedef enum { | ||
DERIVATION_V1 = 1, | ||
|
@@ -253,9 +253,9 @@ static void serialize_index32(uint8_t *out, uint32_t index, derivation_scheme_mo | |
|
||
static void add_left(ed25519_secret_key res_key, uint8_t *z, ed25519_secret_key priv_key, derivation_scheme_mode mode) | ||
{ | ||
uint8_t zl8[32]; | ||
ed25519_secret_key zl8; | ||
|
||
memset(zl8, 0, 32); | ||
memset(zl8, 0, 64); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the size of the |
||
switch (mode) { | ||
case DERIVATION_V1: | ||
/* get 8 * Zl */ | ||
|
@@ -287,10 +287,10 @@ static void add_right(ed25519_secret_key res_key, uint8_t *z, ed25519_secret_key | |
|
||
static void add_left_public(uint8_t *out, uint8_t *z, uint8_t *in, derivation_scheme_mode mode) | ||
{ | ||
uint8_t zl8[32]; | ||
ed25519_secret_key zl8; | ||
ed25519_public_key pub_zl8; | ||
|
||
memset(zl8, 0, 32); | ||
memset(zl8, 0, 64); | ||
switch (mode) { | ||
case DERIVATION_V1: | ||
multiply8_v1(zl8, z, 32); | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
unit8_t
array had32
elements (which is what caused the error message) and is replace withed25519_secret_key
which is 64 elements.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before the fix, the error was: