Adds master key handling functions

This commit completely breaks compilation.
It's probably for the best, since the code
in this branch isn't even properly tested.