Negotiating a secret for encryption in the global press

Use this forum to discuss Diplomacy strategy.
Forum rules
This forum is limited to topics relating to the game Diplomacy only. Other posts or topics will be relocated to the correct forum category or deleted. Please be respectful and follow our normal site rules at http://www.webdiplomacy.net/rules.php.
Message
Author
learnedSloth
Posts: 82
Joined: Mon Sep 12, 2022 10:20 pm
Karma: 31
Contact:

Negotiating a secret for encryption in the global press

#1 Post by learnedSloth » Mon Aug 07, 2023 11:42 am

It can be done with significantly shorter cipher than I assumed in Cryptic messages and intrigue, as encrypting arbitrary messages isn't necessary.
Both players must contribute to the secret and a confounding factor is required to exchange the contributions without revealing them.

Commanding OpenSSL to do the hard work

First your secret contribution:

Code: Select all

openssl genpkey -algorithm X25519 -out contribution
Keep it safe, for computing the secret with it is fast, but too slow without it.
Now the confounded version for sharing:

Code: Select all

openssl pkey -in contribution -pubout -out confounded
It looks like this:

Code: Select all

-----BEGIN PUBLIC KEY-----
MCowBQYDK2VuAyEAIA2nOyv2LtvlcLqEHQz6owx9dBQ7Ie74U+B7qmXnqEk=
-----END PUBLIC KEY-----
If other players can be trusted to reproduce the header and footer by hand, you need to paste just that 1 line of cipher, which is shorter than some gibberish used in the game linked above!

When 2 players have pasted their confounded contributions, they can compute their common secret:

Code: Select all

openssl pkeyutl -derive -inkey contribution -peerkey another_confounded -out common_secret
It's 256 raw bits, so you may have to convert it depending on how you plan to use it.
1

User avatar
Jamiet99uk
Posts: 27646
Joined: Sat Dec 30, 2017 11:42 pm
Location: Durham, UK
Karma: 17104
Contact:

Re: Negotiating a secret for encryption in the global press

#2 Post by Jamiet99uk » Mon Aug 07, 2023 11:55 am

I don't understand.

Is this intended for public press only games?

If so, how do you agree the "secret" part of the cipher with the other player, without breaking the rules on outside press?
1
FREE PALESTINE

learnedSloth
Posts: 82
Joined: Mon Sep 12, 2022 10:20 pm
Karma: 31
Contact:

Re: Negotiating a secret for encryption in the global press

#3 Post by learnedSloth » Mon Aug 07, 2023 12:04 pm

Jamiet99uk wrote:
Mon Aug 07, 2023 11:55 am
If so, how do you agree the "secret" part of the cipher with the other player, without breaking the rules on outside press?
By posting it to the public press in the confounded form; that's the purpose of the confounding factor. Here's an illustration:

Image

User avatar
Jamiet99uk
Posts: 27646
Joined: Sat Dec 30, 2017 11:42 pm
Location: Durham, UK
Karma: 17104
Contact:

Re: Negotiating a secret for encryption in the global press

#4 Post by Jamiet99uk » Mon Aug 07, 2023 12:16 pm

I don't understand the "public transport" part.

That diagram only works if the "public transport" colours are specific colours that would combine to produce the right output.
FREE PALESTINE

learnedSloth
Posts: 82
Joined: Mon Sep 12, 2022 10:20 pm
Karma: 31
Contact:

Re: Negotiating a secret for encryption in the global press

#5 Post by learnedSloth » Mon Aug 07, 2023 12:21 pm

Jamiet99uk wrote:
Mon Aug 07, 2023 12:16 pm
I don't understand the "public transport" part.
Substitute "transport" with "press".
That diagram only works if the "public transport" colours are specific colours that would combine to produce the right output.
They are the confounded contributions to the common secret.

User avatar
JECE
Posts: 1370
Joined: Sun Dec 31, 2017 4:35 pm
Karma: 358
Contact:

Re: Negotiating a secret for encryption in the global press

#6 Post by JECE » Mon Aug 07, 2023 1:01 pm

Jamiet99uk wrote:
Mon Aug 07, 2023 11:55 am
I don't understand.

Is this intended for public press only games?

If so, how do you agree the "secret" part of the cipher with the other player, without breaking the rules on outside press?
I believe that the answer you seek is on this thread from a few months ago:
viewtopic.php?f=7&t=4711

