[PATCH] Keys: Split key permissions checking into a .c file