This document describes the protocol used to secure and verify Spy Cards Online matches.
It is expected that you have at least a basic understanding of cryptography and computer networking, as the fundamentals of these concepts will not be explained in this document.
Tunable algorithm properties and their values as used in Spy Cards Online
Placeholder
Value Used
Description
HASH_FUNC
SHA-256
The function used for key stretching and verification.
The protocol uses a single networking primitive: Exchange Data.
Both sides of the connection send a packet and receive the other side's packet. The implementation may send additional metadata (length, type, etc.)
Spy Cards Online prefixes the data with two varints, representing the packet type and the turn number (zero for non-repeated packets).
Additional data must be sent outside the scope of this protocol - for example, most game messages would be transferred using an asymmetric mechanism, as the non-acting player's computer would not have any way of knowing an action was about to take place.
Initial Handshake
Generate SEED_LEN bytes of random data as SharedSeedHalf[Local].
Exchange Data (0): SharedSeedHalf
SharedSeed is defined as the concatination of the two SharedSeedHalf values, with player 1/host/listener's half first and player 2/client/dialer's half second.
Generate RAND_LEN bytes of random data as PrivateSeed[Local].
Encode the initial deck of cards.
Compute HASH_FUNC(SharedSeed + PrivateSeed[Local] + InitialDeck[Local]) as InitialHash[Local].
Encode the backs of the cards in the initial deck as InitialDeckBacks[Local].
Exchange Data (1): InitialHash + InitialDeckBacks
Verify that InitialDeckBacks[Remote] can be a valid deck, and store the data for later.
Turn Start
Generate RAND_LEN bytes of random data as ShuffleSeedHalf[Local].
Compute HASH_FUNC(SharedSeed + ShuffleSeedHalf[Local]) as ShuffleHash[Local].
Exchange Data (2): ShuffleHash
Exchange Data (3): ShuffleSeedHalf
Verify that HASH_FUNC(SharedSeed + ShuffleSeedHalf[Remote]) matches ShuffleHash[Remote]
ShuffleSeed is defined as the concatination of the two ShuffleSeedHalf, in the same order as SharedSeed.
Shuffle the deck and draw cards.
Turn Ready
TODO
Turn End
TODO
Finalization
Exchange Data (5): PrivateSeed + InitialDeck.
Verify that InitialHash[Remote] matches HASH_FUNC(SharedSeed + PrivateSeed[Remote] + InitialDeck[Remote]).
Verify that InitialDeckBacks[Remote] matches InitialDeck[Remote].
Re-simulate all turns, ensuring that the cards played each turn were in the opponent's hand.