This post in particular:
viewtopic.php?p=340562#p340562
See my full Profile:
http://www.webdiplomacy.net/profile.php?userID=17421

User avatar
Jamiet99uk
Posts: 27646
Joined: Sat Dec 30, 2017 11:42 pm
Location: Durham, UK
Karma: 17104
Contact:

Re: Negotiating a secret for encryption in the global press

#7 Post by Jamiet99uk » Mon Aug 07, 2023 1:22 pm

This all goes over my head, to be honest. I don't think I'd be able to do any of this.
1
FREE PALESTINE

learnedSloth
Posts: 82
Joined: Mon Sep 12, 2022 10:20 pm
Karma: 31
Contact:

Re: Negotiating a secret for encryption in the global press

#8 Post by learnedSloth » Mon Aug 07, 2023 1:36 pm

JECE wrote:
Mon Aug 07, 2023 1:01 pm
I believe that the answer you seek is on this thread from a few months ago:
viewtopic.php?f=7&t=4711

This post in particular:
viewtopic.php?p=340562#p340562
The key metaphor that EFF uses describes the more powerful technique with longer ciphers that I proposed in that thread. If the only goal is to agree to a secret, then the protocol can be streamlined and shorter ciphers suffice. The paint metaphor describes it more accurately. The key takeaway is that mixing is associative.

User avatar
JECE
Posts: 1370
Joined: Sun Dec 31, 2017 4:35 pm
Karma: 358
Contact:

Re: Negotiating a secret for encryption in the global press

#9 Post by JECE » Mon Aug 07, 2023 4:24 pm

I don't think that I understand either, then.
See my full Profile:
http://www.webdiplomacy.net/profile.php?userID=17421

learnedSloth
Posts: 82
Joined: Mon Sep 12, 2022 10:20 pm
Karma: 31
Contact:

Re: Negotiating a secret for encryption in the global press

#10 Post by learnedSloth » Mon Aug 07, 2023 5:31 pm

Understanding isn't required for use. :-)

OK, let's forget metaphors. The math is simple. I made the following table where
- CF is the confounding factor
- S1 is the secret of Player 1
- S2 is the secret of Player 2
- * means mixing
- arrows illustrate direction of dataflow

Code: Select all

Player 1 knows |  Public Press  | Player 2 knows
---------------+----------------+-----------
S1           <-+--     CF     --+->           S2
S1*CF        --+->    S1*CF   --+->     S1*CF*S2
S1*CF*S2     <-+--    CF*S2   <-+--        CF*S2
The shared secret is S1*CF*S2. In theory S1 and S2 could be recovered by inverting the mix, but that is extraordinarily difficult because the mixture is restricted to a finite field with wraparound to fail preconditions that made it easy in the realm of integers. 8-)

User avatar
JECE
Posts: 1370
Joined: Sun Dec 31, 2017 4:35 pm
Karma: 358
Contact:

Re: Negotiating a secret for encryption in the global press

#11 Post by JECE » Mon Aug 07, 2023 9:19 pm

The algebra makes sense. But it isn't algebra, I guess?
See my full Profile:
http://www.webdiplomacy.net/profile.php?userID=17421

learnedSloth
Posts: 82
Joined: Mon Sep 12, 2022 10:20 pm
Karma: 31
Contact:

Re: Negotiating a secret for encryption in the global press

#12 Post by learnedSloth » Mon Aug 07, 2023 10:06 pm

JECE wrote:
Mon Aug 07, 2023 9:19 pm
The algebra makes sense. But it isn't algebra, I guess?
The actual implementation uses algebra of a finite field, but I haven't delved into it so deeply that I could tell how accurate analogy integer multiplication actually is (so I called it just mixing), but Wikipedia seems to use it.

User avatar
kestasjk
Developer
Developer
Posts: 500
Joined: Tue Mar 14, 2017 8:13 pm
Location: Perth, Australia
Karma: 749
Contact:

Re: Negotiating a secret for encryption in the global press

#13 Post by kestasjk » Fri Aug 11, 2023 2:15 pm

learnedSloth wrote:
Mon Aug 07, 2023 11:42 am
It can be done with significantly shorter cipher than I assumed in Cryptic messages and intrigue, as encrypting arbitrary messages isn't necessary.
Both players must contribute to the secret and a confounding factor is required to exchange the contributions without revealing them.

