From 33f126914ed4152f7832c660299980af972b847c Mon Sep 17 00:00:00 2001 From: jl777 Date: Fri, 22 Feb 2019 21:45:03 -1100 Subject: [PATCH] Dilithium key pair --- src/cc/cclib.cpp | 33 +++++++++++++++++++++++++++++++++ src/cc/dilithium.c | 39 +++++++++++++++++++++++++++++++++++++++ src/cc/dilithium.h | 9 +++++---- 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index c7372907e..46a5f4736 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -37,6 +37,7 @@ std::string MYCCLIBNAME = (char *)"rogue"; #define EVAL_SUDOKU 17 #define EVAL_MUSIG 18 +#define EVAL_DILITHIUM 19 std::string MYCCLIBNAME = (char *)"sudoku"; #endif @@ -80,6 +81,11 @@ 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 *)"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 }, + { (char *)"dilithium", (char *)"spend", (char *)"sendtxid sig destpubkey", 3, 3, 'y', EVAL_DILITHIUM }, #endif }; @@ -119,6 +125,13 @@ UniValue musig_partialsig(uint64_t txfee,struct CCcontract_info *cp,cJSON *param UniValue musig_verify(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue musig_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); + +UniValue dilithium_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue dilithium_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue dilithium_keypair(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue dilithium_sign(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); +UniValue dilithium_verify(uint64_t txfee,struct CCcontract_info *cp,cJSON *params); + #endif cJSON *cclib_reparse(int32_t *nump,char *jsonstr) // assumes origparams will be freed by caller @@ -243,6 +256,26 @@ UniValue CClib_method(struct CCcontract_info *cp,char *method,char *jsonstr) return(result); } } + else if ( cp->evalcode == EVAL_DILITHIUM ) + { + if ( strcmp(method,"send") == 0 ) + return(dilithium_send(txfee,cp,params)); + else if ( strcmp(method,"spend") == 0 ) + return(dilithium_spend(txfee,cp,params)); + else if ( strcmp(method,"keypair") == 0 ) + return(dilithium_keypair(txfee,cp,params)); + else if ( strcmp(method,"sign") == 0 ) + return(dilithium_sign(txfee,cp,params)); + else if ( strcmp(method,"verify") == 0 ) + return(dilithium_verify(txfee,cp,params)); + else + { + result.push_back(Pair("result","error")); + result.push_back(Pair("error","invalid dilithium method")); + result.push_back(Pair("method",method)); + return(result); + } + } #endif else { diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index b6624353e..902a3ca49 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -2835,3 +2835,42 @@ int32_t main(void) } #endif +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); + for (i=0; i +/* #ifndef CPUCYCLES_H #define CPUCYCLES_H @@ -11,7 +12,7 @@ #define DBENCH_STOP(t) #endif -#ifdef USE_RDPMC /* Needs echo 2 > /sys/devices/cpu/rdpmc */ +#ifdef USE_RDPMC // Needs echo 2 > /sys/devices/cpu/rdpmc #ifdef SERIALIZE_RDC static inline uint64_t cpucycles_start(void) { @@ -103,7 +104,7 @@ static inline uint64_t cpucycles_stop(void) { int64_t cpucycles_overhead(void); -#endif +#endif*/ #ifndef FIPS202_H #define FIPS202_H @@ -144,7 +145,7 @@ void shake256(uint8_t *output, #define PARAMS_H #ifndef MODE -#define MODE 2 +#define MODE 3 #endif #define SEEDBYTES 32U @@ -410,7 +411,7 @@ int crypto_sign_open(uint8_t *m, int32_t *mlen, #define API_H #ifndef MODE -#define MODE 2 +#define MODE 3 #endif #if MODE == 0