Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
433744c
Revert unnecessary formatting from 815a7fa
lehins Jun 29, 2026
bde6d37
Revert "cardano-crypto-wallet: rename ed25519 C symbols from cardano_…
lehins Jun 29, 2026
1d26f3b
Add the odd `output` file to gitignore
lehins May 30, 2026
d0611b6
Introduce `SecretKey`
lehins May 30, 2026
89fd899
Make `PublicKey` into a `newtype`
lehins May 30, 2026
4c3af11
Introduce `withDecryptedKeyMaterial`
lehins May 31, 2026
b363718
Introduce proper scoping in `withEncryptedKeyOutput`
lehins May 31, 2026
d4ff41a
Introduce `Validity` parameter to `KeyMaterial`
lehins May 31, 2026
dd2efa7
Improve `EncryptedKey` type safety
lehins May 31, 2026
3882867
Make `ChainCode` into a `newtype`
lehins May 31, 2026
42a9765
Improve scoping of `decryptKeyMaterialV2`
lehins May 31, 2026
b34220a
Rename "Encrypted" -> "Secret/Unencrypted"
lehins May 31, 2026
9670918
Simplify validation of `KeyMaterial`
lehins May 31, 2026
96635ea
Introduce `KeyMaterialBuffer`
lehins May 31, 2026
835dbec
Avoid unnecessarily allocating `CKeyMaterialBuffer`
lehins May 31, 2026
e99165b
Remove confusing `encrypted_` suffix
lehins May 31, 2026
73c29c8
Remove redundant `legacyKeySize`
lehins May 31, 2026
bc26f2a
More type safety for `Nonce` and `Salt`
lehins May 31, 2026
5f234c7
More type safety for `Tag`
lehins May 31, 2026
b43461d
WIP rename plaintext to secret_key
lehins May 31, 2026
3af6efe
Rename Ciphertext to EncSecretKey
lehins May 31, 2026
182349a
Remove another redundant argument to decrypt C function
lehins May 31, 2026
9ef6935
Introduce `WrappingKey` and remove redundant parameters
lehins May 31, 2026
641e27d
Rename `Envelope` and other minor cleanup
lehins May 31, 2026
1e7072f
Expose safe parts of the `Envelope`
lehins Jun 1, 2026
f90e278
Consistent and unique naming for C functions and FFI
lehins Jun 4, 2026
d776a49
Switch to using consistent `CCW` definition everywhere
lehins Jun 4, 2026
7c85e5f
Ensure more bytes than necessary is not copied over.
lehins Jun 4, 2026
e0aa2e3
Stop writing zeros into memory that is guaranteed to be overwritten
lehins Jun 4, 2026
7a24990
Ensure sizes match up
lehins Jun 4, 2026
76d59c3
Add lower bound on libsodium due to argon2id
lehins Jul 4, 2026
0763e4f
Reduce duplication in the test suite
lehins Jul 4, 2026
8d6931f
Remove duplicate data from the `Envelope`
lehins Jul 4, 2026
ed17cfe
f
lehins Jul 4, 2026
c6ef882
Expose `decodeEncryptedKey`
lehins Jul 4, 2026
19f6bf6
Introduce a roundtrip test for the test `Envelope`
lehins Jul 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ stack-local.yaml

# Test artefacts
/result-*
cardano-crypto-wallet/output
cardano-crypto-class/output
cardano-crypto-praos/output

Expand Down
2 changes: 1 addition & 1 deletion cardano-crypto-wallet/bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ main = do
, bench "sign-v2 (encryptedSign)" $
whnfIO (encryptedSign key testPass testMsg)
, bench "change-passphrase (encryptedChangePass)" $
whnfIO (encryptedChangePass testPass newPass key)
whnfIO (encryptedChangePassphrase testPass newPass key)
]
8 changes: 7 additions & 1 deletion cardano-crypto-wallet/cardano-crypto-wallet.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@ library
Cardano.Crypto.WalletHD.Encrypted

build-depends:
FailT,
bytestring,
cardano-binary,
cardano-crypto-class,
cborg,
deepseq,
memory,

pkgconfig-depends: libsodium
pkgconfig-depends:
libsodium >=1.0.13

c-sources:
cbits/ed25519/ed25519.c
cbits/encrypted_sign.c
Expand Down Expand Up @@ -91,6 +95,8 @@ test-suite tests
-with-rtsopts=-N