Commanding OpenSSL to do the hard work

First your secret contribution:

Code: Select all

openssl genpkey -algorithm X25519 -out contribution
Keep it safe, for computing the secret with it is fast, but too slow without it.
Now the confounded version for sharing:

Code: Select all

openssl pkey -in contribution -pubout -out confounded
It looks like this:

Code: Select all

-----BEGIN PUBLIC KEY-----
MCowBQYDK2VuAyEAIA2nOyv2LtvlcLqEHQz6owx9dBQ7Ie74U+B7qmXnqEk=
-----END PUBLIC KEY-----
If other players can be trusted to reproduce the header and footer by hand, you need to paste just that 1 line of cipher, which is shorter than some gibberish used in the game linked above!

When 2 players have pasted their confounded contributions, they can compute their common secret:

Code: Select all

openssl pkeyutl -derive -inkey contribution -peerkey another_confounded -out common_secret
It's 256 raw bits, so you may have to convert it depending on how you plan to use it.
Eeenteresting.. So here's my confounded contribution:

Code: Select all

-----BEGIN PUBLIC KEY-----
MCowBQYDK2VuAyEAlzaB5x9nLBv47jZ66s0EClFsf2oRqjk+AeIOV5JbtjI=
-----END PUBLIC KEY-----
I now have a common secret with you.. so I guess I can use those 256 raw bits to encrypt something only you can read?

If I generate an AES key from our common secret, then use that to encrypt some text, and base64 encode it, with a little help from chatgpt:

Code: Select all

openssl dgst -sha256 -binary -out derived_key.bin common_secret
echo "[redacted, super interesting message]" > message.txt
openssl enc -aes-256-cbc -salt -in message.txt -out encrypted_message.bin -pass file:derived_key.bin
openssl base64 -in encrypted_message.bin -out encrypted_message_base64.txt
You and only you should be able to decrypt this super interesting message: (?)

Code: Select all

U2FsdGVkX18uQxnaYjc0xc2NfrEMIYcOtHnDtOgA48iVG7VXpvobCqPoYHue1qZK
zK3FDt6drOV1B/bYcVK+qtMb5aA3ASygEQcIvapxZQw=
I can see this catching on :P

edit: Where does the common paint come from though? Or is that common for everyone?

learnedSloth
Posts: 82
Joined: Mon Sep 12, 2022 10:20 pm
Karma: 31
Contact:

Re: Negotiating a secret for encryption in the global press

#14 Post by learnedSloth » Fri Aug 11, 2023 3:46 pm

kestasjk wrote:
Fri Aug 11, 2023 2:15 pm

Eeenteresting.. So here's my confounded contribution:

Code: Select all

-----BEGIN PUBLIC KEY-----
MCowBQYDK2VuAyEAlzaB5x9nLBv47jZ66s0EClFsf2oRqjk+AeIOV5JbtjI=
-----END PUBLIC KEY-----
I now have a common secret with you.. so I guess I can use those 256 raw bits to encrypt something only you can read?

If I generate an AES key from our common secret, then use that to encrypt some text, and base64 encode it, with a little help from chatgpt:

Code: Select all

openssl dgst -sha256 -binary -out derived_key.bin common_secret
echo "[redacted, super interesting message]" > message.txt
openssl enc -aes-256-cbc -salt -in message.txt -out encrypted_message.bin -pass file:derived_key.bin
openssl base64 -in encrypted_message.bin -out encrypted_message_base64.txt
You and only you should be able to decrypt this super interesting message: (?)

Code: Select all

U2FsdGVkX18uQxnaYjc0xc2NfrEMIYcOtHnDtOgA48iVG7VXpvobCqPoYHue1qZK
zK3FDt6drOV1B/bYcVK+qtMb5aA3ASygEQcIvapxZQw=
I can see this catching on :P
Luckily I still had the contribution I used lying around. :-D Here's my super sensitive response:

Code: Select all

