diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 46a5f4736..4f539b7f9 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -81,7 +81,7 @@ CClib_methods[] = { (char *)"musig", (char *)"verify", (char *)"msg sig pubkey", 3, 3, 'V', EVAL_MUSIG }, { (char *)"musig", (char *)"send", (char *)"combined_pk amount", 2, 2, 'x', EVAL_MUSIG }, { (char *)"musig", (char *)"spend", (char *)"sendtxid sig destpubkey", 3, 3, 'y', EVAL_MUSIG }, - { (char *)"dilithium", (char *)"keypair", (char *)"", 0, 0, 'K', EVAL_DILITHIUM }, + { (char *)"dilithium", (char *)"keypair", (char *)"[hexseed]", 0, 1, 'K', EVAL_DILITHIUM }, { (char *)"dilithium", (char *)"sign", (char *)"msg privkey", 2, 2, 'S', EVAL_DILITHIUM }, { (char *)"dilithium", (char *)"verify", (char *)"msg sig pubtxid", 3, 3, 'V', EVAL_DILITHIUM }, { (char *)"dilithium", (char *)"send", (char *)"pubtxid amount", 2, 2, 'x', EVAL_DILITHIUM }, diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 9103a6037..10718d1c3 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -2437,7 +2437,8 @@ void challenge(poly *c, * * Returns 0 (success) **************************************************/ -int _dilithium_keypair(uint8_t *pk, uint8_t *sk) { +int _dilithium_keypair(uint8_t *pk, uint8_t *sk,uint8_t *privkey) +{ uint32_t i; uint8_t seedbuf[3*SEEDBYTES]; uint8_t tr[CRHBYTES]; @@ -2448,7 +2449,8 @@ int _dilithium_keypair(uint8_t *pk, uint8_t *sk) { polyveck s2, t, t1, t0; /* Expand 32 bytes of randomness into rho, rhoprime and key */ - randombytes(seedbuf, SEEDBYTES); + //randombytes(seedbuf, SEEDBYTES); + memcpy(seedbuf,privkey,SEEDBYTES); shake256(seedbuf, 3*SEEDBYTES, seedbuf, SEEDBYTES); rho = seedbuf; rhoprime = rho + SEEDBYTES; @@ -2841,8 +2843,16 @@ int32_t main(void) UniValue dilithium_keypair(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) { - UniValue result(UniValue::VOBJ); uint8_t pk[CRYPTO_PUBLICKEYBYTES],sk[CRYPTO_SECRETKEYBYTES]; char str[CRYPTO_SECRETKEYBYTES*2+1]; int32_t i; - _dilithium_keypair(pk,sk); + UniValue result(UniValue::VOBJ); uint8_t seed[SEEDBYTES],pk[CRYPTO_PUBLICKEYBYTES],sk[CRYPTO_SECRETKEYBYTES]; char str[CRYPTO_SECRETKEYBYTES*2+1]; int32_t i,n,externalflag=0; + //randombytes(seed,SEEDBYTES); + Myprivkey(seed); + if ( params != 0 && (n= cJSON_GetArraySize(params)) == 1 ) + { + if ( musig_parsehash(seed,jitem(params,0),32) < 0 ) + return(cclib_error(result,"error parsing seed")); + else externalflag = 1; + } + _dilithium_keypair(pk,sk,seed); for (i=0; i