Skip to content

Commit 138cedd

Browse files
authored
refactor in sign ed25519 api (#67)
1 parent 58673ba commit 138cedd

File tree

12 files changed

+227
-208
lines changed

12 files changed

+227
-208
lines changed

bindings/js/ed25519.test.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,3 @@ describe("ecc_ed25519_is_valid_point", () => {
3333
assert.ok(r);
3434
});
3535
});
36-
37-
describe("ecc_sign_ed25519_seed_keypair", () => {
38-
39-
it("generates a keypair with a specified seed", async () => {
40-
const libecc = await libecc_module();
41-
const seed = hex2bin("829ee32a86b93d3766df28d8d77069fdc04e05b17fb095043c72a56d846d0372");
42-
let pk = new Uint8Array(32);
43-
let sk = new Uint8Array(64);
44-
libecc.ecc_sign_ed25519_seed_keypair(pk, sk, seed);
45-
assert.strictEqual(bin2hex(pk), "b5ed5efc01b59d13708efa6186a6b11df026e1f5f66d417492c795bbc53211ee");
46-
assert.strictEqual(bin2hex(sk), "829ee32a86b93d3766df28d8d77069fdc04e05b17fb095043c72a56d846d0372b5ed5efc01b59d13708efa6186a6b11df026e1f5f66d417492c795bbc53211ee");
47-
});
48-
});