U2FsdGVkX1+LVOdAuYvHGZ2zDUIU8hLwozJyZFir0VYfqX4TWXEkZPX+ULmCPY8U
wPjdQpWhsfd9P9yM1r0wtZu0ZXP/BCM1UnRUAYe5J9f7FezRrMaUTl9wGz1YQM3c
vxHQhZJdnzgiF1QHfj8HgEZCJnAvwPTopfmGs1iyiBk=
edit: Where does the common paint come from though? Or is that common for everyone?
From the contribution generation algorithm (X25519) I think. Idk if it can be changed. OpenSSL seems to embed some metadata (our "public keys" start identically), but it could be just for sanity checks or something like that.
1

User avatar
kestasjk
Developer
Developer
Posts: 500
Joined: Tue Mar 14, 2017 8:13 pm
Location: Perth, Australia
Karma: 749
Contact:

Re: Negotiating a secret for encryption in the global press

#15 Post by kestasjk » Fri Aug 11, 2023 4:17 pm

learnedSloth wrote:
Fri Aug 11, 2023 3:46 pm
kestasjk wrote:
Fri Aug 11, 2023 2:15 pm

Eeenteresting.. So here's my confounded contribution:

Code: Select all

-----BEGIN PUBLIC KEY-----
MCowBQYDK2VuAyEAlzaB5x9nLBv47jZ66s0EClFsf2oRqjk+AeIOV5JbtjI=
-----END PUBLIC KEY-----
I now have a common secret with you.. so I guess I can use those 256 raw bits to encrypt something only you can read?

If I generate an AES key from our common secret, then use that to encrypt some text, and base64 encode it, with a little help from chatgpt:

Code: Select all

openssl dgst -sha256 -binary -out derived_key.bin common_secret
echo "[redacted, super interesting message]" > message.txt
openssl enc -aes-256-cbc -salt -in message.txt -out encrypted_message.bin -pass file:derived_key.bin
openssl base64 -in encrypted_message.bin -out encrypted_message_base64.txt
You and only you should be able to decrypt this super interesting message: (?)

Code: Select all

U2FsdGVkX18uQxnaYjc0xc2NfrEMIYcOtHnDtOgA48iVG7VXpvobCqPoYHue1qZK
zK3FDt6drOV1B/bYcVK+qtMb5aA3ASygEQcIvapxZQw=
I can see this catching on :P
Luckily I still had the contribution I used lying around. :-D Here's my super sensitive response:

Code: Select all

U2FsdGVkX1+LVOdAuYvHGZ2zDUIU8hLwozJyZFir0VYfqX4TWXEkZPX+ULmCPY8U
wPjdQpWhsfd9P9yM1r0wtZu0ZXP/BCM1UnRUAYe5J9f7FezRrMaUTl9wGz1YQM3c
vxHQhZJdnzgiF1QHfj8HgEZCJnAvwPTopfmGs1iyiBk=
edit: Where does the common paint come from though? Or is that common for everyone?
From the contribution generation algorithm (X25519) I think. Idk if it can be changed. OpenSSL seems to embed some metadata (our "public keys" start identically), but it could be just for sanity checks or something like that.
Hey it works! Nifty..
> As with a lot of this stuff, very neat, but a bit impractical
< I think more practical and definitely more secure than what was used in that game that inspired this guide. :)

It'd be good if there was decent software that allowed this kind of thing more easily. We use this sort of stuff every day in our web browsers and it's the norm, but between individuals only .. tech enthusiasts.. are going to go to these lengths if it needs these openssl commands and saving binary files etc.

learnedSloth
Posts: 82
Joined: Mon Sep 12, 2022 10:20 pm
Karma: 31
Contact:

Re: Negotiating a secret for encryption in the global press

#16 Post by learnedSloth » Mon Aug 14, 2023 12:07 pm

kestasjk wrote:
Fri Aug 11, 2023 4:17 pm
Hey it works! Nifty..
> As with a lot of this stuff, very neat, but a bit impractical
< I think more practical and definitely more secure than what was used in that game that inspired this guide. :)

It'd be good if there was decent software that allowed this kind of thing more easily. We use this sort of stuff every day in our web browsers and it's the norm, but between individuals only .. tech enthusiasts.. are going to go to these lengths if it needs these openssl commands and saving binary files etc.
The fact that those commands "just" produce files suggests using make. Actually a makefile is in my head as I write this. :razz: Attaching a makefile just didn't work last time, but copying it shouldn't be too difficult.

