hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 087d4f7150e4cfafa1627499dfd809741d4f9e1c
parent 4169acfb42c1b663fdc939b331fc37c5925ffd21
Author: Armin Preiml <apreiml@strohwolke.at>
Date:   Wed, 20 Jul 2022 08:52:45 +0200

crypto:ed25519: name keys pubkey and privkey

Signed-off-by: Armin Preiml <apreiml@strohwolke.at>

Diffstat:
Mcrypto/ed25519/+test.ha | 12++++++------
Mcrypto/ed25519/ed25519.ha | 20++++++++++----------
2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/crypto/ed25519/+test.ha b/crypto/ed25519/+test.ha @@ -6,9 +6,9 @@ use strings; @test fn roundtrip() void = { let seed: seed = [1...]; - let priv_key: privatekey = [0...]; - private_init(&priv_key, &seed); - let pub_key = skey_getpublic(&priv_key); + let priv_key: privkey = [0...]; + privkey_init(&priv_key, &seed); + let pub_key = privkey_getpubkey(&priv_key); const msg = strings::toutf8("hello, world!"); let sig = sign(&priv_key, msg); @@ -27,16 +27,16 @@ use strings; @test fn golden() void = { // TODO https://todo.sr.ht/~sircmpwn/hare/596 - let priv_key: privatekey = [0...]; + let priv_key: privkey = [0...]; let priv_key_u8 = hex::decodestr("8ed7a797b9cea8a8370d419136bcdf683b759d2e3c6947f17e13e2485aa9d420b49f3a78b1c6a7fca8f3466f33bc0e929f01fba04306c2a7465f46c3759316d9") as []u8; priv_key[..] = priv_key_u8[..]; free(priv_key_u8); - const pub_key = skey_getpublic(&priv_key); + const pub_key = privkey_getpubkey(&priv_key); let msg = hex::decodestr("a750c232933dc14b1184d86d8b4ce72e16d69744ba69818b6ac33b1d823bb2c3") as []u8; defer free(msg); - let good_sig: privatekey = [0...]; + let good_sig: privkey = [0...]; let sig_u8 = hex::decodestr("04266c033b91c1322ceb3446c901ffcf3cc40c4034e887c9597ca1893ba7330becbbd8b48142ef35c012c6ba51a66df9308cb6268ad6b1e4b03e70102495790b") as []u8; good_sig[..] = sig_u8[..]; free(sig_u8); diff --git a/crypto/ed25519/ed25519.ha b/crypto/ed25519/ed25519.ha @@ -13,22 +13,22 @@ use hash; export def SEEDSZ: size = 32; // The size of an Ed25519 public key. -export def PUBLICKEYSZ: size = 32; +export def PUBKEYSZ: size = 32; // The size of an Ed25519 private key. -export def PRIVATEKEYSZ: size = 64; +export def PRIVKEYSZ: size = 64; // The size of an Ed25519 signature. export def SIGNATURESZ: size = 64; -export type privatekey = [PRIVATEKEYSZ]u8; -export type publickey =[PUBLICKEYSZ]u8; +export type privkey = [PRIVKEYSZ]u8; +export type pubkey =[PUBKEYSZ]u8; export type seed = [SEEDSZ]u8; // Derives a new Ed25519 private key from a given seed. The seed must be // initialized to cryptographically random data; [[crypto::random]] is // recommended for this purpose. -export fn private_init(out: *privatekey, seed: *seed) void = { +export fn privkey_init(out: *privkey, seed: *seed) void = { let h: [64]u8 = [0...]; let sha = sha512::sha512(); hash::write(&sha, seed[..]); @@ -45,18 +45,18 @@ export fn private_init(out: *privatekey, seed: *seed) void = { point_encode(&A_bytes, &A); out[0..SEEDSZ] = seed[..]; - out[SEEDSZ..PRIVATEKEYSZ] = A_bytes[..]; + out[SEEDSZ..PRIVKEYSZ] = A_bytes[..]; }; // Derive the public key for a given private key. -export fn skey_getpublic(priv: *privatekey) publickey = { - let pk: publickey = [0...]; +export fn privkey_getpubkey(priv: *privkey) pubkey = { + let pk: pubkey = [0...]; pk[0..] = priv[SEEDSZ..]; return pk; }; // Signs a message with a private key, returning the signature. -export fn sign(priv: *privatekey, msg: []u8) [SIGNATURESZ]u8 = { +export fn sign(priv: *privkey, msg: []u8) [SIGNATURESZ]u8 = { let h: [64]u8 = [0...]; let sha = sha512::sha512(); hash::write(&sha, priv[0..SEEDSZ]); @@ -100,7 +100,7 @@ export fn sign(priv: *privatekey, msg: []u8) [SIGNATURESZ]u8 = { // Given a public key, verifies a signature produced with the // corresponding private key for a given message, returning true if the // signature is valid and false otherwise. -export fn verify(pub: *publickey, msg: []u8, sig: *[SIGNATURESZ]u8) bool = { +export fn verify(pub: *pubkey, msg: []u8, sig: *[SIGNATURESZ]u8) bool = { let A = point { ... }; if (!point_decode(&A, pub)) { return false;