bindings/js/libecc-post.js

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4878,13 +4878,13 @@ Module.ecc_opaque_ristretto255_sha512_3DH_Response = (
48784878

48794879
// sign
48804880

4881-
const ecc_sign_ed25519_SIZE = 64;
4881+
const ecc_sign_ed25519_SIGNATURESIZE = 64;
48824882
/**
48834883
* Signature size.
48844884
*
48854885
* @type {number}
48864886
*/
4887-
Module.ecc_sign_ed25519_SIZE = ecc_sign_ed25519_SIZE;
4887+
Module.ecc_sign_ed25519_SIGNATURESIZE = ecc_sign_ed25519_SIGNATURESIZE;
48884888

48894889
const ecc_sign_ed25519_SEEDSIZE = 32;
48904890
/**
@@ -4935,62 +4935,62 @@ const ecc_sign_eth_bls_SIGNATURESIZE = 96;
49354935
Module.ecc_sign_eth_bls_SIGNATURESIZE = ecc_sign_eth_bls_SIGNATURESIZE;
49364936

49374937
/**
4938-
* Signs the message msg whose length is msg_len bytes, using the
4939-
* secret key sk, and puts the signature into sig.
4938+
* Signs the `message` whose length is `message_len` in bytes, using the
4939+
* secret key `sk`, and puts the signature into `signature`.
49404940
*
4941-
* @param {Uint8Array} sig (output) the signature, size:ecc_sign_ed25519_SIZE
4942-
* @param {Uint8Array} msg input message, size:msg_len
4943-
* @param {number} msg_len the length of `msg`
4941+
* @param {Uint8Array} signature (output) the signature, size:ecc_sign_ed25519_SIGNATURESIZE
4942+
* @param {Uint8Array} message input message, size:message_len
4943+
* @param {number} message_len the length of `message`
49444944
* @param {Uint8Array} sk the secret key, size:ecc_sign_ed25519_SECRETKEYSIZE
49454945
*/
4946-
Module.ecc_sign_ed25519_sign = (
4947-
sig,
4948-
msg,
4949-
msg_len,
4946+
Module.ecc_sign_ed25519_Sign = (
4947+
signature,
4948+
message,
4949+
message_len,
49504950
sk,
49514951
) => {
4952-
const ptr_sig = mput(sig, ecc_sign_ed25519_SIZE);
4953-
const ptr_msg = mput(msg, msg_len);
4952+
const ptr_signature = mput(signature, ecc_sign_ed25519_SIGNATURESIZE);
4953+
const ptr_message = mput(message, message_len);
49544954
const ptr_sk = mput(sk, ecc_sign_ed25519_SECRETKEYSIZE);
4955-
_ecc_sign_ed25519_sign(
4956-
ptr_sig,
4957-
ptr_msg,
4958-
msg_len,
4955+
_ecc_sign_ed25519_Sign(
4956+
ptr_signature,
4957+
ptr_message,
4958+
message_len,
49594959
ptr_sk,
49604960
);
4961-
mget(sig, ptr_sig, ecc_sign_ed25519_SIZE);
4962-
mfree(ptr_sig, ecc_sign_ed25519_SIZE);
4963-
mfree(ptr_msg, msg_len);
4961+
mget(signature, ptr_signature, ecc_sign_ed25519_SIGNATURESIZE);
4962+
mfree(ptr_signature, ecc_sign_ed25519_SIGNATURESIZE);
4963+
mfree(ptr_message, message_len);
49644964
mfree(ptr_sk, ecc_sign_ed25519_SECRETKEYSIZE);
49654965
}
49664966

49674967
/**
4968-
* Verifies that sig is a valid signature for the message msg whose length
4969-
* is msg_len bytes, using the signer's public key pk.
4968+
* Verifies that `signature` is a valid signature for the `message` whose length
4969+
* is `message_len` in bytes, using the signer's public key `pk`.
49704970
*
4971-
* @param {Uint8Array} sig the signature, size:ecc_sign_ed25519_SIZE
4972-
* @param {Uint8Array} msg input message, size:msg_len
4973-
* @param {number} msg_len the length of `msg`
4971+
* @param {Uint8Array} signature the signature, size:ecc_sign_ed25519_SIGNATURESIZE
4972+
* @param {Uint8Array} message input message, size:message_len
4973+
* @param {number} message_len the length of `message`
49744974
* @param {Uint8Array} pk the public key, size:ecc_sign_ed25519_PUBLICKEYSIZE
49754975
* @return {number} -1 if the signature fails verification, or 0 on success
49764976
*/
4977-
Module.ecc_sign_ed25519_verify = (
4978-
sig,
4979-
msg,
4980-
msg_len,
4977+
Module.ecc_sign_ed25519_Verify = (
4978+
signature,
4979+
message,
4980+
message_len,
49814981
pk,
49824982
) => {
4983-
const ptr_sig = mput(sig, ecc_sign_ed25519_SIZE);
4984-
const ptr_msg = mput(msg, msg_len);
4983+
const ptr_signature = mput(signature, ecc_sign_ed25519_SIGNATURESIZE);
4984+
const ptr_message = mput(message, message_len);
49854985
const ptr_pk = mput(pk, ecc_sign_ed25519_PUBLICKEYSIZE);
4986-
const fun_ret = _ecc_sign_ed25519_verify(
4987-
ptr_sig,
4988-
ptr_msg,
4989-
msg_len,
4986+
const fun_ret = _ecc_sign_ed25519_Verify(
4987+
ptr_signature,
4988+
ptr_message,
4989+
message_len,
49904990
ptr_pk,
49914991
);
4992-
mfree(ptr_sig, ecc_sign_ed25519_SIZE);
4993-
mfree(ptr_msg, msg_len);
4992+
mfree(ptr_signature, ecc_sign_ed25519_SIGNATURESIZE);
4993+
mfree(ptr_message, message_len);
49944994
mfree(ptr_pk, ecc_sign_ed25519_PUBLICKEYSIZE);
49954995
return fun_ret;
49964996
}
@@ -5001,13 +5001,13 @@ Module.ecc_sign_ed25519_verify = (
50015001
* @param {Uint8Array} pk (output) public key, size:ecc_sign_ed25519_PUBLICKEYSIZE
50025002
* @param {Uint8Array} sk (output) private key, size:ecc_sign_ed25519_SECRETKEYSIZE
50035003
*/
5004-
Module.ecc_sign_ed25519_keypair = (
5004+
Module.ecc_sign_ed25519_KeyPair = (
50055005
pk,
50065006
sk,
50075007
) => {
50085008
const ptr_pk = mput(pk, ecc_sign_ed25519_PUBLICKEYSIZE);
50095009
const ptr_sk = mput(sk, ecc_sign_ed25519_SECRETKEYSIZE);
5010-
_ecc_sign_ed25519_keypair(
5010+
_ecc_sign_ed25519_KeyPair(
50115011
ptr_pk,
50125012
ptr_sk,
50135013
);
@@ -5019,21 +5019,21 @@ Module.ecc_sign_ed25519_keypair = (
50195019

50205020
/**
50215021
* Generates a random key pair of public and private keys derived
5022-
* from a seed.
5022+
* from a `seed`.
50235023
*
50245024
* @param {Uint8Array} pk (output) public key, size:ecc_sign_ed25519_PUBLICKEYSIZE
50255025
* @param {Uint8Array} sk (output) private key, size:ecc_sign_ed25519_SECRETKEYSIZE
50265026
* @param {Uint8Array} seed seed to generate the keys, size:ecc_sign_ed25519_SEEDSIZE
50275027
*/
5028-
Module.ecc_sign_ed25519_seed_keypair = (
5028+
Module.ecc_sign_ed25519_SeedKeyPair = (
50295029
pk,
50305030
sk,
50315031
seed,
50325032
) => {
50335033
const ptr_pk = mput(pk, ecc_sign_ed25519_PUBLICKEYSIZE);
50345034
const ptr_sk = mput(sk, ecc_sign_ed25519_SECRETKEYSIZE);
50355035
const ptr_seed = mput(seed, ecc_sign_ed25519_SEEDSIZE);
5036-
_ecc_sign_ed25519_seed_keypair(
5036+
_ecc_sign_ed25519_SeedKeyPair(
50375037
ptr_pk,
50385038
ptr_sk,
50395039
ptr_seed,
@@ -5046,18 +5046,18 @@ Module.ecc_sign_ed25519_seed_keypair = (
50465046
}
50475047

50485048
/**
5049-
* Extracts the seed from the secret key sk and copies it into seed.
5049+
* Extracts the seed from the secret key `sk` and copies it into `seed`.
50505050
*
50515051
* @param {Uint8Array} seed (output) the seed used to generate the secret key, size:ecc_sign_ed25519_SEEDSIZE
50525052
* @param {Uint8Array} sk the secret key, size:ecc_sign_ed25519_SECRETKEYSIZE
50535053
*/
5054-
Module.ecc_sign_ed25519_sk_to_seed = (
5054+
Module.ecc_sign_ed25519_SkToSeed = (
50555055
seed,
50565056
sk,
50575057
) => {
50585058
const ptr_seed = mput(seed, ecc_sign_ed25519_SEEDSIZE);
50595059
const ptr_sk = mput(sk, ecc_sign_ed25519_SECRETKEYSIZE);
5060-
_ecc_sign_ed25519_sk_to_seed(
5060+
_ecc_sign_ed25519_SkToSeed(
50615061
ptr_seed,
50625062
ptr_sk,
50635063
);
@@ -5067,18 +5067,18 @@ Module.ecc_sign_ed25519_sk_to_seed = (
50675067
}
50685068

50695069
/**
5070-
* Extracts the public key from the secret key sk and copies it into pk.
5070+
* Extracts the public key from the secret key `sk` and copies it into `pk`.
50715071
*
50725072
* @param {Uint8Array} pk (output) the public key, size:ecc_sign_ed25519_PUBLICKEYSIZE
50735073
* @param {Uint8Array} sk the secret key, size:ecc_sign_ed25519_SECRETKEYSIZE
50745074
*/
5075-
Module.ecc_sign_ed25519_sk_to_pk = (
5075+
Module.ecc_sign_ed25519_SkToPk = (
50765076
pk,
50775077
sk,
50785078
) => {
50795079
const ptr_pk = mput(pk, ecc_sign_ed25519_PUBLICKEYSIZE);
50805080
const ptr_sk = mput(sk, ecc_sign_ed25519_SECRETKEYSIZE);
5081-
_ecc_sign_ed25519_sk_to_pk(
5081+
_ecc_sign_ed25519_SkToPk(
50825082
ptr_pk,
50835083
ptr_sk,
50845084
);

bindings/js/libecc.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/js/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"oprf.test.js",
2424
"opaque.test.js",
2525
"pre.test.js",
26+
"sign.test.js",
2627
"README.md",
2728
"LICENSE",
2829
"dist/ecc.dev.js",

bindings/js/sign.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2022, Alden Torres
3+
*
4+
* Licensed under the terms of the MIT license.
5+
* Copy of the license at https://opensource.org/licenses/MIT
6+
*/
7+
8+
import libecc_module from "./libecc.js";
9+
import assert from "assert";
10+
import {
11+
bin2hex,
12+
hex2bin,
13+
} from "./util.js";
14+
15+
describe("ecc_sign_ed25519_SeedKeypair", () => {
16+
17+
it("generates a keypair with a specified seed", async () => {
18+
const libecc = await libecc_module();
19+
const seed = hex2bin("829ee32a86b93d3766df28d8d77069fdc04e05b17fb095043c72a56d846d0372");
20+
let pk = new Uint8Array(libecc.ecc_sign_ed25519_PUBLICKEYSIZE);
21+
let sk = new Uint8Array(libecc.ecc_sign_ed25519_SECRETKEYSIZE);
22+
libecc.ecc_sign_ed25519_SeedKeyPair(pk, sk, seed);
23+
assert.strictEqual(bin2hex(pk), "b5ed5efc01b59d13708efa6186a6b11df026e1f5f66d417492c795bbc53211ee");
24+
assert.strictEqual(bin2hex(sk), "829ee32a86b93d3766df28d8d77069fdc04e05b17fb095043c72a56d846d0372b5ed5efc01b59d13708efa6186a6b11df026e1f5f66d417492c795bbc53211ee");
25+
});
26+
});

bindings/jvm/libecc.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,58 +3200,58 @@ JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1opaque_1ristretto2
32003200

32013201
// sign
32023202

3203-
JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1sign(
3203+
JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1Sign(
32043204
JNIEnv *env, jclass cls,
3205-
jbyteArray sig,
3206-
jbyteArray msg,
3207-
jint msg_len,
3205+
jbyteArray signature,
3206+
jbyteArray message,
3207+
jint message_len,
32083208
jbyteArray sk
32093209
) {
3210-
byte_t *ptr_sig = mput(env, sig, ecc_sign_ed25519_SIZE);
3211-
byte_t *ptr_msg = mput(env, msg, msg_len);
3210+
byte_t *ptr_signature = mput(env, signature, ecc_sign_ed25519_SIGNATURESIZE);
3211+
byte_t *ptr_message = mput(env, message, message_len);
32123212
byte_t *ptr_sk = mput(env, sk, ecc_sign_ed25519_SECRETKEYSIZE);
3213-
ecc_sign_ed25519_sign(
3214-
ptr_sig,
3215-
ptr_msg,
3216-
msg_len,
3213+
ecc_sign_ed25519_Sign(
3214+
ptr_signature,
3215+
ptr_message,
3216+
message_len,
32173217
ptr_sk
32183218
);
3219-
mget(env, sig, ptr_sig, ecc_sign_ed25519_SIZE);
3220-
mfree(ptr_sig, ecc_sign_ed25519_SIZE);
3221-
mfree(ptr_msg, msg_len);
3219+
mget(env, signature, ptr_signature, ecc_sign_ed25519_SIGNATURESIZE);
3220+
mfree(ptr_signature, ecc_sign_ed25519_SIGNATURESIZE);
3221+
mfree(ptr_message, message_len);
32223222
mfree(ptr_sk, ecc_sign_ed25519_SECRETKEYSIZE);
32233223
}
32243224

3225-
JNIEXPORT int JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1verify(
3225+
JNIEXPORT int JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1Verify(
32263226
JNIEnv *env, jclass cls,
3227-
jbyteArray sig,
3228-
jbyteArray msg,
3229-
jint msg_len,
3227+
jbyteArray signature,
3228+
jbyteArray message,
3229+
jint message_len,
32303230
jbyteArray pk
32313231
) {
3232-
byte_t *ptr_sig = mput(env, sig, ecc_sign_ed25519_SIZE);
3233-
byte_t *ptr_msg = mput(env, msg, msg_len);
3232+
byte_t *ptr_signature = mput(env, signature, ecc_sign_ed25519_SIGNATURESIZE);
3233+
byte_t *ptr_message = mput(env, message, message_len);
32343234
byte_t *ptr_pk = mput(env, pk, ecc_sign_ed25519_PUBLICKEYSIZE);
3235-
const int fun_ret = ecc_sign_ed25519_verify(
3236-
ptr_sig,
3237-
ptr_msg,
3238-
msg_len,
3235+
const int fun_ret = ecc_sign_ed25519_Verify(
3236+
ptr_signature,
3237+
ptr_message,
3238+
message_len,
32393239
ptr_pk
32403240
);
3241-
mfree(ptr_sig, ecc_sign_ed25519_SIZE);
3242-
mfree(ptr_msg, msg_len);
3241+
mfree(ptr_signature, ecc_sign_ed25519_SIGNATURESIZE);
3242+
mfree(ptr_message, message_len);
32433243
mfree(ptr_pk, ecc_sign_ed25519_PUBLICKEYSIZE);
32443244
return fun_ret;
32453245
}
32463246

3247-
JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1keypair(
3247+
JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1KeyPair(
32483248
JNIEnv *env, jclass cls,
32493249
jbyteArray pk,
32503250
jbyteArray sk
32513251
) {
32523252
byte_t *ptr_pk = mput(env, pk, ecc_sign_ed25519_PUBLICKEYSIZE);
32533253
byte_t *ptr_sk = mput(env, sk, ecc_sign_ed25519_SECRETKEYSIZE);
3254-
ecc_sign_ed25519_keypair(
3254+
ecc_sign_ed25519_KeyPair(
32553255
ptr_pk,
32563256
ptr_sk
32573257
);
@@ -3261,7 +3261,7 @@ JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1key
32613261
mfree(ptr_sk, ecc_sign_ed25519_SECRETKEYSIZE);
32623262
}
32633263

3264-
JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1seed_1keypair(
3264+
JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1SeedKeyPair(
32653265
JNIEnv *env, jclass cls,
32663266
jbyteArray pk,
32673267
jbyteArray sk,
@@ -3270,7 +3270,7 @@ JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1see
32703270
byte_t *ptr_pk = mput(env, pk, ecc_sign_ed25519_PUBLICKEYSIZE);
32713271
byte_t *ptr_sk = mput(env, sk, ecc_sign_ed25519_SECRETKEYSIZE);
32723272
byte_t *ptr_seed = mput(env, seed, ecc_sign_ed25519_SEEDSIZE);
3273-
ecc_sign_ed25519_seed_keypair(
3273+
ecc_sign_ed25519_SeedKeyPair(
32743274
ptr_pk,
32753275
ptr_sk,
32763276
ptr_seed
@@ -3282,14 +3282,14 @@ JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1see
32823282
mfree(ptr_seed, ecc_sign_ed25519_SEEDSIZE);
32833283
}
32843284

3285-
JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1sk_1to_1seed(
3285+
JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1SkToSeed(
32863286
JNIEnv *env, jclass cls,
32873287
jbyteArray seed,
32883288
jbyteArray sk
32893289
) {
32903290
byte_t *ptr_seed = mput(env, seed, ecc_sign_ed25519_SEEDSIZE);
32913291
byte_t *ptr_sk = mput(env, sk, ecc_sign_ed25519_SECRETKEYSIZE);
3292-
ecc_sign_ed25519_sk_to_seed(
3292+
ecc_sign_ed25519_SkToSeed(
32933293
ptr_seed,
32943294
ptr_sk
32953295
);
@@ -3298,14 +3298,14 @@ JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1sk_
32983298
mfree(ptr_sk, ecc_sign_ed25519_SECRETKEYSIZE);
32993299
}
33003300

3301-
JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1sk_1to_1pk(
3301+
JNIEXPORT void JNICALL Java_org_ssohub_crypto_ecc_libecc_ecc_1sign_1ed25519_1SkToPk(
33023302
JNIEnv *env, jclass cls,
33033303
jbyteArray pk,
33043304
jbyteArray sk
33053305
) {
33063306
byte_t *ptr_pk = mput(env, pk, ecc_sign_ed25519_PUBLICKEYSIZE);
33073307
byte_t *ptr_sk = mput(env, sk, ecc_sign_ed25519_SECRETKEYSIZE);
3308-
ecc_sign_ed25519_sk_to_pk(
3308+
ecc_sign_ed25519_SkToPk(
33093309
ptr_pk,
33103310
ptr_sk
33113311
);

0 commit comments

Comments
 (0)