learnedSloth
Posts: 82
Joined: Mon Sep 12, 2022 10:20 pm
Karma: 31
Contact:

Re: Negotiating a secret for encryption in the global press

#17 Post by learnedSloth » Thu Aug 17, 2023 7:59 pm

Attaching the makefile still fails, but you can cat > makefile and paste the contents below:

Code: Select all

my_confounded: my_secret
	openssl pkey -in $< -pubout -out $@
	cat $@ # Below this line

my_secret:
	openssl genpkey -algorithm X25519 -out $@

common_with_%: % my_secret
	openssl pkeyutl -derive -inkey my_secret -peerkey $< -out $@

key_with_%: common_with_%
	openssl dgst -sha256 -binary -out $@ $<

message_to_%: key_with_% this_forces_make_to_always_oblige
	openssl enc -aes-256-cbc -salt -pass file:$< | openssl base64 -out $@
	cat $@ # Below this line

message_from_%: key_with_% this_forces_make_to_always_oblige
	openssl base64 -d | openssl enc -d -aes-256-cbc -salt -pass file:$< -out $@ 
	cat $@ # Below this line

.SECONDARY: $(common_with_%) $(key_with_%)

.PHONY: this_forces_make_to_always_oblige
Note that the indents must be tabs. As this is now more than a demo, I write usage instructions.

You want to use a different secret in every anonymous game. The easiest way to avoid mixing them is to make a new directory for each game. You just need to copy the makefile to each game directory. Then you can generate your personal secret and the confounded version by just invoking make:

Code: Select all

make
You must paste the confounded version to the public press. When another country has pasted his, you can copy it to a file, that you want to name after him, to permit multiple peers.

Code: Select all

cat > kestas
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VuAyEAlzaB5x9nLBv47jZ66s0EClFsf2oRqjk+AeIOV5JbtjI=
-----END PUBLIC KEY-----
Message processing commands compute the common secret and the respective encryption key on first run. If you write your message to plain_message, you can encrypt it like this:

Code: Select all

make message_to_kestas < plain_message
The base64-encoded encrypted message will be written to message_to_kestas and displayed. Decryption is quite similar:

Code: Select all

make message_from_kestas < base64_encoded_encrypted_message
The message will be written to message_from_kestas and displayed.

User avatar
Yigg
Posts: 156
Joined: Sun Dec 31, 2017 3:56 am
Location: Majesty's Court, Jester's Chair
Karma: 290
Contact:

Re: Negotiating a secret for encryption in the global press

#18 Post by Yigg » Fri Aug 18, 2023 6:46 pm

Image
2

captainmeme
Posts: 613
Joined: Fri Sep 29, 2017 3:06 pm
Location: Manchester, UK
Karma: 757
Contact:

Re: Negotiating a secret for encryption in the global press

#19 Post by captainmeme » Fri Aug 18, 2023 10:35 pm

Going to say here, from a kinda-mod perspective, this is a cool thought experiment but if you do it in a public press game (assuming I'm understanding this correctly), you are essentially communicating privately. If you join a PPO variant game everyone is going in expecting to play a variant in which private communication is banned - if you want to communicate privately, please just join a game where it's allowed instead of trying to introduce it in a variant where it's explicitly not permitted!

I like it as a thought experiment, and hell it could be fun to mess around with in a full press game just for amusement, but please don't do this in a public press only game.
3

User avatar
JECE
Posts: 1370
Joined: Sun Dec 31, 2017 4:35 pm
Karma: 358
Contact:

Re: Negotiating a secret for encryption in the global press

#20 Post by JECE » Sat Aug 19, 2023 1:07 am

captainmeme wrote:
Fri Aug 18, 2023 10:35 pm
Going to say here, from a kinda-mod perspective, this is a cool thought experiment but if you do it in a public press game (assuming I'm understanding this correctly), you are essentially communicating privately. If you join a PPO variant game everyone is going in expecting to play a variant in which private communication is banned - if you want to communicate privately, please just join a game where it's allowed instead of trying to introduce it in a variant where it's explicitly not permitted!

I like it as a thought experiment, and hell it could be fun to mess around with in a full press game just for amusement, but please don't do this in a public press only game.
I think that the intent was to set up a private public press game where this was allowed.
See my full Profile:
http://www.webdiplomacy.net/profile.php?userID=17421

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests