# Python KDF - Master Key and Derivatives

The encrypted file can be opened by following combinations (either any 2 DK, or 1 MK):

DK1 + DK2
DK1 + DK3
DK2 + DK3
DK1 + DK2 + DK3
MK


Any heads-up with Python KDF logic? Any good documentation/reference will also suffice the purpose.

I tried deriving keys with KDF(MK, "pass1") -> DK1 but then the combination logic didn't work.

-
Welcome to crypto-exchange. It seems to me, that you don't need a KDF function to achieve this but a "2-out-of-3" secret sharing scheme. Btw, the combination $DK_1+DK_2+DK_3$ can be ommited, since it's already covered by all 3 previous ones (someone who knows 3 keys can also unlock the file by only using two of them already) –  tylo Jun 12 '14 at 11:02
Please don't cross-post, it is not allowed on the SE network. –  mikeazo Jun 12 '14 at 15:57

While your post is hard to decipher, I understand you need to split your master key $(MK)$ into three shares $DK_i$, of which any two would suffice to recover $MK$.

This is called secret splitting (or sharing), or a (2,3) threshold scheme.

One of the many possible ways to do this is with Shamir's Secret Sharing Scheme (SSSS). It is proven secure when implemented correctly and is available in many languages including Python.

-

If I understand your requirements, you want:

• One master key that opens the encryption.
• Three subkeys, at least two of which are required to open the encryption.

If I understood correctly, you can accomplish this by

1. Deriving the encryption key from the master, e.g. $KDF(M, salt)$, or using the master key as is, if it only needs to open one encryption and it being derived from the derived keys isn't a problem.
2. Sharing that encryption key using any $(2,3)$–secret sharing system.

Recommendations for a particular implementation are off topic, but you should be able to find them knowing the term "secret sharing".

-
Thanks for your comments guys! But then, I couldn't find an implementation in PYTHON for SSSS. Isn't there a library for that? Or, do I have to do the computations myself in raw python? –  pwn.star Jun 12 '14 at 15:52
@pwn.star You couldn't find any? Did you try this? –  mikeazo Jun 12 '14 at 16:45