build-depends:
FailT,
HUnit,
QuickCheck,
bytestring,
cardano-crypto-class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ ge25519_is_neutral_vartime(const ge25519 *p) {
}

int
ED25519_FN(ed25519_sign_open_batch) (const unsigned char **m, size_t *mlen, const unsigned char **pk, const unsigned char **RS, size_t num, int *valid) {
CCW_FN(ed25519_sign_open_batch) (const unsigned char **m, size_t *mlen, const unsigned char **pk, const unsigned char **RS, size_t num, int *valid) {
batch_heap ALIGN(16) batch;
ge25519 ALIGN(16) p;
bignum256modm *r_scalars;
Expand All @@ -217,7 +217,7 @@ ED25519_FN(ed25519_sign_open_batch) (const unsigned char **m, size_t *mlen, cons
batchsize = (num > max_batch_size) ? max_batch_size : num;

/* generate r (scalars[batchsize+1]..scalars[2*batchsize] */
ED25519_FN(ed25519_randombytes_unsafe) (batch.r, batchsize * 16);
CCW_FN(ed25519_randombytes_unsafe) (batch.r, batchsize * 16);
r_scalars = &batch.scalars[batchsize + 1];
for (i = 0; i < batchsize; i++)
expand256_modm(r_scalars[i], batch.r[i], 16);
Expand Down Expand Up @@ -252,7 +252,7 @@ ED25519_FN(ed25519_sign_open_batch) (const unsigned char **m, size_t *mlen, cons

fallback:
for (i = 0; i < batchsize; i++) {
valid[i] = ED25519_FN(ed25519_sign_open) (m[i], mlen[i], pk[i], RS[i]) ? 0 : 1;
valid[i] = CCW_FN(ed25519_sign_open) (m[i], mlen[i], pk[i], RS[i]) ? 0 : 1;
ret |= (valid[i] ^ 1);
}
}
Expand All @@ -266,7 +266,7 @@ ED25519_FN(ed25519_sign_open_batch) (const unsigned char **m, size_t *mlen, cons
}

for (i = 0; i < num; i++) {
valid[i] = ED25519_FN(ed25519_sign_open) (m[i], mlen[i], pk[i], RS[i]) ? 0 : 1;
valid[i] = CCW_FN(ed25519_sign_open) (m[i], mlen[i], pk[i], RS[i]) ? 0 : 1;
ret |= (valid[i] ^ 1);
}

Expand Down
2 changes: 1 addition & 1 deletion cardano-crypto-wallet/cbits/ed25519/ed25519-randombytes.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void
ED25519_FN(ed25519_randombytes_unsafe) (void *p, size_t len) {
CCW_FN(ed25519_randombytes_unsafe) (void *p, size_t len) {
exit(1);
}
14 changes: 6 additions & 8 deletions cardano-crypto-wallet/cbits/ed25519/ed25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/


#define ED25519_FN(fn) ccw_##fn

#include "ed25519-donna.h"
#include "ed25519.h"
#include "ed25519-randombytes.h"
Expand Down Expand Up @@ -37,7 +35,7 @@ ed25519_hram(hash_512bits hram, const ed25519_signature RS, const ed25519_public
}

void
ED25519_FN(ed25519_publickey) (const ed25519_secret_key sk, ed25519_public_key pk) {
CCW_FN(ed25519_publickey) (const ed25519_secret_key sk, ed25519_public_key pk) {
bignum256modm a;
ge25519 ALIGN(16) A;
hash_512bits extsk = { 0 };
Expand All @@ -55,7 +53,7 @@ ED25519_FN(ed25519_publickey) (const ed25519_secret_key sk, ed25519_public_key p
}

void
ED25519_FN(ed25519_sign) (const unsigned char *m, size_t mlen, const unsigned char *salt, size_t slen, const ed25519_secret_key sk, const ed25519_public_key pk, ed25519_signature RS) {
CCW_FN(ed25519_sign) (const unsigned char *m, size_t mlen, const unsigned char *salt, size_t slen, const ed25519_secret_key sk, const ed25519_public_key pk, ed25519_signature RS) {
ed25519_hash_context ctx;
bignum256modm r, S, a;
ge25519 ALIGN(16) R;
Expand Down Expand Up @@ -94,7 +92,7 @@ ED25519_FN(ed25519_sign) (const unsigned char *m, size_t mlen, const unsigned ch
}

int
ED25519_FN(ed25519_sign_open) (const unsigned char *m, size_t mlen, const ed25519_public_key pk, const ed25519_signature RS) {
CCW_FN(ed25519_sign_open) (const unsigned char *m, size_t mlen, const ed25519_public_key pk, const ed25519_signature RS) {
ge25519 ALIGN(16) R, A;
hash_512bits hash;
bignum256modm hram, S;
Expand All @@ -120,7 +118,7 @@ ED25519_FN(ed25519_sign_open) (const unsigned char *m, size_t mlen, const ed2551

/* we only need the leftmost 32 bytes of the extended secret key */
int
ED25519_FN(ed25519_scalar_add) (const ed25519_secret_key sk1, const ed25519_secret_key sk2, ed25519_secret_key res)
CCW_FN(ed25519_scalar_add) (const ed25519_secret_key sk1, const ed25519_secret_key sk2, ed25519_secret_key res)
{
bignum256modm s1, s2;
expand256_modm(s1, sk1, 32);
Expand All @@ -131,7 +129,7 @@ ED25519_FN(ed25519_scalar_add) (const ed25519_secret_key sk1, const ed25519_secr
}

int
ED25519_FN(ed25519_point_add) (const ed25519_public_key pk1, const ed25519_public_key pk2, ed25519_public_key res)
CCW_FN(ed25519_point_add) (const ed25519_public_key pk1, const ed25519_public_key pk2, ed25519_public_key res)
{
ge25519 ALIGN(16) R, P, Q;

Expand All @@ -148,7 +146,7 @@ ED25519_FN(ed25519_point_add) (const ed25519_public_key pk1, const ed25519_publi
}

int
ED25519_FN(ed25519_extend) (const ed25519_unextended_secret_key seed, ed25519_secret_key secret)
CCW_FN(ed25519_extend) (const ed25519_unextended_secret_key seed, ed25519_secret_key secret)
{
ed25519_extsk(secret, seed);

Expand Down
14 changes: 8 additions & 6 deletions cardano-crypto-wallet/cbits/ed25519/ed25519.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <stdlib.h>

#define CCW_FN(fn) cardano_crypto_wallet_##fn

#if defined(__cplusplus)
extern "C" {
#endif
Expand All @@ -12,12 +14,12 @@ typedef unsigned char ed25519_public_key[32];
typedef unsigned char ed25519_unextended_secret_key[32]; // this is the UNEXTENDED SECRET KEY
typedef unsigned char ed25519_secret_key[64]; // this is the EXTENDED SECRET KEY

void ccw_ed25519_publickey(const ed25519_secret_key sk, ed25519_public_key pk);
int ccw_ed25519_sign_open(const unsigned char *m, size_t mlen, const ed25519_public_key pk, const ed25519_signature RS);
void ccw_ed25519_sign (const unsigned char *m, size_t mlen, const unsigned char *salt, size_t slen, const ed25519_secret_key sk, const ed25519_public_key pk, ed25519_signature RS);
int ccw_ed25519_scalar_add (const ed25519_secret_key sk1, const ed25519_secret_key sk2, ed25519_secret_key res);
int ccw_ed25519_point_add (const ed25519_public_key pk1, const ed25519_public_key pk2, ed25519_public_key res);
int ccw_ed25519_extend (const ed25519_unextended_secret_key seed, ed25519_secret_key secret);
void CCW_FN(ed25519_publickey) (const ed25519_secret_key sk, ed25519_public_key pk);
int CCW_FN(ed25519_sign_open) (const unsigned char *m, size_t mlen, const ed25519_public_key pk, const ed25519_signature RS);
void CCW_FN(ed25519_sign) (const unsigned char *m, size_t mlen, const unsigned char *salt, size_t slen, const ed25519_secret_key sk, const ed25519_public_key pk, ed25519_signature RS);
int CCW_FN(ed25519_scalar_add) (const ed25519_secret_key sk1, const ed25519_secret_key sk2, ed25519_secret_key res);
int CCW_FN(ed25519_point_add) (const ed25519_public_key pk1, const ed25519_public_key pk2, ed25519_public_key res);
int CCW_FN(ed25519_extend) (const ed25519_unextended_secret_key seed, ed25519_secret_key secret);

#if defined(__cplusplus)
}
Expand Down
Loading
Loading