diff --git a/bls/main.cpp b/bls/main.cpp index 567b3aa..ca48735 100644 --- a/bls/main.cpp +++ b/bls/main.cpp @@ -53,12 +53,28 @@ struct pub_key_type { int len; }; +struct signature_type { + char *data; + int len; +}; + +struct hash_type { + char *data; + int len; +}; + + struct Game { bool new_game(int n) { len = 0; players = (char**)malloc(sizeof(char*) * n); stakes = (int*)malloc(sizeof(int) * n); game_id = game_id_autoinc++; + signs = (signature_type*)malloc(sizeof(signature_type) * n); + reveals = 0; + threshold = n * 2 / 3 + 1; + winner = -1; + state = STATE_GATHERING_STAKES; return true; @@ -107,6 +123,26 @@ struct Game { return state; } + bool reveal(pub_key_type pub_key, hash_type game_id_hash, signature_type sign) { + blsSignature s; + blsPublicKey pk; + + mclBnG1_setStr(&s.v, sign.data, sign.len, 512); + mclBnG2_setStr(&pk.v, pub_key.data, pub_key.len, 0); + + if (!blsVerify(&s, &pk, game_id_hash.data, game_id_hash.len)) { + return; + } + + signs[reveals++] = sign; + + if (reveals == threshold) { + winner = players[blsAggregate(signs, reveals)]; + } + + state = STATE_DONE; + } + private: bool compare(char *a, char *b, int len) { for (int i = 0; i < len; i++) {